Enhance .gitignore created during bd init (#98)

- Expand .gitignore to include all SQLite-related files (journal, WAL, SHM)
- Add daemon runtime files (logs, PID, socket)
- Include legacy database filenames
- Explicitly allow JSONL files with !*.jsonl pattern
- Add test coverage to verify .gitignore content
This commit is contained in:
Ben Madore
2025-10-21 16:59:19 -04:00
committed by GitHub
parent 34593cad8c
commit cfe15a9d34
3 changed files with 50 additions and 2 deletions

View File

@@ -44,7 +44,24 @@ and database file. Optionally specify a custom issue prefix.`,
// Create .gitignore in .beads directory
gitignorePath := filepath.Join(beadsDir, ".gitignore")
gitignoreContent := "*.db\n*.db-*\n"
gitignoreContent := `# SQLite databases
*.db
*.db-journal
*.db-wal
*.db-shm
# Daemon runtime files
daemon.log
daemon.pid
bd.sock
# Legacy database files
db.sqlite
bd.db
# Keep JSONL exports (source of truth for git)
!*.jsonl
`
if err := os.WriteFile(gitignorePath, []byte(gitignoreContent), 0644); err != nil {
fmt.Fprintf(os.Stderr, "Warning: failed to create .gitignore: %v\n", err)
// Non-fatal - continue anyway

View File

@@ -113,6 +113,31 @@ func TestInitCommand(t *testing.T) {
t.Error(".beads directory was not created")
}
// Verify .gitignore was created with proper content
gitignorePath := filepath.Join(beadsDir, ".gitignore")
gitignoreContent, err := os.ReadFile(gitignorePath)
if err != nil {
t.Errorf(".gitignore file was not created: %v", err)
} else {
// Check for essential patterns
gitignoreStr := string(gitignoreContent)
expectedPatterns := []string{
"*.db",
"*.db-journal",
"*.db-wal",
"*.db-shm",
"daemon.log",
"daemon.pid",
"bd.sock",
"!*.jsonl",
}
for _, pattern := range expectedPatterns {
if !strings.Contains(gitignoreStr, pattern) {
t.Errorf(".gitignore missing expected pattern: %s", pattern)
}
}
}
// Verify database was created
var dbPath string
if tt.prefix != "" {

View File

@@ -4,4 +4,10 @@ stdout 'initialized successfully'
exists .beads/test.db
exists .beads/.gitignore
grep '^\*\.db$' .beads/.gitignore
grep '^\*\.db-\*$' .beads/.gitignore
grep '^\*\.db-journal$' .beads/.gitignore
grep '^\*\.db-wal$' .beads/.gitignore
grep '^\*\.db-shm$' .beads/.gitignore
grep '^daemon\.log$' .beads/.gitignore
grep '^daemon\.pid$' .beads/.gitignore
grep '^bd\.sock$' .beads/.gitignore
grep '^!\*\.jsonl$' .beads/.gitignore