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

Re: [BUG] worktree local refs weirdness

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Mar 7, 2019, 09:38 UTC
Message-ID
<ec707cbb-96e8-f26f-3d69-b69d29b31737@gmail.com>
In-Reply-To
<f6e197f2-886a-5e82-7fc4-c53737dd66cc@gmail.com>
On 06/03/2019 15:57, Phillip Wood wrote:
Show 8 quoted lines
> When it is run in a worktree 'git for-each-ref' only seems to show refs 
> under refs/rewritten if that directory also exists under $GIT_COMMON_DIR 
> even though they are local to the worktree.
> 
> Initially I thought this was due to $GIT_COMMON_DIR pointing to a bare 
> repo, but that is not the case. However while writing a test case which 
> cloned to a bare repo I noticed it was listing a ref for the HEAD of a 
> worktree in the repo I had cloned from, not the clone itself.

Ignore that last paragraph, it's just showing the branch that got created when the worktree was created. The last part of the script is redundant, I've updated it below

# setup initial repo mkdir repo && cd repo && git init && echo a>a && git add a && git commit -ma && #add a worktree and set a ref under refs/rewritten git worktree add ../worktree-1 && cd ../worktree-1 && echo 'worktree-1 adding refs/rewritten/a' && git update-ref refs/rewritten/a HEAD && git rev-parse --verify refs/rewritten/a && echo 'refs/rewritten/a exists but is not shown' && git for-each-ref && # add a ref under refs/rewritten to the main repo cd ../repo && echo 'repo adding refs/rewritten/z' && git update-ref refs/rewritten/z HEAD && git for-each-ref && cd ../worktree-1 && echo 'worktree-1 now shows refs/rewritten/a' && git for-each-ref

Output
Initialized empty Git repository in /tmp/x/repo/.git/
[master (root-commit) d60b5d6] a
  1 file changed, 1 insertion(+)
  create mode 100644 a
Preparing worktree (new branch 'worktree-1')
HEAD is now at d60b5d6 a
worktree-1 adding refs/rewritten/a
d60b5d6532fe5ed6e3bc3a0233c6de9d86092d13
refs/rewritten/a exists but is not shown
d60b5d6532fe5ed6e3bc3a0233c6de9d86092d13 commit	refs/heads/master
d60b5d6532fe5ed6e3bc3a0233c6de9d86092d13 commit	refs/heads/worktree-1
repo adding refs/rewritten/z
d60b5d6532fe5ed6e3bc3a0233c6de9d86092d13 commit	refs/heads/master
d60b5d6532fe5ed6e3bc3a0233c6de9d86092d13 commit	refs/heads/worktree-1
d60b5d6532fe5ed6e3bc3a0233c6de9d86092d13 commit	refs/rewritten/z
worktree-1 now shows refs/rewritten/a
d60b5d6532fe5ed6e3bc3a0233c6de9d86092d13 commit	refs/heads/master
d60b5d6532fe5ed6e3bc3a0233c6de9d86092d13 commit	refs/heads/worktree-1
d60b5d6532fe5ed6e3bc3a0233c6de9d86092d13 commit	refs/rewritten/a
Best Wishes
Phillip
Show 84 quoted lines
> 
> The script below reproduces both issues, I've copied the output below 
> it. I'm not sure what's going on or the best way to debug it.
> 
> Best Wishes
> 
> Phillip
> 
> # setup initial repo
> mkdir repo &&
> cd repo &&
> git init &&
> echo a>a &&
> git add a &&
> git commit -ma &&
> #add a worktree and set a ref under refs/rewritten
> git worktree add ../worktree-1 &&
> cd ../worktree-1 &&
> echo 'worktree-1 adding refs/rewritten/a' &&
> git update-ref refs/rewritten/a HEAD &&
> git rev-parse --verify refs/rewritten/a &&
> echo 'refs/rewritten/a exists but is not shown' &&
> git for-each-ref &&
> # add a ref under refs/rewritten to the main repo
> cd ../repo &&
> echo 'repo adding refs/rewritten/z' &&
> git update-ref refs/rewritten/z HEAD &&
> git for-each-ref &&
> cd ../worktree-1 &&
> echo 'worktree-1 now shows refs/rewritten/a' &&
> git for-each-ref &&
> cd .. &&
> # create a bare clone with a worktree
> git clone --bare --no-local repo bare &&
> cd bare &&
> git worktree add ../worktree-2 &&
> cd ../worktree-2 &&
> echo 'worktree-2 adding refs/rewritten/b' &&
> echo 'why does this show refs/worktree-1/head' &&
> echo 'but not refs/rewritten/b?' &&
> git worktree list &&
> git update-ref refs/rewritten/b HEAD &&
> git rev-parse --verify refs/rewritten/b &&
> git for-each-ref
> 
> 
> Output
> Initialized empty Git repository in 
> /home/phil/src/git-utils/dev/git-rewrite/repo/.git/
> [master (root-commit) dc2045a] a
>   1 file changed, 1 insertion(+)
>   create mode 100644 a
> Preparing worktree (new branch 'worktree-1')
> HEAD is now at dc2045a a
> worktree-1 adding refs/rewritten/a
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656
> refs/rewritten/a exists but is not shown
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/heads/master
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/heads/worktree-1
> repo adding refs/rewritten/z
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/heads/master
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/heads/worktree-1
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/rewritten/z
> worktree-1 now shows refs/rewritten/a
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/heads/master
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/heads/worktree-1
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/rewritten/a
> Cloning into bare repository 'bare'...
> remote: Enumerating objects: 3, done.
> remote: Counting objects: 100% (3/3), done.
> remote: Total 3 (delta 0), reused 0 (delta 0)
> Receiving objects: 100% (3/3), done.
> Preparing worktree (new branch 'worktree-2')
> HEAD is now at dc2045a a
> worktree-2 adding refs/rewritten/b
> why does this show refs/worktree-1/head
> but not refs/rewritten/b?
> /home/phil/src/git-utils/dev/git-rewrite/bare        (bare)
> /home/phil/src/git-utils/dev/git-rewrite/worktree-2  dc2045a [worktree-2]
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/heads/master
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/heads/worktree-1
> dc2045a36f38ba4e9bacd8cd86ba74f58a1d4656 commit    refs/heads/worktree-2
> 
Previous: Phillip WoodNext: Duy Nguyen
Message 2 of 11 in “[BUG] worktree local refs weirdness”
  1. Phillip WoodMar 6, 2019
  2. Phillip WoodMar 7, 2019
  3. Duy NguyenMar 7, 2019
  4. Duy NguyenMar 7, 2019
  5. 0/3 Fix refs/rewritten not show up in for-each-refNguyễn Thái Ngọc Duy, Mar 7, 2019
  6. 1/3 files-backend.c: factor out per-worktree code in loose_fill_ref_dir()Nguyễn Thái Ngọc Duy, Mar 7, 2019
  7. 2/3 files-backend.c: reduce duplication in add_per_worktree_entries_to_dir()Nguyễn Thái Ngọc Duy, Mar 7, 2019
  8. Phillip WoodMar 7, 2019
  9. 3/3 Make sure refs/rewritten/ is per-worktreeNguyễn Thái Ngọc Duy, Mar 7, 2019
  10. Phillip WoodMar 7, 2019
  11. Duy NguyenMar 7, 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.