fierj
PublicTiny personal git forge
3ea37b999102d74a74c3cb9eb1c514b4adb4f4a7
diff --git a/patch.go b/patch.go
index b4e85f3..bfeef51 100644
--- a/patch.go
+++ b/patch.go
@@ -260,15 +260,30 @@ func fastForwardMerge(repoPath, target, branch string) error {
return nil
}
-// nonDefaultBranches returns branches that aren't the default (potential patches).
+// headTarget returns the symbolic-ref target of HEAD even if the branch
+// doesn't exist yet. Returns "" if HEAD is detached or unreadable.
+func headTarget(repoPath string) string {
+ name := strings.TrimSuffix(filepath.Base(repoPath), ".git")
+ g := &Git{Dir: filepath.Dir(repoPath), Name: name}
+ out, err := g.cmd("symbolic-ref", "--short", "HEAD")
+ if err != nil {
+ return ""
+ }
+ return strings.TrimSpace(out)
+}
+
+// nonDefaultBranches returns branches that aren't the primary branch
+// (the one HEAD points to, even if it doesn't exist yet). Also excludes
+// wip/ branches. These are candidates for patch submission.
func nonDefaultBranches(repoPath string) []string {
- def := defaultBranch(repoPath)
+ head := headTarget(repoPath)
all := listBranches(repoPath)
var result []string
for _, b := range all {
- if b != def && !strings.HasPrefix(b, "wip/") {
- result = append(result, b)
+ if b == head || strings.HasPrefix(b, "wip/") {
+ continue
}
+ result = append(result, b)
}
return result
}