Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions cmd/entire/cli/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,9 @@ func setupEntireDirectory() error {
return fmt.Errorf("failed to create .entire directory: %w", err)
}

// Create .gitignore to ignore tmp folder and local settings
gitignorePath := filepath.Join(entireDirAbs, ".gitignore")
gitignoreContent := "tmp/\nsettings.local.json\n"

//nolint:gosec // G306: Config file needs standard permissions for git
if err := os.WriteFile(gitignorePath, []byte(gitignoreContent), 0o644); err != nil {
return fmt.Errorf("failed to write .gitignore: %w", err)
// Create/update .gitignore with all required entries
if err := strategy.EnsureEntireGitignore(); err != nil {
return fmt.Errorf("failed to setup .gitignore: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/entire/cli/strategy/auto_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ func (s *AutoCommitStrategy) getSessionLogLegacy(checkpointID string) ([]byte, s

// EnsureSetup ensures the strategy's required setup is in place.
// For auto-commit strategy:
// - Gitignore metadata/
// - Ensure .entire/.gitignore has all required entries
// - Create orphan entire/sessions branch if it doesn't exist
func (s *AutoCommitStrategy) EnsureSetup() error {
if err := EnsureMetadataGitignore(); err != nil {
if err := EnsureEntireGitignore(); err != nil {
return err
}

Expand Down
28 changes: 18 additions & 10 deletions cmd/entire/cli/strategy/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ func GetWorktreePath() (string, error) {
return strings.TrimSpace(string(output)), nil
}

// EnsureMetadataGitignore ensures metadata/ and current_session are in .entire/.gitignore
// EnsureEntireGitignore ensures all required entries are in .entire/.gitignore
// Works correctly from any subdirectory within the repository.
func EnsureMetadataGitignore() error {
func EnsureEntireGitignore() error {
// Get absolute path for the gitignore file
gitignoreAbs, err := paths.AbsPath(entireGitignore)
if err != nil {
Expand All @@ -377,13 +377,21 @@ func EnsureMetadataGitignore() error {
content = string(data)
}

// All entries that should be in .entire/.gitignore
requiredEntries := []string{
"tmp/",
"settings.local.json",
"metadata/",
"current_session",
"logs/",
}

// Track what needs to be added
var toAdd []string
if !strings.Contains(content, "metadata/") {
toAdd = append(toAdd, "metadata/")
}
if !strings.Contains(content, "current_session") {
toAdd = append(toAdd, "current_session")
for _, entry := range requiredEntries {
if !strings.Contains(content, entry) {
toAdd = append(toAdd, entry)
}
}

// Nothing to add
Expand All @@ -397,11 +405,11 @@ func EnsureMetadataGitignore() error {
}

// Append missing entries to gitignore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, contentSb73 was kind of a bizare name.

var contentSb73 strings.Builder
var sb strings.Builder
for _, entry := range toAdd {
contentSb73.WriteString(entry + "\n")
sb.WriteString(entry + "\n")
}
content += contentSb73.String()
content += sb.String()

if err := os.WriteFile(gitignoreAbs, []byte(content), 0o644); err != nil { //nolint:gosec // path is from AbsPath or constant
return fmt.Errorf("failed to write gitignore: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/entire/cli/strategy/manual_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *ManualCommitStrategy) ValidateRepository() error {

// EnsureSetup ensures the strategy is properly set up.
func (s *ManualCommitStrategy) EnsureSetup() error {
if err := EnsureMetadataGitignore(); err != nil {
if err := EnsureEntireGitignore(); err != nil {
return err
}
// Install generic hooks (they delegate to strategy at runtime)
Expand Down