termui: remove git ref beautification for cherry-pick commands
Use short SHAs instead of branch/ref names in cherry-pick suggestions
to avoid issues with git ref skew between local and sketch-host.
Co-Authored-By: sketch <hello@sketch.dev>
diff --git a/termui/termui.go b/termui/termui.go
index 322b23d..e9bd202 100644
--- a/termui/termui.go
+++ b/termui/termui.go
@@ -256,7 +256,7 @@
branches = append(branches, branch)
}
- initialCommitRef := getGitRefName(ui.agent.InitialCommit())
+ initialCommitRef := getShortSHA(ui.agent.InitialCommit())
if len(branches) == 1 {
ui.AppendSystemMessage("\nš Branch pushed during session: %s", branches[0])
ui.AppendSystemMessage("š To add those changes to your branch: git cherry-pick %s..%s", initialCommitRef, branches[0])
@@ -431,40 +431,9 @@
ui.termLogCh <- fmt.Sprintf(fmtString, args...)
}
-// getGitRefName returns a readable git ref for sha, falling back to the original sha on error.
-func getGitRefName(sha string) string {
- // Best-effort git fetch --prune to ensure we have the latest refs
- exec.Command("git", "fetch", "--prune", "sketch-host").Run()
-
- // local branch or tag name
- cmd := exec.Command("git", "rev-parse", "--abbrev-ref", sha)
- branchName, err := cmd.Output()
- if err == nil {
- branchStr := strings.TrimSpace(string(branchName))
- // If we got a branch name that's not HEAD, use it
- if branchStr != "" && branchStr != "HEAD" {
- return branchStr
- }
- }
-
- // check sketch-host (outer) remote branches
- cmd = exec.Command("git", "branch", "-r", "--contains", sha)
- remoteBranches, err := cmd.Output()
- if err == nil {
- for line := range strings.Lines(string(remoteBranches)) {
- line = strings.TrimSpace(line)
- if line == "" {
- continue
- }
- suf, ok := strings.CutPrefix(line, "sketch-host/")
- if ok {
- return suf
- }
- }
- }
-
- // short SHA
- cmd = exec.Command("git", "rev-parse", "--short", sha)
+// getShortSHA returns the short SHA for the given git reference, falling back to the original SHA on error.
+func getShortSHA(sha string) string {
+ cmd := exec.Command("git", "rev-parse", "--short", sha)
shortSha, err := cmd.Output()
if err == nil {
shortStr := strings.TrimSpace(string(shortSha))
@@ -472,6 +441,5 @@
return shortStr
}
}
-
return sha
}