Skip to content

git: worktree, fix treeContainsDirs test to build a new tree for each…#2047

Merged
pjbgf merged 1 commit into
go-git:mainfrom
aymanbagabas:wt-buildtree
May 1, 2026
Merged

git: worktree, fix treeContainsDirs test to build a new tree for each…#2047
pjbgf merged 1 commit into
go-git:mainfrom
aymanbagabas:wt-buildtree

Conversation

@aymanbagabas
Copy link
Copy Markdown
Member

… test case

This makes the TestTreeContainsDirs test more robust by ensuring that each test case operates on a fresh tree instance. This prevents any unintended side effects from previous test cases.

The treeContainsDirs function may write to the tree and cause a race condition when a single tree is shared across multiple test cases. By building a new tree for each test case, we ensure that the tests are isolated and can be run in parallel without interference.

See tree.go:185-189:

  func (t *Tree) entry(baseName string) (*TreeEntry, error) {
      if t.m == nil {       // read t.m
          t.buildMap()      // write t.m
      }
      entry, ok := t.m[baseName]  // read t.m

Fixes: https://github.com/go-git/go-git/actions/runs/25163491857/job/73763612343?pr=2014

… test case

This makes the TestTreeContainsDirs test more robust by ensuring that
each test case operates on a fresh tree instance. This prevents any
unintended side effects from previous test cases.

The treeContainsDirs function may write to the tree and cause a race
condition when a single tree is shared across multiple test cases. By
building a new tree for each test case, we ensure that the tests are
isolated and can be run in parallel without interference.

See tree.go:185-189:

  func (t *Tree) entry(baseName string) (*TreeEntry, error) {
      if t.m == nil {       // read t.m
          t.buildMap()      // write t.m
      }
      entry, ok := t.m[baseName]  // read t.m

Signed-off-by: Ayman Bagabas <[email protected]>
@aymanbagabas aymanbagabas requested a review from pjbgf April 30, 2026 12:00
Copy link
Copy Markdown
Contributor

@onee-only onee-only left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related: #1917
Although this wouldn't fix the root cause of the issue, test isolation still is a great improvement.

Copy link
Copy Markdown
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aymanbagabas thanks for working on this. 🙇

@onee-only thanks for the initial review. 🥇

@pjbgf pjbgf merged commit dd81470 into go-git:main May 1, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants