Archived
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:
@@ -2,9 +2,11 @@ package theme
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
|
||||
"submarine/internal/submodule"
|
||||
)
|
||||
@@ -27,13 +29,28 @@ func IssueWord(k submodule.IssueKind) string {
|
||||
return "conflict"
|
||||
case submodule.IssueOffPin:
|
||||
return "off pin"
|
||||
case submodule.IssueOffTarget:
|
||||
return "off target"
|
||||
default:
|
||||
return "changed"
|
||||
}
|
||||
}
|
||||
|
||||
// RoleWord is the label of a commit's role on the detail pane's spine.
|
||||
func RoleWord(r submodule.Role) string {
|
||||
// maxTargetWidth limits the branch name that labels the target on the spine.
|
||||
const maxTargetWidth = 16
|
||||
|
||||
// ShortRef is a remote ref without its remote, e.g. "marco-dev" for
|
||||
// "origin/marco-dev", cut to maxTargetWidth with an ellipsis.
|
||||
func ShortRef(ref string) string {
|
||||
if _, name, ok := strings.Cut(ref, "/"); ok {
|
||||
ref = name
|
||||
}
|
||||
return ansi.Truncate(ref, maxTargetWidth, "…")
|
||||
}
|
||||
|
||||
// RoleWord is the label of a commit's role on the detail pane's spine; the
|
||||
// target is labelled with the name of its branch.
|
||||
func RoleWord(r submodule.Role, target string) string {
|
||||
switch r {
|
||||
case submodule.RolePin:
|
||||
return "pin"
|
||||
@@ -43,6 +60,11 @@ func RoleWord(r submodule.Role) string {
|
||||
return Staged
|
||||
case submodule.RoleBase:
|
||||
return "base"
|
||||
case submodule.RoleTarget:
|
||||
if target == "" {
|
||||
return "target"
|
||||
}
|
||||
return ShortRef(target)
|
||||
case submodule.RoleTip:
|
||||
return "tip"
|
||||
default:
|
||||
@@ -118,6 +140,8 @@ func (t Theme) LevelStyle(l submodule.Level, base lipgloss.Style) lipgloss.Style
|
||||
return base.Foreground(t.Danger).Bold(true)
|
||||
case submodule.LevelWarn:
|
||||
return base.Foreground(t.Warn)
|
||||
case submodule.LevelInfo:
|
||||
return base.Foreground(t.Info)
|
||||
default:
|
||||
return base.Foreground(t.Muted)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user