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

Re: [PATCH/RFC] git.c: support "!!" aliases that do not move cwd

From
Jeff King <peff@peff.net>
Date
Oct 6, 2016, 19:00 UTC
Message-ID
<20161006190014.owmqr2eqyk5h5cau@sigill.intra.peff.net>
In-Reply-To
<20161006114124.4966-1-pclouds@gmail.com>
On Thu, Oct 06, 2016 at 06:41:24PM +0700, Nguyễn Thái Ngọc Duy wrote:
Show 12 quoted lines
> Throwing something at the mailing list to see if anybody is
> interested.
> 
> Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make
> handling path arguments hard because they are relative to the original
> cwd. We set GIT_PREFIX to work around it, but I still think it's more
> natural to keep cwd where it is.
> 
> We have a way to do that now after 441981b (git: simplify environment
> save/restore logic - 2016-01-26). It's just a matter of choosing the
> right syntax. I'm going with '!!'. I'm not very happy with it. But I
> do like this type of alias.

Hmm. I wonder if any commands will be fooled by not being moved to GIT_WORK_TREE. I know that there is a bug already in this case:

  export HOME=$PWD
  for i in one two; do
  	git init $i &&
  	(cd $i &&
  	 echo "* diff=$i" >.gitattributes &&
  	 git add . &&
  	 git commit -m $i) &&
  	git config --global diff.$i.textconv "sed s/^/$i:/"
  done
  cd two &&
  git --git-dir=$(pwd)/../one/.git --work-tree=$(pwd)/../one show

This shows the contents of repo one using the .gitattributes from repo two. I am not sure if the bug is that when GIT_WORK_TREE is set, git-show doesn't position itself at the toplevel of that tree, or if the attributes machinery should be more careful about looking up paths in the work-tree versus the current directory.

This bug is tangential to your patch (it has nothing to do with aliases, and should be fixed regardless). But I wonder if your "!!" aliases will expose this bug more frequently.

-Peff
PS I think your "!!" syntax conflicts with something like:
    git -c alias.has-changes="!! git diff --quiet' has-changes
   I don't know if that is worth worrying about or not. I also notice
   that using "!!git diff" with no space seems broken, as it seems to
   skip using the shell. I wonder if that is a bug in run-command.
Previous: Jakub NarębskiNext: Jeff King
Message 33 of 34 in “git.c: support "!!" aliases that do not move cwd”
  1. git.c: support "!!" aliases that do not move cwdNguyễn Thái Ngọc Duy, Oct 6, 2016
  2. Junio C HamanoOct 6, 2016
  3. Johannes SchindelinOct 7, 2016
  4. Duy NguyenOct 7, 2016
  5. Matthieu MoyOct 7, 2016
  6. Duy NguyenOct 7, 2016
  7. Johannes SchindelinOct 7, 2016
  8. Matthieu MoyOct 7, 2016
  9. Johannes SchindelinOct 7, 2016
  10. Jeff KingOct 7, 2016
  11. Johannes SixtOct 7, 2016
  12. Jeff KingOct 7, 2016
  13. Johannes SchindelinOct 8, 2016
  14. Jeff KingOct 9, 2016
  15. Jeff KingOct 9, 2016
  16. Duy NguyenOct 9, 2016
  17. Jeff KingOct 9, 2016
  18. Junio C HamanoOct 10, 2016
  19. Jeff KingOct 10, 2016
  20. Junio C HamanoOct 10, 2016
  21. Johannes SchindelinOct 11, 2016
  22. Duy NguyenOct 11, 2016
  23. Johannes SchindelinOct 11, 2016
  24. Jeff KingOct 11, 2016
  25. Duy NguyenOct 26, 2016
  26. Junio C HamanoOct 26, 2016
  27. Jakub NarębskiOct 7, 2016
  28. Johannes SchindelinOct 7, 2016
  29. Jakub NarębskiOct 7, 2016
  30. Duy NguyenOct 8, 2016
  31. SZEDER GáborOct 11, 2016
  32. Jakub NarębskiOct 11, 2016
  33. Jeff KingOct 6, 2016
  34. Jeff KingOct 6, 2016

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.