return res
}
+func RepoGetBranchOid() (string, string, error) {
+ cmd := exec.Command("git", "branch", "--show-current")
+ x, err := cmd.Output()
+ if err != nil {
+ return "", "", fmt.Errorf("failed to get branch: %v: %v", cmd, err)
+ }
+ branch := strings.TrimSpace(string(x))
+
+ cmd = exec.Command("git", "rev-parse", "--verify", "--end-of-options",
+ branch)
+ x, err = cmd.Output()
+ if err != nil {
+ return "", "", fmt.Errorf("failed to get oid: %v: %v", cmd, err)
+ }
+ oid := strings.TrimSpace(string(x))
+
+ return oid, branch, nil
+}
+
// RepoGetConfig reads the punyci configuration from the git repo in the
// current working directory.
func RepoGetConfig(ref string) (*Config, error) {
func main() {
usage := func() {
log.SetFlags(0)
- log.Fatalf("usage: %s post-receive", os.Args[0])
+ log.Fatalf("usage: %[1]s post-receive\n"+
+ " %[1]s post-commit", os.Args[0])
}
if len(os.Args) != 2 {
usage()
if err != nil {
log.Fatal(err)
}
+ case "post-commit":
+ err := postCommit()
+ if err != nil {
+ log.Fatal(err)
+ }
case "internal-post-receive":
err := internalPostReceive()
if err != nil {
}
pushOptions := HookGetPushOptions()
+ return foreground(oid, branch, pushOptions)
+}
+
+func postCommit() error {
+ oid, branch, err := RepoGetBranchOid()
+ if err != nil {
+ return err
+ }
+
+ err = os.Chdir(".git")
+ if err != nil {
+ return err
+ }
+
+ return foreground(oid, branch, nil)
+}
+
+func foreground(oid, branch string, pushOptions []string) error {
cfg, err := RepoGetConfig(oid)
if err != nil {
return err
return err
}
name := filepath.Base(cwd)
+ if name == ".git" {
+ // For "post-commit"
+ name = filepath.Base(filepath.Dir(cwd))
+ }
tmp, err := os.MkdirTemp("", "punyci-")
if err != nil {