fix(import): only pass signed-commits to fast-export when git supports it
1 files changed, +10 −1
- forge/import.go modified +10 −1
forge/import.go modified
| @@ -366,11 +366,20 @@ func (s *Server) claim(w http.ResponseWriter, r *http.Request, repo Repo) { | ||
| 366 | 366 | 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}}) |
| 367 | 367 | } |
| 368 | 368 | |
| 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 | + | |
| 369 | 374 | func rewriteAuthors(dir string, picked map[string]bool, to string) error { |
| 370 | 375 | ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute) |
| 371 | 376 | defer cancel() |
| 372 | 377 | 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...) | |
| 374 | 383 | imp := exec.CommandContext(ctx, "git", "-C", dir, "fast-import", "--quiet", "--force") |
| 375 | 384 | export.Env, imp.Env = env, env |
| 376 | 385 | var errb bytes.Buffer |