Fix bd init to auto-import issues from git on fresh clone
Prevents agents from creating duplicate low-numbered issues when starting with a fresh git clone that already has issues.jsonl in git history. Changes: - bd init now checks for existing issues in git after DB creation - Auto-imports with collision resolution if found - Updates AGENTS.md to simplify onboarding (just 'bd init') Fixes the scenario where: 1. Fresh clone has .beads/issues.jsonl in git (212 issues) 2. Agent runs bd init (creates empty DB) 3. Agent starts creating bd-1, bd-2, etc (collisions with git) Now bd init automatically imports all issues from git on first run. Amp-Thread-ID: https://ampcode.com/threads/T-8a41f14d-d4c3-4c50-a18b-5f112110f138 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -43,7 +43,7 @@ func checkAndAutoImport(ctx context.Context, store storage.Storage) bool {
|
||||
}
|
||||
|
||||
// Import from git
|
||||
if err := importFromGit(ctx, store, jsonlPath); err != nil {
|
||||
if err := importFromGit(ctx, dbPath, store, jsonlPath); err != nil {
|
||||
if !jsonOutput {
|
||||
fmt.Fprintf(os.Stderr, "Warning: auto-import failed: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Try manually: git show HEAD:%s | bd import -i /dev/stdin\n", jsonlPath)
|
||||
@@ -130,7 +130,7 @@ func findGitRoot() string {
|
||||
}
|
||||
|
||||
// importFromGit imports issues from git HEAD
|
||||
func importFromGit(ctx context.Context, store storage.Storage, jsonlPath string) error {
|
||||
func importFromGit(ctx context.Context, dbFilePath string, store storage.Storage, jsonlPath string) error {
|
||||
// Get content from git
|
||||
cmd := exec.Command("git", "show", fmt.Sprintf("HEAD:%s", jsonlPath))
|
||||
jsonlData, err := cmd.Output()
|
||||
@@ -167,6 +167,6 @@ func importFromGit(ctx context.Context, store storage.Storage, jsonlPath string)
|
||||
SkipPrefixValidation: true, // Auto-import is lenient about prefixes
|
||||
}
|
||||
|
||||
_, err = importIssuesCore(ctx, dbPath, store, issues, opts)
|
||||
_, err = importIssuesCore(ctx, dbFilePath, store, issues, opts)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user