~gitpocket/gitpocket

4

fix(import): only pass signed-commits to fast-export when git supports it

commit
4b5e48eebab4ce62f9be9b6ab232cb40a4f113b1 browse tree
parent
7f502c8c8384ee728652be25cba55f9a59ac6422
author
obscurejames <354576047+obscurejames@users.noreply.github.com>
signature
Signed by: ~james SHA256:KlzJ0P0gvJcnOYpaxD5yCUw52ImHttTKRjVAEnnYnKg
date
2026-11-13 17:49 UTC

1 files changed, +10 −1

forge/import.go modified

@@ -366,11 +366,20 @@ func (s *Server) claim(w http.ResponseWriter, r *http.Request, repo Repo) {
366366 s.render(w, r, "claim", page{Title: "Claim commits", Error: r.URL.Query().Get("error"), Data: map[string]any{"Page": rp, "Identities": ids, "Name": name, "Email": email}})
367367 }
368368
369+var signedCommitsFlag = sync.OnceValue(func() bool {
370+ out, _ := exec.Command("git", "fast-export", "-h").CombinedOutput()
371+ return bytes.Contains(out, []byte("signed-commits"))
372+})
373+
369374 func rewriteAuthors(dir string, picked map[string]bool, to string) error {
370375 ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
371376 defer cancel()
372377 env := []string{"GIT_CONFIG_NOSYSTEM=1", "HOME=/nonexistent", "LC_ALL=C.UTF-8", "PATH=" + os.Getenv("PATH")}
373- export := exec.CommandContext(ctx, "git", "-C", dir, "fast-export", "--all", "--no-data", "--signed-tags=strip", "--signed-commits=strip", "--reencode=yes")
378+ args := []string{"-C", dir, "fast-export", "--all", "--no-data", "--signed-tags=strip", "--reencode=yes"}
379+ if signedCommitsFlag() {
380+ args = append(args, "--signed-commits=strip")
381+ }
382+ export := exec.CommandContext(ctx, "git", args...)
374383 imp := exec.CommandContext(ctx, "git", "-C", dir, "fast-import", "--quiet", "--force")
375384 export.Env, imp.Env = env, env
376385 var errb bytes.Buffer