Skip to content

Commit d924b1b

Browse files
Copilotpelikhan
andcommitted
feat: auto-generate .gitignore in .aw directory
- Install command now creates .aw/.gitignore automatically - This ensures imports/ folder is ignored even without root .gitignore - Prevents accidental commits of cached imported files - Updates documentation to reflect this automatic behavior Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 21a9f06 commit d924b1b

6 files changed

Lines changed: 3303 additions & 3258 deletions

File tree

.github/workflows/artifacts-summary.lock.yml

Lines changed: 849 additions & 847 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/ci-doctor.lock.yml

Lines changed: 856 additions & 854 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/dev.lock.yml

Lines changed: 849 additions & 847 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/tidy.lock.yml

Lines changed: 709 additions & 709 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/content/docs/reference/imports.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The install command:
5656
3. Clones repositories at the specified versions
5757
4. Stores imported files in `.aw/imports/`
5858
5. Creates/updates `.aw/imports.lock` with resolved SHAs
59+
6. Creates `.aw/.gitignore` to automatically ignore the `imports/` folder
5960

6061
## Lock File
6162

@@ -136,7 +137,9 @@ Result: GitHub tools will have both sets of allowed functions.
136137

137138
## Version Control
138139

139-
Add `.aw/imports/` to `.gitignore` to exclude cached imported files while keeping the lock file:
140+
The `gh aw install` command automatically creates a `.aw/.gitignore` file that ignores the `imports/` folder. This ensures the cached imported files are not committed while the lock file remains trackable.
141+
142+
You can also add `.aw/imports/` to your project's root `.gitignore` for additional protection:
140143

141144
```gitignore
142145
# Workflow imports (cached files only, not the lock file)

pkg/cli/install_imports.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func InstallImports(workflowName string, verbose bool) error {
6565
return fmt.Errorf("failed to create .aw directory: %w", err)
6666
}
6767

68+
// Create .gitignore in .aw directory to ignore imports folder
69+
if err := ensureAwGitignore(awDir, verbose); err != nil {
70+
return fmt.Errorf("failed to create .aw/.gitignore: %w", err)
71+
}
72+
6873
// Read existing lock file
6974
lock, err := parser.ReadImportLockFile(lockFilePath)
7075
if err != nil {
@@ -415,3 +420,34 @@ func collectTransitiveFiles(filePath, baseDir string, verbose bool) ([]string, e
415420

416421
return files, nil
417422
}
423+
424+
// ensureAwGitignore creates or updates .gitignore in .aw directory to ignore imports folder
425+
func ensureAwGitignore(awDir string, verbose bool) error {
426+
gitignorePath := filepath.Join(awDir, ".gitignore")
427+
428+
// Content to write - ignore the imports folder
429+
content := "# Ignore cached imported files\nimports/\n"
430+
431+
// Check if .gitignore already exists
432+
existingContent, err := os.ReadFile(gitignorePath)
433+
if err == nil {
434+
// File exists, check if it already has the imports/ entry
435+
if strings.Contains(string(existingContent), "imports/") {
436+
// Already configured, no need to update
437+
return nil
438+
}
439+
// Append to existing content
440+
content = string(existingContent) + "\n" + content
441+
}
442+
443+
// Write the .gitignore file
444+
if err := os.WriteFile(gitignorePath, []byte(content), 0644); err != nil {
445+
return fmt.Errorf("failed to write .gitignore: %w", err)
446+
}
447+
448+
if verbose {
449+
fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Created/updated %s", gitignorePath)))
450+
}
451+
452+
return nil
453+
}

0 commit comments

Comments
 (0)