Add conflict marker detection to bd import/validate
- bd import now detects git conflict markers and shows resolution steps - bd validate --checks=conflicts improved with clearer instructions - Updated AGENTS.md with better conflict resolution docs - Closes bd-7e7ddffa epic (repair tools complete) Amp-Thread-ID: https://ampcode.com/threads/T-4a11a65b-56c2-4d92-8f68-66f0a56ab5e3 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -59,24 +59,34 @@ Behavior:
|
||||
lineNum := 0
|
||||
|
||||
for scanner.Scan() {
|
||||
lineNum++
|
||||
line := scanner.Text()
|
||||
lineNum++
|
||||
line := scanner.Text()
|
||||
|
||||
// Skip empty lines
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Parse JSON
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal([]byte(line), &issue); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing line %d: %v\n", lineNum, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
allIssues = append(allIssues, &issue)
|
||||
// Skip empty lines
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Detect git conflict markers
|
||||
if strings.Contains(line, "<<<<<<<") || strings.Contains(line, "=======") || strings.Contains(line, ">>>>>>>") {
|
||||
fmt.Fprintf(os.Stderr, "Error: Git conflict markers detected in JSONL file (line %d)\n\n", lineNum)
|
||||
fmt.Fprintf(os.Stderr, "To resolve:\n")
|
||||
fmt.Fprintf(os.Stderr, " git checkout --ours .beads/issues.jsonl && bd import -i .beads/issues.jsonl\n")
|
||||
fmt.Fprintf(os.Stderr, " git checkout --theirs .beads/issues.jsonl && bd import -i .beads/issues.jsonl\n\n")
|
||||
fmt.Fprintf(os.Stderr, "For advanced field-level merging, see: https://github.com/neongreen/mono/tree/main/beads-merge\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Parse JSON
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal([]byte(line), &issue); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing line %d: %v\n", lineNum, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
allIssues = append(allIssues, &issue)
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error reading input: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -400,17 +400,21 @@ func validateGitConflicts(_ context.Context, fix bool) checkResult {
|
||||
if len(conflictLines) > 0 {
|
||||
result.issueCount = 1 // One conflict situation
|
||||
result.suggestions = append(result.suggestions,
|
||||
fmt.Sprintf("Resolve git conflict in %s (markers at lines: %v)", jsonlPath, conflictLines))
|
||||
if !fix {
|
||||
result.suggestions = append(result.suggestions,
|
||||
fmt.Sprintf("Then run 'bd import -i %s' to reload issues", jsonlPath))
|
||||
}
|
||||
fmt.Sprintf("Git conflict markers found in %s at lines: %v", jsonlPath, conflictLines))
|
||||
result.suggestions = append(result.suggestions,
|
||||
"To resolve, choose one version:")
|
||||
result.suggestions = append(result.suggestions,
|
||||
" git checkout --ours .beads/issues.jsonl && bd import -i .beads/issues.jsonl")
|
||||
result.suggestions = append(result.suggestions,
|
||||
" git checkout --theirs .beads/issues.jsonl && bd import -i .beads/issues.jsonl")
|
||||
result.suggestions = append(result.suggestions,
|
||||
"For advanced field-level merging: https://github.com/neongreen/mono/tree/main/beads-merge")
|
||||
}
|
||||
|
||||
// Can't auto-fix git conflicts
|
||||
if fix && result.issueCount > 0 {
|
||||
result.suggestions = append(result.suggestions,
|
||||
"Git conflicts cannot be auto-fixed. Resolve manually in your editor or run 'bd export' to regenerate JSONL")
|
||||
"Note: Git conflicts cannot be auto-fixed with --fix-all")
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user