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

Re: [PATCH v2] Add command line option --chdir/-C to allow setting git process work directory.

From
Jeff King <peff@peff.net>
Date
Oct 19, 2008, 21:02 UTC
Message-ID
<20081019210241.GA32589@coredump.intra.peff.net>
In-Reply-To
<20081019161819.GA12495@charybdis.dreamhost.com>
On Sun, Oct 19, 2008 at 09:18:19AM -0700, Maciej Pasternacki wrote:
Show 5 quoted lines
> When "git pull" is ran outside of work tree, it is unable to update work tree
> with pulled changes; specifying --git-dir and --work-tree does not help here
> because "cd_to_toplevel" call in git-pull occurs after "require_work_tree";
> changing order may break the commend if there is no working tree.  Some more
> commands behave in a similar way.

I took a closer look at this. I'm not sure that there is actually a problem with moving the cd_to_toplevel before require_work_tree. cd_to_toplevel makes sure there is actually something to cdup to. In my test without a work-tree, "git rev-parse --show-cdup" simply printed nothing, causing no "cd" to occur.

Moreover, git-pull is not the only script with this problem. There are quite a few with

  require_work_tree
  cd_to_toplevel

which will break in the same way with --work-tree. And there are even more with just require_work_tree that don't cd_to_toplevel at all. So I suspect that --work-tree is largely broken in our scripts and nobody has actually tried it.

So:
  1. I think we can fix this breakage by swapping the two.
  2. There is still breakage in other scripts, some of which may need
     quite in-depth fixes (e.g., git-bisect requires a work tree but
     does not chdir at all. For the require_work_tree test to work, it
     needs to be inside the work tree, and the script will need a
     careful looking over to see what ramifications that has).
  3. I think your -C option has some merit independent of this, since
     it allows you to chdir and still use the usual lookup rules (e.g.,
     see if it is bare vs a regular repository). But I don't feel
     strongly about it one way or the other.
-Peff
Previous: Maciej Pasternacki
Message 2 of 2 in “Add command line option --chdir/-C to allow setting git process work directory.”
  1. Add command line option --chdir/-C to allow setting git process work directory.Maciej Pasternacki, Oct 19, 2008
  2. Jeff KingOct 19, 2008

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.