git alias always chdir to top
- From
- Pete 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/topdirBut inside /home/me/topdir/subdir, the pwd alias is invoked in the wrong dir:
$ pwd
/home/me/topdir/subdir
$ git pwd
/home/me/topdirThe 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.cIt 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