Fix bd-270: Detect and handle Git merge conflicts in JSONL auto-import
- Add pre-parse merge conflict marker detection before JSON parsing - Show clear error message when conflicts are detected - Provide resolution instructions (Git client or bd export) - Add TestAutoImportMergeConflict test case - Prevents silent auto-import failures from cryptic parse errors Amp-Thread-ID: https://ampcode.com/threads/T-d83011c0-7dfc-49c9-96c1-05c94ec2a3d3 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
@@ -208,6 +209,22 @@ func autoImportIfNewer() {
|
||||
fmt.Fprintf(os.Stderr, "Debug: auto-import triggered (hash changed)\n")
|
||||
}
|
||||
|
||||
// Check for Git merge conflict markers (bd-270)
|
||||
conflictMarkers := []string{"<<<<<<< ", "=======", ">>>>>>> "}
|
||||
for _, marker := range conflictMarkers {
|
||||
if bytes.Contains(jsonlData, []byte(marker)) {
|
||||
fmt.Fprintf(os.Stderr, "\n❌ Git merge conflict detected in %s\n\n", jsonlPath)
|
||||
fmt.Fprintf(os.Stderr, "The JSONL file contains unresolved merge conflict markers.\n")
|
||||
fmt.Fprintf(os.Stderr, "This prevents auto-import from loading your issues.\n\n")
|
||||
fmt.Fprintf(os.Stderr, "To resolve:\n")
|
||||
fmt.Fprintf(os.Stderr, " 1. Resolve the merge conflict in your Git client, OR\n")
|
||||
fmt.Fprintf(os.Stderr, " 2. Export from database to regenerate clean JSONL:\n")
|
||||
fmt.Fprintf(os.Stderr, " bd export -o %s\n\n", jsonlPath)
|
||||
fmt.Fprintf(os.Stderr, "After resolving, commit the fixed JSONL file.\n")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Content changed - parse all issues
|
||||
scanner := bufio.NewScanner(strings.NewReader(string(jsonlData)))
|
||||
scanner.Buffer(make([]byte, 0, 1024), 2*1024*1024) // 2MB buffer for large JSON lines
|
||||
|
||||
Reference in New Issue
Block a user