git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [BUG?] Weird interaction between `git -C`, aliases and worktrees
@ 2020-10-14 15:27 Philippe Blain
  2020-10-14 22:02 ` Elijah Newren
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Blain @ 2020-10-14 15:27 UTC (permalink / raw)
  To: Git mailing list; +Cc: Eric Sunshine, Elijah Newren

Hello all,

Up to recently I had an alias 'st' for `git status`, i.e. `git config alias.st status`. 
This works well in the main working tree as well as secondary worktrees (`git worktree add ...`),
and also shows paths relative to the current directory if I'm not at the root of the repo, 
just like `git status`.

Now I wanted to change my alias so that it ran `git status` and then an additional command, i.e.
`git config alias.st '!git status && date'` (for demonstration purposes).
This works correctly in the main worktree and secondary worktrees, but since aliases
run from the root of the repo, the paths in the output of 'git st' are not relative
to the current directory.

So my next attempt was `git config alias.st '!git -C "${GIT_PREFIX}" status && date'`,
so that paths would be relative in the output. However, this works in the main worktree
but fails badly in the secondary worktree:

```
rm -rf test &&
rm -rf test2 &&
git init test &&  
cd test &&
mkdir folder &&
date>>folder/file &&
git add folder/file &&
git ci -m "commit" &&
git config alias.st '!git -C "${GIT_PREFIX}" status && date' &&
date >>folder/file &&
echo '=== `git st` in main worktree at root ===' &&
git st &&
cd folder &&  
echo '=== `git st` in main worktree in folder ===' &&
git st &&
git worktree add ../test2 &&
cd ../test2 &&
date >>folder/file &&
echo '=== `git st` in secondary worktree at root ===' &&
git st &&  
cd folder &&
echo '=== `git st` in secondary worktree in folder ===' &&
git st
```

The last commands ouputs: 

```
=== `git st` in secondary worktree in folder ===
On branch test2
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	deleted:    folder/file

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	file

no changes added to commit (use "git add" and/or "git commit -a")
```

So something is wrong in the automatic worktree path detection...
If I replace the alias with 

    git config alias.st '!git -C "${GIT_PREFIX}" --work-tree=$PWD status && date' 

then it works correctly, but I have a feeling this should not be necessary...

I've CC-ed Eric (because of his work on `git worktree`) and Elijah (because
I remember he worked on `dir.c` so maybe this is related to that code, but I'm
not sure).

Cheers,
Philippe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-16  0:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 15:27 [BUG?] Weird interaction between `git -C`, aliases and worktrees Philippe Blain
2020-10-14 22:02 ` Elijah Newren
2020-10-14 22:35   ` Philippe Blain
2020-10-16  0:23     ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).