Compare pins with a target branch and flag pins off it

The ref of a pin was the closest branch containing it, so a pin on a
feature branch looked like a perfect one, and the ref changed with the
branch checked out in the submodule. Split it in two:

- Pin.Target is the branch the pin should be on: `branch =` of
  .gitmodules (none if it does not exist locally), else the remote's
  default branch.
- Pin.Ref is shown: the target if the pin is on it, else the branch
  containing the pin with the fewest commits after it. A tie goes to the
  upstream of the checked-out branch, then to the first name; no branch is
  a favorite.

A pushed pin that is not on its target is `off target`, a new issue at the
new level Info (blue), counted in the header and below collapsed rows. The
spine shows the target's tip, labelled with its branch name, so the
distance from it is visible; a diverged one is the fork. The role words in
a spine label are styled separately and `you` is bold.

Add Status.TargetTip, TargetDrift and Bases.Target, Pin.Target and
Pin.Branches; drop RefSource.IsTarget. The detail pane's label column is 11
wide for the word `off target`.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 17:35:16 +02:00
co-authored by Claude Sonnet 5.5
parent f287d6009f
commit e8d366d88f
19 changed files with 606 additions and 238 deletions
+23 -10
View File
@@ -67,10 +67,10 @@ const (
type RefSource int
const (
RefFromGitmodules RefSource = iota
RefFromCurrentBranch
RefFromDefaultBranch
RefFromContains
RefFromGitmodules RefSource = iota // the target, `branch =` in .gitmodules; the pin is on it
RefFromDefaultBranch // the target, the remote's default branch; the pin is on it
RefFromContains // a branch containing the pin, which is not on the target
RefFromCurrentBranch // upstream of the checked-out branch, there being no better
RefFromTag
RefFromSHA
)
@@ -79,12 +79,12 @@ func (r RefSource) String() string {
switch r {
case RefFromGitmodules:
return ".gitmodules branch"
case RefFromCurrentBranch:
return "checked out branch"
case RefFromDefaultBranch:
return "remote default branch"
case RefFromContains:
return "branch containing pin"
case RefFromCurrentBranch:
return "checked out branch"
case RefFromTag:
return "tag"
default:
@@ -96,9 +96,17 @@ func (r RefSource) String() string {
type PinInfo struct {
Ref string // e.g. "origin/main"; empty if unresolved
Source RefSource
// Target is the branch the pin is supposed to be on (`branch =` of
// .gitmodules, else the remote's default branch); empty if there is none or
// it does not exist locally. Ref is the target if the pin is on it, else
// the branch the pin is on instead.
Target string
Ahead int // commits in pin not in ref
Behind int // commits in ref not in pin
Pushed bool // pin is reachable from some remote ref
// Branches are remote branches other than Ref that contain the pin, oldest
// tip first and limited.
Branches []string
}
// Commit is a short commit description.
@@ -179,7 +187,7 @@ type Distance struct{ Ahead, Behind int }
// Bases are the merge bases of the pin with the commits that have diverged
// from it, where the histories split. A field is nil if that commit has not
// diverged or the base is unknown.
type Bases struct{ Tip, Checkout, Committed *Commit }
type Bases struct{ Tip, Checkout, Committed, Target *Commit }
// Status is the full state of one submodule.
type Status struct {
@@ -198,7 +206,12 @@ type Status struct {
// only added. CommittedDrift compares it with Pinned like Drift.
Committed *Commit
CommittedDrift Distance
Bases Bases
Changes *Changes // nil if the worktree is clean or the details are unknown
FetchedAt time.Time // last fetch of the submodule; zero if never
// TargetTip is the tip of Pin.Target if the pin is not on it (the ref is
// another branch), else nil. TargetDrift compares it with Pinned like
// Drift: Ahead = commits only the target has.
TargetTip *Commit
TargetDrift Distance
Bases Bases
Changes *Changes // nil if the worktree is clean or the details are unknown
FetchedAt time.Time // last fetch of the submodule; zero if never
}