Skip to content
Closed
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
1 change: 1 addition & 0 deletions .github/aw/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
imports/
68 changes: 68 additions & 0 deletions pkg/cli/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,74 @@ func ensureLogsGitignore() error {
return nil
}

// awGitignoreEntries lists all entries that must be present in .github/aw/.gitignore.
// Note: the logs/ directory is handled separately by ensureLogsGitignore() which creates
// .github/aw/logs/.gitignore so that the directory itself remains tracked by git.
var awGitignoreEntries = []string{"imports/"}

// ensureAwGitignore ensures that .github/aw/.gitignore exists and contains the required entries.
// If the file already exists, any missing entries are appended.
func ensureAwGitignore() error {
gitLog.Print("Ensuring .github/aw/.gitignore exists")
gitRoot, err := findGitRoot()
if err != nil {
return err
}

awDir := filepath.Join(gitRoot, ".github", "aw")
gitignorePath := filepath.Join(awDir, ".gitignore")

if err := os.MkdirAll(awDir, 0755); err != nil {
gitLog.Printf("Failed to create .github/aw directory: %v", err)
return fmt.Errorf("failed to create .github/aw directory: %w", err)
}

// Read existing content (if any)
existing, readErr := os.ReadFile(gitignorePath)
existingContent := ""
if readErr == nil {
existingContent = string(existing)
gitLog.Print(".github/aw/.gitignore already exists, checking for missing entries")
}

// Collect any entries that are not yet present
var missing []string
for _, entry := range awGitignoreEntries {
if !strings.Contains(existingContent, entry) {
missing = append(missing, entry)
}
}

if len(missing) == 0 {
gitLog.Print(".github/aw/.gitignore already contains all required entries")
return nil
}

// Append missing entries (ensure file ends with a newline before appending)
appendContent := ""
if existingContent != "" && !strings.HasSuffix(existingContent, "\n") {
appendContent = "\n"
}
for _, entry := range missing {
appendContent += entry + "\n"
}

f, err := os.OpenFile(gitignorePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
gitLog.Printf("Failed to open .gitignore for writing: %v", err)
return fmt.Errorf("failed to write .github/aw/.gitignore: %w", err)
}
defer f.Close()

if _, err := f.WriteString(appendContent); err != nil {
gitLog.Printf("Failed to write .gitignore: %v", err)
return fmt.Errorf("failed to write .github/aw/.gitignore: %w", err)
}

gitLog.Printf("Successfully updated .github/aw/.gitignore (added: %v)", missing)
return nil
}

// getCurrentBranch gets the current git branch name
func getCurrentBranch() (string, error) {
gitLog.Print("Getting current git branch")
Expand Down
10 changes: 10 additions & 0 deletions pkg/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ func InitRepository(opts InitOptions) error {
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Configured .gitattributes"))
}

// Ensure .github/aw/.gitignore exists with imports/ entry
initLog.Print("Ensuring .github/aw/.gitignore exists")
if err := ensureAwGitignore(); err != nil {
initLog.Printf("Failed to ensure .github/aw/.gitignore: %v", err)
return fmt.Errorf("failed to ensure .github/aw/.gitignore: %w", err)
}
if opts.Verbose {
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Ensured .github/aw/.gitignore"))
}

// Write dispatcher agent
initLog.Print("Writing agentic workflows dispatcher agent")
if err := ensureAgenticWorkflowsDispatcher(opts.Verbose, false); err != nil {
Expand Down