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

Re: [PATCH] Preserve cwd in setup_git_directory()

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Jul 24, 2008, 18:37 UTC
Message-ID
<fcaeb9bf0807241137h65292d7egad8cc5f797114607@mail.gmail.com>
In-Reply-To
<alpine.DEB.1.00.0807241506340.8986@racer>
On 7/24/08, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 33 quoted lines
> Hi,
>
>  On Thu, 24 Jul 2008, Nguyen Thai Ngoc Duy wrote:
>
>  > On 7/24/08, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>  >
>
> > >  On Thu, 24 Jul 2008, Nguyen Thai Ngoc Duy wrote:
>  > >
>  > >  > When GIT_DIR is not set, cwd is used to determine where .git is. If
>  > >  > core.worktree is set, setup_git_directory() needs to jump back to
>  > >  > the original cwd in order to calculate worktree, this leads to
>  > >  > incorrect .git location later in setup_work_tree().
>  > >
>  > > I do not understand.  core.worktree is either absolute, in which case
>  > > there is no problem.  Or it is relative to where the config lives, no?
>  >
>  > The problem is GIT_DIR is not absolute in this case. So cwd must stay
>  > where git dir is until it is absolute-ized by setup_work_tree().
>
>
> I do not see GIT_DIR being set in your test case at all.
>
>  I do not see how get_git_work_tree() ro get_relative_cwd() should ever be
>  allowed to chdir().
>
>  _If_ they were (which I strongly doubt), they should chdir() back
>  themselves.
>
>  I now wasted easily 30 minutes just trying to make sense of your patch and
>  your response.  And I am still puzzled.
>
>  Your commit message was of no help.
Alright, let's look at the code.
 1. cwd is moved to toplevel working directory by setup_git_directory_gently()
 2. setup_git_env() by default will set git_dir variable as ".git" as
part of check_repository_format_gently()
 3. now in setup_git_directory() finds out core.worktree, it chdir()
to get relative prefix
 4. setup_work_tree() sees that git_dir is not absolute path, it makes
git_dir absolute

If in step 3, it does not chdir(), step 4 will be right. In this case, step 3 does chdir() and not going back, access to git repository will fail as Geoff Russell discovered.

-- 
Duy
Previous: Johannes SchindelinNext: Geoff Russell
Message 7 of 9 in “Preserve cwd in setup_git_directory()”
  1. Preserve cwd in setup_git_directory()Nguyễn Thái Ngọc Duy, Jul 24, 2008
  2. Johannes SixtJul 24, 2008
  3. Preserve cwd in setup_git_directory()Nguyen Thai Ngoc Duy, Jul 24, 2008
  4. Johannes SchindelinJul 24, 2008
  5. Nguyen Thai Ngoc DuyJul 24, 2008
  6. Johannes SchindelinJul 24, 2008
  7. Nguyen Thai Ngoc DuyJul 24, 2008
  8. Geoff RussellJul 25, 2008
  9. Johannes SchindelinJul 25, 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.