Skip to content

fix(git): repair the mainSCMDir/scmDir directory-role invariant - #7825

Closed
e-kulikov wants to merge 1 commit into
JanDeDobbeleer:nextfrom
e-kulikov:fix/git-worktree-common-dir
Closed

fix(git): repair the mainSCMDir/scmDir directory-role invariant#7825
e-kulikov wants to merge 1 commit into
JanDeDobbeleer:nextfrom
e-kulikov:fix/git-worktree-common-dir

Conversation

@e-kulikov

Copy link
Copy Markdown
Contributor

Fixes #7798.

Supersedes #7802, which GitHub cannot reopen after its base ref was deleted and the head branch was force-pushed.

Prerequisites

  • I have read and understood the contributing guide.
  • The commit message follows the conventional commits guidelines.
  • Tests for the changes have been added.
  • Docs have been added/updated where relevant.

Description

mainSCMDir is meant to be the current checkout's own git directory (where HEAD, index and
rebase/merge state live) and scmDir the repository's shared directory (config, refs/stash,
worktrees/). Several discovery branches assigned these backwards — a linked worktree's, a
--separate-git-dir clone's and a bare-via-.git-file layout's, plus a submodule's own linked
worktree, which needed the split the other way round. Every reader that expects the shared directory
but gets the per-checkout one breaks the same way: .Remotes comes back empty, .WorktreeCount reads
zero, repoName() returns an empty string, and a submodule's linked worktree can even display its
parent's branch instead of its own.

This PR establishes the invariant properly across every layout (plain clone, linked worktree, bare,
submodule, submodule worktree, --separate-git-dir) and repoints the affected readers —
getGitConfig()/Remotes(), WorktreeCount(), repoName(), native git status, and the git config
memoisation that was poisoning subsequent reads — at the correct directory for each. A structural
check guards against acting on an empty directory when a segment is restored from cache before
discovery has run, so a cache-restore race cannot silently poison a memoised lookup.

Verified end to end across all measured positions with the regression tests.

This is part of a stacked series

next (includes #7801)
 └─ fix/git-worktree-common-dir      (this PR)
     └─ fix/git-bare-head-upstream   → #7803
         └─ feat/statusline-payload-pwd → #7804

Each branch contributes one commit. The later PRs temporarily include their predecessors and shrink
to their own commit as the stack is merged in order.

Keep mainSCMDir checkout-specific and scmDir repository-wide across worktrees, submodules, bare repositories, and separate git directories.

Read config, remotes, worktree counts, repository names, and native status from the correct directory, with regression coverage for the supported layouts.

Fixes JanDeDobbeleer#7798
@github-actions

Copy link
Copy Markdown

📦 Release binary size report

Compares this PR's release-equivalent build against the latest published release, per OS (amd64).

OS Baseline This PR Delta
darwin 13.79 MB 13.79 MB -4.0 KB (-0.03%)
linux 13.46 MB 13.46 MB +0.0 KB (+0%)
windows 14.02 MB 13.98 MB -39.8 KB (-0.28%)

🎉 Binary size shrank on at least one platform.

@JanDeDobbeleer

Copy link
Copy Markdown
Owner

this shouldn't have been closed my bad.

@e-kulikov

Copy link
Copy Markdown
Contributor Author

No worries — thanks for confirming.

This one can't be reopened: next no longer exists upstream, so the base ref is gone and gh pr reopen 404s on it. Since next had already been merged into main, I've rebased onto main and opened a fresh PR instead of waiting for next to come back:

#7828

Same commit, same content as this PR, just rebased onto current main. #7801 and #7804 have landed in the meantime, so it's down to a single commit now.

I'll reopen the follow-up (fix/git-bare-head-upstream, was #7803) against main as well once this one is in.

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.

2 participants