git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git alias always chdir to top

From
PWPete Wyckoff <pw@padd.com>
Date
Dec 3, 2008, 16:08 UTC
Message-ID
<20081203160852.GA3773@osc.edu>

I have a git alias that takes a relative file name argument, and would like to know from where in the tree it was invoked, especially if inside a subdirectory of the git tree.

Consider .git/config:
    [alias]
	pwd = !/bin/pwd
Then a git tree:
    /home/me
	topdir/
	    .git/
	    subdir/
		subdir-y.c
	    topdir-x.c
Then inside /home/me/topdir, all is well:
    $ pwd
    /home/me/topdir
    $ git pwd
    /home/me/topdir

But inside /home/me/topdir/subdir, the pwd alias is invoked in the wrong dir:

    $ pwd
    /home/me/topdir/subdir
    $ git pwd
    /home/me/topdir
The implication of this is that I call an alias command like:
    $ pwd
    /home/me/topdir/subdir
    $ git myalias subdir-y.c
    myalias: No such file subdir-y.c

It looks like handle_alias() uses setup_git_directory_gently() to find the .git, which chdir()s up until it gets there. Is there a way to do this without changing the process current working directory instead? I could even handle an environment variable saving the original cwd, but that's ickier.

		-- Pete
Next: Jeff King
Message 1 of 3 in “git alias always chdir to top”
  1. Pete WyckoffDec 3, 2008
  2. Jeff KingDec 4, 2008
  3. Pete WyckoffDec 5, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.