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
Philip Oakley <philipoakley@iee.org>
Date
Oct 16, 2013, 22:39 UTC
Message-ID
<29AA597BEBC146B09E8B370949EC2CE9@PhilipOakley>
In-Reply-To
<xmqqeh7k51vg.fsf@gitster.dls.corp.google.com>
From: "Junio C Hamano" <gitster@pobox.com>
Show 8 quoted lines
> worley@alum.mit.edu (Dale R. Worley) writes:
>
>> In general, Git commands on a repository with a detached worktree can
>> be executed by cd'ing into the directory containing the .git
>> directory, ...
>
> Eh?  News to me; it might happened to have appeared to work by
> accident, but that is not by design.
I think it is this part in Dale's original email

"However, this approach does not work with "git filter-branch", which objects with "You need to run this command from the toplevel of the working tree."

that is the problem Dale has seen. IIRC there are a few commands that do require to be run from the toplevel ('git bisect' I think is another), and the detection process for 'toplevel' may not work properly when in a separated work-tree environment.

Perhaps something to consider.
Philip
Show 23 quoted lines
>
> IIRC, the intended use pattern (i.e. the change that introduced
> GIT_DIR and GIT_WORK_TREE environment variables was designed to
> support) for such a working tree is to:
>
> - export GIT_DIR that points at the correct .git directory;
>
> - export GIT_WORK_TREE that points at the correct top-level of such
>   a working tree; and then
>
> - run the commands anywhere in the working tree, as if you did not
>   export these two environment variables and instead had the .git
>   directory at the usual place in the working tree.
>
> It _is_ possible that we may have broken this canonical use pattern
> over time with more recent updates; I do not think we have extensive
> test coverage for "detached worktree" use case in the first place.
>
>> Does anyone have any feedback on this?
>
> Not exporting GIT_DIR variable in sh-setup was done not by accident
> but as a very deliberate design choice, IIRC.
> --
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 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.