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

Re: [git-users] Problem using detached worktrees with commands implemented in scripts

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 17, 2013, 22:48 UTC
Message-ID
<20131017224834.GW9464@google.com>
In-Reply-To
<1390B0AFBE7F4C4A875987C7469B0791@PhilipOakley>
Philip Oakley wrote:
Show 5 quoted lines
> A bit more looking gave that the cd_to_toplevel () in git-sh-setup.sh
> directly uses `git rev-parse --show-toplevel`, which simply returns
> work_tree (static char *work_tree; in environment.c, with comment /*
> This is set by setup_git_dir_gently() and/or git_default_config()
> */), apparently without a check for the GIT_WORK_TREE.
Getting closer. :)

The usual way to use GIT_WORK_TREE is along with GIT_DIR. That takes you into the setup_explicit_git_dir() codepath, which does respect GIT_WORK_TREE as it should. (setup_discovered_git_dir does, too.)

The strange behavior you ran into is that unlike, say, git-pull.sh and git-am.sh, filter-branch does not set SUBDIRECTORY_OK, store the prefix from 'git rev-parse --show-prefix', and then cd_to_toplevel at the top of the script. In other words, nobody bothered to make it work from anywhere other than the toplevel of the worktree to begin with, and nobody wanted it enough to fix it later.

Hope that helps, Jonathan

Previous: Philip OakleyNext: Philip Oakley
Message 9 of 17 in “[git-users] Problem using detached worktrees with commands implemented in scripts”
  1. Dale R. WorleyOct 16, 2013
  2. Junio C HamanoOct 16, 2013
  3. Philip OakleyOct 16, 2013
  4. Junio C HamanoOct 16, 2013
  5. Philip OakleyOct 17, 2013
  6. Junio C HamanoOct 17, 2013
  7. Philip OakleyOct 17, 2013
  8. Philip OakleyOct 17, 2013
  9. Jonathan NiederOct 17, 2013
  10. Philip OakleyOct 18, 2013
  11. Dale R. WorleyOct 18, 2013
  12. Dale R. WorleyOct 17, 2013
  13. Junio C HamanoOct 17, 2013
  14. Dale R. WorleyOct 18, 2013
  15. Junio C HamanoOct 18, 2013
  16. Dale R. WorleyOct 21, 2013
  17. Dale R. WorleyOct 18, 2013

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.