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

Re: Git rebase --exec cannot run git commands affecting other repos

From
Jeff King <peff@peff.net>
Date
Jan 11, 2019, 16:04 UTC
Message-ID
<20190111160411.GD16754@sigill.intra.peff.net>
In-Reply-To
<20190110214842.dfisujzv7psx2jqe@hactar.rmz.io>
On Thu, Jan 10, 2019 at 09:48:42PM +0000, Samir Benmendil wrote:
Show 11 quoted lines
> > If the user wants to work in a different repository, the
> > environments that tells Git about the original repository can be
> > unset to do so, which is a very much deliberately designed
> > behaviour, primarily to help those who run "git rebase" from a
> > subdirectory of the project.
> 
> When run in a directory that does not have ".git" repository directory, Git
> tries to find such a directory in the parent directories to find the top of
> the working tree.
> 
> That should be the case as well for `git rebase`, is it not?

Generally yes. But ".git" does not necessarily have to be connected. For example, try this:

  # a separate worktree and repo
  mkdir worktree
  git init --bare repo.git
  git -C repo.git config core.bare false
  git -C repo.git config core.worktree "$PWD/worktree"
  # an unrelated repo we'll try to access
  git init unrelated
  # operate in the separated repo using $GIT_DIR to point to the repo
  export GIT_DIR=$PWD/repo.git
  cd worktree
  # rebase that tries to operate in another repository
  echo content >file
  git add file
  git commit -m file
  git rebase --root -x 'cd ../unrelated && git rev-parse --git-dir'

And in fact, this case behaves the same now or with older versions of Git (because GIT_DIR would be set either way). Likewise the less exotic "git --git-dir=something rebase", which would set GIT_DIR in the environment. I think there are other cases, too, where we'd internally set GIT_DIR during repo discovery, but I don't remember all of them offhand.

So I think the reasoning at the time was along the lines of "scripts already should not be relying on the absence of $GIT_DIR". That said, I do think there's an argument to be made that it generally worked before in many common setups, even if it was not bulletproof.

And I am not sure I could construct a case where setting $GIT_DIR when it was not already set explicitly _helps_ the "exec" command (because if searching from the working tree does not work, then the caller of "git rebase" would had to have set $GIT_DIR itself).

-Peff
Previous: Samir Benmendil
Message 4 of 4 in “Git rebase --exec cannot run git commands affecting other repos”
  1. Samir BenmendilJan 10, 2019
  2. Junio C HamanoJan 10, 2019
  3. Samir BenmendilJan 10, 2019
  4. Jeff KingJan 11, 2019

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.