Attach a refs/notes/byre note to each squash merge and push it

This commit is contained in:
Ian Gulliver
2026-10-15 19:44:53 -07:00
parent c5e3a680d8
commit 6741177f53
8 changed files with 275 additions and 11 deletions
+20 -3
View File
@@ -3,6 +3,7 @@ package git
import (
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
@@ -217,8 +218,8 @@ const Remote = "origin"
var ErrRemoteMoved = errors.New("the remote's branch has moved")
func Push(repo, commit, branch string) error {
out, stderr, code, err := runCode(repo, nil, "push", "--porcelain", Remote, commit+":refs/heads/"+branch)
func Push(repo, commit, branch, notes string) error {
out, stderr, code, err := runCode(repo, nil, "push", "--atomic", "--porcelain", Remote, commit+":refs/heads/"+branch, notes+":"+NotesRef)
if err != nil {
return err
}
@@ -239,7 +240,7 @@ func FastForward(repo, rev string) error {
}
func FetchFastForward(repo, branch string) error {
_, err := run(repo, "fetch", Remote, branch)
_, err := run(repo, "fetch", Remote)
if err != nil {
return err
}
@@ -303,10 +304,26 @@ func runEnv(dir string, env []string, args ...string) (string, error) {
return out, nil
}
func runInput(dir string, env []string, input string, args ...string) (string, error) {
out, stderr, code, err := runCodeInput(dir, env, strings.NewReader(input), args...)
if err != nil {
return "", err
}
if code != 0 {
return "", fmt.Errorf("git %s: exit status %d: %s", strings.Join(args, " "), code, stderr)
}
return out, nil
}
func runCode(dir string, env []string, args ...string) (string, string, int, error) {
return runCodeInput(dir, env, nil, args...)
}
func runCodeInput(dir string, env []string, stdin io.Reader, args ...string) (string, string, int, error) {
cmd := exec.Command("git", args...)
cmd.Dir = dir
cmd.Env = append(os.Environ(), env...)
cmd.Stdin = stdin
stderr := &strings.Builder{}
cmd.Stderr = stderr
out, err := cmd.Output()