fierj
PublicTiny personal git forge
1f7ca422774a42c3afaff876bfbed004ce19c6f7
diff --git a/patch.go b/patch.go
index 4681ec4..4d4956c 100644
--- a/patch.go
+++ b/patch.go
@@ -1,8 +1,10 @@
package main
import (
+ "bytes"
"encoding/json"
"fmt"
+ "log/slog"
"os"
"os/exec"
"path/filepath"
@@ -186,13 +188,11 @@ func mergePatch(repoPath string, p *Patch) error {
if current.Branch != "" {
cmd := exec.Command("git", "merge", "--ff-only", current.Branch)
cmd.Dir = repoPath
+ var stderr bytes.Buffer
+ cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
- // Try non-ff merge
- cmd = exec.Command("git", "merge", "--no-ff", "-m", "Merge "+current.Branch, current.Branch)
- cmd.Dir = repoPath
- if err := cmd.Run(); err != nil {
- return fmt.Errorf("merge failed: %w", err)
- }
+ slog.Error("patch merge failed", "repo", filepath.Base(repoPath), "branch", current.Branch, "error", err, "stderr", stderr.String())
+ return fmt.Errorf("cannot fast-forward merge %q: %s", current.Branch, strings.TrimSpace(stderr.String()))
}
} else if current.PatchFile != "" {
patchFilePath := filepath.Join(patchDataDir(repoPath), current.PatchFile)
diff --git a/patch_handlers.go b/patch_handlers.go
index a8eb23d..256e586 100644
--- a/patch_handlers.go
+++ b/patch_handlers.go
@@ -4,6 +4,7 @@ import (
"fmt"
"html/template"
"io"
+ "log/slog"
"net/http"
"strings"
)
@@ -148,6 +149,7 @@ func PatchMergePost(cfg Config, tmpl *template.Template) http.HandlerFunc {
return
}
if err := mergePatch(rp, p); err != nil {
+ slog.Error("merge patch", "repo", git.Name, "patch", patchID, "error", err)
renderError(w, tmpl, http.StatusInternalServerError, err.Error())
return
}
@@ -164,6 +166,7 @@ func PatchClosePost(cfg Config, tmpl *template.Template) http.HandlerFunc {
patchID := r.PathValue("patchId")
rp := repoPath(cfg, git.Name)
if err := closePatch(rp, patchID); err != nil {
+ slog.Error("close patch", "repo", git.Name, "patch", patchID, "error", err)
renderError(w, tmpl, http.StatusInternalServerError, err.Error())
return
}