termui: check sketch-host remote when formatting cherry-pick command
Update getGitRefName function to look for commit references in the
sketch-host remote when local branch names are not available.
This makes the cherry-pick command display more user-friendly
by using remote branch names when possible.
Co-Authored-By: sketch <hello@sketch.dev>
diff --git a/termui/termui.go b/termui/termui.go
index e6e5b4e..3a0be7a 100644
--- a/termui/termui.go
+++ b/termui/termui.go
@@ -404,7 +404,7 @@
// 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
+ // local branch or tag name
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", sha)
branchName, err := cmd.Output()
if err == nil {
@@ -415,6 +415,22 @@
}
}
+ // 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)
shortSha, err := cmd.Output()