Skip to content

fix(git): interpret bare HEAD through the shared resolver and stop overwriting .Upstream with the remote list - #7830

Open
e-kulikov wants to merge 2 commits into
JanDeDobbeleer:mainfrom
e-kulikov:fix/git-bare-head-upstream
Open

fix(git): interpret bare HEAD through the shared resolver and stop overwriting .Upstream with the remote list#7830
e-kulikov wants to merge 2 commits into
JanDeDobbeleer:mainfrom
e-kulikov:fix/git-bare-head-upstream

Conversation

@e-kulikov

Copy link
Copy Markdown
Contributor

Fixes #7799.

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

getBareRepoInfo() hand-rolled a HEAD parse that only understood ref: refs/heads/… — a reftables
repository rendered .Ref as .invalid, and a detached bare HEAD rendered the full 40-character
object ID with .Detached false and .Hash/.ShortHash empty, even though the non-bare path already
handles all of this correctly. Separately, .Upstream was assigned the raw, newline-separated output
of git remote — with two remotes configured, that put a literal line break in the middle of the
prompt.

This PR routes bare HEAD interpretation through the same resolver the non-bare path already uses, and
replaces the .Upstream assignment with a real upstream/remote-selection lookup, resolving to the
branch's actual upstream (or empty, when none is configured) instead of the remote list. Most of the
directory-selection machinery this originally needed is no longer necessary, since the directory-role
fix below already makes the current checkout's git directory correct in every layout this PR touches.

Verified with new tests covering reftables, detached HEAD, single- and multi-remote bare repositories,
and the existing non-bare behaviour, confirmed unchanged.

Replaces #7803

#7803 was closed automatically when the next branch was deleted upstream — not because of anything
in the code. This is the same work, rebased onto main as a single commit, per the request to rebase
and squash. The earlier review discussion lives in #7803.

This is part of a stacked series

main (includes #7801, #7804)
 └─ fix/git-worktree-common-dir                 → #7828 (issue #7798)
     └─ fix/git-bare-head-upstream (this PR)    → issue #7799

This branch adds one commit on top of fix/git-worktree-common-dir (#7828) and depends on it
directly: the simplified HEAD resolution here assumes that PR's directory-role fix has landed.
Concretely, it relies on hasWorktree no longer repointing mainSCMDir at the working-tree root in
the --separate-git-dir branch — without that, updateHEADReference() reads HEAD from the wrong
directory and the bare-repository case in #7799 stays broken. Until #7828 merges, this PR's diff
includes its commit too; it will then shrink to this PR's own single commit.

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
Resolve bare HEAD through the shared ref resolver so detached HEAD and
reftables are handled consistently with the non-bare path.

Populate Upstream from git while keeping the remote inventory separate,
and document and test the bare repository fields.

Fixes JanDeDobbeleer#7799
@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.80 MB 13.80 MB +4.0 KB (+0.03%)
linux 13.46 MB 13.46 MB +4.0 KB (+0.03%)
windows 14.02 MB 13.99 MB -38.3 KB (-0.27%)

🎉 Binary size shrank on at least one platform.

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.

Bare repositories: .Ref/.HEAD mishandle detached HEAD and reftables, and .Upstream holds the raw remote list

1 participant