Improve git cherry-pick display with abbreviated SHA/branch references
This change modifies how git cherry-pick commands are displayed in the UI.
Instead of showing full SHA hashes, it now attempts to:
1. Show branch/tag names if available
2. Fall back to abbreviated SHA via git rev-parse --short
3. Use the original full SHA only if the above methods fail
This makes cherry-pick commands more readable and user-friendly.
Co-Authored-By: sketch <hello@sketch.dev>
diff --git a/termui/termui.go b/termui/termui.go
index 36e5701..82ae67c 100644
--- a/termui/termui.go
+++ b/termui/termui.go
@@ -232,9 +232,10 @@
branches = append(branches, branch)
}
+ initialCommitRef := getGitRefName(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", ui.agent.InitialCommit(), branches[0])
+ ui.AppendSystemMessage("š To add those changes to your branch: git cherry-pick %s..%s", initialCommitRef, branches[0])
} else {
ui.AppendSystemMessage("\nš Branches pushed during session:")
for _, branch := range branches {
@@ -242,7 +243,7 @@
}
ui.AppendSystemMessage("\nš To add all those changes to your branch:")
for _, branch := range branches {
- ui.AppendSystemMessage("git cherry-pick %s..%s", ui.agent.InitialCommit(), branch)
+ ui.AppendSystemMessage("git cherry-pick %s..%s", initialCommitRef, branch)
}
}
}
@@ -388,3 +389,29 @@
func (ui *termUI) AppendSystemMessage(fmtString string, args ...any) {
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 {
+ // 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
+ }
+ }
+
+ // short SHA
+ cmd = exec.Command("git", "rev-parse", "--short", sha)
+ shortSha, err := cmd.Output()
+ if err == nil {
+ shortStr := strings.TrimSpace(string(shortSha))
+ if shortStr != "" {
+ return shortStr
+ }
+ }
+
+ return sha
+}