Linked worktree: HEAD reflog entries are written to the main worktree's logs/HEAD
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
The cause is in RefDirectory: logFor resolves HEAD against the common dir's logs, while fileFor and ReflogReaderImpl use the worktree git dir. Start with RefDirectory.logFor and fileFor, then check ReflogWriter and ReflogReaderImpl. Done means the reproduction's commit and checkout entries land in worktrees/wt/logs/HEAD and the main worktree's logs/HEAD is unchanged, with the existing reflog tests still passing.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version
7.8.0.202609011348-r and 7.7.0.202606012155-r (RefDirectory.logFor is unchanged on master)
Operating System
MacOS
Bug description
When a repository is opened on a linked worktree (created with git worktree add), JGit writes the reflog entries for that worktree's HEAD into the main worktree's <common dir>/logs/HEAD, instead of <common dir>/worktrees/<name>/logs/HEAD. Branch reflogs (logs/refs/heads/*) are shared by all worktrees and are written correctly.
To reproduce (git 2.54, JDK 25):
git init -b main repo
git -C repo commit --allow-empty -m init
git -C repo worktree add -b wt ../wt
try (Git git = Git.open(new File("wt"))) { // the same with new File("repo/.git/worktrees/wt")
git.commit().setMessage("commit in wt").setAllowEmpty(true).call();
git.checkout().setCreateBranch(true).setName("topic").call();
System.out.println(git.reflog().call().size()); // prints 2: neither of the new entries
}
git -C repo reflog # the main worktree, which never moved
git -C wt reflog # the linked worktree
Cause: RefDirectory.fileFor resolves HEAD against the worktree's git dir, and ReflogReaderImpl reads HEAD's log from db.getDirectory(). But RefDirectory.logFor resolves every name outside refs/, HEAD included, against logsDir, which the constructor sets to fs.resolve(gitCommonDir, LOGS). ReflogWriter writes through logFor, so JGit writes HEAD's log to one file and reads it from another. This affects every update of HEAD: commit, checkout, reset, merge, rebase, cherry-pick, revert, and renaming the current branch (RefDirectoryRename).
Actual behavior
- The commit and checkout entries are appended to
repo/.git/logs/HEAD, the main worktree's HEAD reflog. - In the main worktree,
git reflog,HEAD@{1}and@{-1}follow the linked worktree's history.@{-1}iswt, sogit -C repo checkout -switches the main worktree towt, a branch it never had checked out. git -C wt reflogdoesn't show the entries, and neither does JGit's ownReflogCommandin the linked worktree.- With a bare repository and a linked worktree, JGit creates
<bare repo>/logs/HEAD.
Expected behavior
As with the git CLI: the entries for the linked worktree's HEAD go to repo/.git/worktrees/wt/logs/HEAD, where ReflogReaderImpl already reads them, and the main worktree's logs/HEAD is unchanged. Running the same commit and checkout with git -C wt ... does exactly that.
Relevant log output
$ git -C repo reflog
a80a6dd HEAD@{0}: checkout: moving from wt to topic
a80a6dd HEAD@{1}: commit: commit in wt
3a829fd HEAD@{2}: commit (initial): init
$ git -C wt reflog
3a829fd HEAD@{0}: reset: moving to HEAD
3a829fd HEAD@{1}:
Other information
-
It isn't specific to macOS: it's path resolution in
RefDirectory. Seen on macOS 26 (arm64) with JDK 25. -
A minimal fix could resolve HEAD's log in
logForthe wayfileForresolves HEAD:if (name.equals(HEAD)) { return new File(gitDir, L_LOGS + HEAD); }More generally, git keeps the logs of all per-worktree refs (HEAD, pseudo-refs such as ORIG_HEAD,
refs/bisect/,refs/worktree/,refs/rewritten/) in the worktree's own git dir, as was noted in the review of the worktree read support (https://eclipse.gerrithub.io/c/eclipse-jgit/jgit/+/1194900). -
Related, seen with 7.7.0:
RebaseCommand.resetSoftToParent(squash or fixup in an interactive rebase) readsORIG_HEADthroughexactRef, whichfileForresolves against the common dir, and writes it back withwriteOrigHead, which uses the worktree's git dir. After a squash in a linked worktree, that worktree'sORIG_HEADholds the main worktree's value. -
Found in Leaf (https://github.com/zzhelev/Leaf), a desktop git client built on JGit. It works around the bug by overriding
FS.resolvefor(<common dir>, "logs")in theFSit opens linked worktrees with.
- Ngôn ngữ chính
- Java
- Star
- 427
- Fork
- 116
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của eclipse-jgit/jgit
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
eclipse-jgit/jgit#329 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
eclipse-jgit/jgit#327 ·
-
Repository.create(boolean bare) should provide a no-arg overload that uses isBare()Có thể làm lại được @hardikyadav12 đã nhận 77 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
eclipse-jgit/jgit#297 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
eclipse-jgit/jgit#293 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
eclipse-jgit/jgit#288 ·
Tất cả issue của eclipse-jgit/jgit
Issue tương tự
-
? - Needs Triage bot_watch bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NVIDIA/cudf-spark-jni#5594 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Upgrade solr to 9.11.0Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
DataONEorg/dataone-indexer#390 ·