Attach a refs/notes/byre note to each squash merge and push it
This commit is contained in:
+20
-3
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user