Skip to content

Allow add-wizard to initialize empty repositories - #51895

Merged
pelikhan merged 9 commits into
mainfrom
copilot/fix-gh-add-wizard-empty-repo
Aug 11, 2026
Merged

Allow add-wizard to initialize empty repositories#51895
pelikhan merged 9 commits into
mainfrom
copilot/fix-gh-add-wizard-empty-repo

Conversation

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

gh aw add-wizard rejected empty repositories after its own initialization files made the working tree appear dirty.

  • Clean-tree validation

    • Exclude only initialization files created after the wizard’s initial clean-tree check.
    • Continue rejecting unrelated staged, modified, or untracked files.
  • PR contents

    • Stage generated repository initialization files alongside the workflow files.
  • Regression coverage

    • Cover newly created and modified tracked initialization files.
    • Verify unrelated changes still block PR creation.

Run URL: https://github.com/github/gh-aw/actions/runs/31450173394> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 24.1 AIC · ⌖ 5.21 AIC · ⊞ 6.1K ·

Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 22.1 AIC · ⌖ 6.79 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI and others added 2 commits August 11, 2026 01:26
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix gh add-wizard failing to add workflow in empty git repository Allow add-wizard to initialize empty repositories Aug 11, 2026
Copilot AI requested a review from pelikhan August 11, 2026 01:29
@pelikhan
pelikhan marked this pull request as ready for review August 11, 2026 01:30
Copilot AI balanced review requested due to automatic review settings August 11, 2026 01:30
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Lean already. Ship.

Generated by Ponytail Reviewer for #51895

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #51895 does not have the 'implementation' label and has only 59 new lines of code in business logic directories (threshold: 100).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • api.individual.githubcopilot.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.individual.githubcopilot.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

🧪 Test quality analysis by Test Quality Sentinel

Copilot AI left a comment

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.

Pull request overview

Enables add-wizard to tolerate and stage repository initialization files while still rejecting unrelated changes.

Changes:

  • Adds clean-tree checks with explicit path exclusions.
  • Passes initialization files through PR creation and stages them.
  • Adds regression coverage for ignored initialization files.
Show a summary per file
File Description
pkg/cli/git.go Adds path-aware clean-tree validation.
pkg/cli/git_test.go Tests ignored generated and modified files.
pkg/cli/add_workflow_pr.go Tracks initialization files for staging.
pkg/cli/add_interactive_git.go Passes initialization paths into add options.
pkg/cli/add_command.go Excludes initialization paths from PR cleanliness checks.

Review details

Tip

Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread pkg/cli/add_workflow_pr.go Outdated
// Create file tracker for rollback capability
tracker := NewFileTracker()
for _, initializedFile := range opts.initializedFiles {
tracker.TrackModified(initializedFile)
Comment thread pkg/cli/add_workflow_pr.go Outdated
Comment on lines +79 to +80
for _, initializedFile := range opts.initializedFiles {
tracker.TrackModified(initializedFile)
@github-actions

Copy link
Copy Markdown
Contributor

Review

One correctness issue found in the rollback logic.

Bug: initFiles tracked as modified instead of created

In add_workflow_pr.go (lines 79-81 in the diff), the initializedFiles (produced by ensureAddRepositoryInitializedWithDetails) are newly-created files. They are registered with tracker.TrackModified(initializedFile), but they should use tracker.TrackCreated(initializedFile).

TrackModified reads and stores the file's original content at registration time — for brand-new files this read fails silently, so the map entry is empty. On rollback, RollbackModifiedFiles finds no stored content and logs a warning instead of cleaning up, leaving stale init-files on disk. TrackCreated would correctly delete them via RollbackCreatedFiles on failure.

Otherwise the path normalisation in checkCleanWorkingDirectoryIgnoring, the pathspec exclusion logic, and the test coverage all look solid.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 37.4 AIC · ⌖ 6.41 AIC · ⊞ 5.4K ·

@github-actions github-actions Bot left a comment

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.

One blocking correctness issue: in add_workflow_pr.go, initializedFiles are newly-created files but are passed to tracker.TrackModified() instead of tracker.TrackCreated(). On rollback failure, RollbackModifiedFiles will find no stored original content and silently skip cleanup, leaving stale init-files on disk. Change TrackModified to TrackCreated for these files.

@copilot please address this.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 37.4 AIC · ⌖ 6.41 AIC · ⊞ 5.4K

@github-actions github-actions Bot left a comment

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.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — requesting changes on two correctness issues and a test gap.

📋 Key Themes & Highlights

Key Themes

  • Rollback semantics: Init files are newly created by InitRepository but tracked with TrackModified, which restores content instead of deleting on rollback. Should use TrackCreated.
  • Flag inconsistency: --untracked-files=all is only added when paths are excluded, creating a silent behavioural difference in the baseline code path.
  • Test coverage gap: The staged-but-not-committed case for an excluded init file is not tested.

Positive Highlights

  • ✅ Clean layering: the ignore list is plumbed through AddOptions without touching unrelated paths
  • ✅ Path normalization (forward-slash, top-pathspec) is thoughtful and cross-platform
  • ✅ Regression tests cover untracked and modified-tracked cases, and verify unrelated files still block

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 43.4 AIC · ⌖ 6.75 AIC · ⊞ 7.1K
Comment /matt to run again

Comment thread pkg/cli/add_workflow_pr.go Outdated
// Create file tracker for rollback capability
tracker := NewFileTracker()
for _, initializedFile := range opts.initializedFiles {
tracker.TrackModified(initializedFile)

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.

[/diagnosing-bugs] TrackModified is used here for init files that were just created by InitRepository, not pre-existing files. If rollback is triggered, TrackModified restores the stored "original" content (captured after creation) rather than deleting the file — leaving orphaned init files in the repo.

💡 Suggested fix

Init files are brand-new, so register them with TrackCreated, which deletes them on rollback — matching how workflow and lock files are handled:

for _, initializedFile := range opts.initializedFiles {
    tracker.TrackCreated(initializedFile)
}

@copilot please address this.

Comment thread pkg/cli/git.go

// checkCleanWorkingDirectoryIgnoring checks for uncommitted changes except for
// the provided repository-relative paths.
func checkCleanWorkingDirectoryIgnoring(verbose bool, ignoredPaths []string) error {

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.

[/diagnosing-bugs] --untracked-files=all is added to git status only when ignoredPaths is non-empty. The baseline checkCleanWorkingDirectory path now uses different flags than before (it omits --untracked-files=all), which may silently miss untracked files in subdirectories in some Git configurations.

💡 Suggested fix

Always pass --untracked-files=all regardless of whether paths are excluded:

args := []string{"status", "--porcelain", "--untracked-files=all"}
if len(ignoredPaths) > 0 {
    args = append(args, "--", ":(top)**")
    for _, p := range ignoredPaths {
        ...
    }
}

@copilot please address this.

Comment thread pkg/cli/git_test.go
require.NoError(t, exec.Command("git", "add", generatedFile).Run())
require.NoError(t, exec.Command("git", "commit", "-m", "initial commit").Run())
require.NoError(t, os.WriteFile(generatedFile, []byte("updated"), 0644))

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.

[/tdd] The test creates a SKILL.md file as the representative init file, but the test covers only the untracked and modified-tracked cases — not a staged-but-not-committed init file. A staged init file that is excluded should also pass the check.

💡 Suggested additional case
// Staged init file should still be ignored
require.NoError(t, exec.Command("git", "add", generatedFile).Run())
require.NoError(t, checkCleanWorkingDirectoryIgnoring(false, []string{generatedFile}))

@copilot please address this.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Test Quality Score: 100/100 — Excellent

Analyzed 1 test: 1 design, 0 implementation, 0 violations.

📊 Metrics (1 test)
Metric Value
Analyzed 1 (Go: 1, JS: 0)
✅ Design 1 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 3 assertions
Duplicate clusters 0
Inflation 1.38:1 (acceptable)
🚨 Violations 0
Test File Classification Issues
TestCheckCleanWorkingDirectoryIgnoring pkg/cli/git_test.go:82–116 behavioral_contract, high_value, design_test None

📋 Test Details

TestCheckCleanWorkingDirectoryIgnoring (pkg/cli/git_test.go:82–116)

This test verifies the behavioral contract of the new checkCleanWorkingDirectoryIgnoring() function introduced in this PR. It validates that:

  1. Ignored paths are excluded — Generated files in the ignore list are not flagged as dirty even if untracked
  2. Non-ignored paths are still detected — Untracked user files trigger the dirty check when not ignored
  3. Tracked file modifications are caught — Both untracked AND modified tracked files are detected as dirty (added in commit 2)

Classification: ✅ Design test verifying public API contract, not implementation details.

Error coverage: Strong — 3 explicit error assertions (require.ErrorContains) validate that dirty conditions are properly detected.

Test inflation: 1.38:1 ratio (36 test lines / 26 production lines) — acceptable and well below the 2:1 threshold.

Quality signals:

  • ✅ Proper build tag ((go/redacted):build !integration)
  • ✅ No forbidden mock libraries (uses only exec.Command)
  • ✅ Good edge-case coverage (tracked file modification scenario)
  • ✅ Descriptive error messages in assertions

Verdict

PASS. Test Quality Score: 100/100. 0% implementation tests (threshold: 30%). No violations detected.

🧪 Test quality analysis by Test Quality Sentinel · haiku45 · 22.7 AIC · ⌖ 3.98 AIC · ⊞ 7.6K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

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.

✅ Test Quality Sentinel: 100/100. 0% implementation tests (threshold: 30%). No violations.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot quick triage: this PR has two fresh blocking github-actions reviews requesting changes. Please address the rollback tracking issue in pkg/cli/add_workflow_pr.go (TrackCreated vs TrackModified) and the --untracked-files=all behavior gap called out by Matt Pocock, then run the pr-finisher skill. Run: https://github.com/github/gh-aw/actions/runs/31450173394

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 24.1 AIC · ⌖ 5.21 AIC · ⊞ 6.1K ·
Comment /souschef to run again

Copilot AI and others added 2 commits August 11, 2026 02:00
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot quick triage: this PR has two fresh blocking github-actions reviews requesting changes. Please address the rollback tracking issue in pkg/cli/add_workflow_pr.go (TrackCreated vs `TrackMod...

Addressed both review issues:

  1. TrackCreated vs TrackModified (pkg/cli/add_workflow_pr.go): Changed to TrackCreated — these are newly-created files so TrackModified was wrong (it tried to read original content that doesn't exist).

  2. Files not actually written (pkg/cli/add_init.go): Moved the file list population to after InitRepository runs, filtering to only markers that isBootstrapInitMarkerSatisfied confirms were written. This correctly handles --no-gitattributes where .gitattributes is intentionally skipped. Errors from filepath.Abs are now propagated rather than silently dropped.

  3. Absolute path resolution (pkg/cli/git.go): checkCleanWorkingDirectoryIgnoring now converts absolute paths to git-root-relative paths via filepath.Rel before building :(top,literal,exclude) pathspecs, fixing the broken exclusion when the wizard is invoked from a nested directory. filepath.Rel failures are returned as errors.

Commit: dbbb8ac → latest

Copilot AI requested a review from gh-aw-bot August 11, 2026 02:02
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot add git integration test

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add git integration test

Added two tests:

  • TestCheckCleanWorkingDirectoryIgnoringAbsolutePaths (pkg/cli/git_test.go): sets the process CWD to a subdirectory of the repo, then passes the init file as an absolute path to checkCleanWorkingDirectoryIgnoring. Verifies the file is excluded from the dirty-tree check while an unrelated untracked file is still detected.

  • TestEnsureAddRepositoryInitializedWithDetails_AbsolutePaths (pkg/cli/add_command_test.go): mocks addInitRepository to write only one of two missing markers (simulating --no-gitattributes). Verifies the returned slice contains exactly one entry, that it is an absolute path, and that the skipped marker is absent.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot quick triage: there are still unresolved review threads, but you already replied with follow-up fixes on head 43adcd6f31235826c02bd2e713f4ed672e4e84f7. Please resolve the remaining maintainer-facing feedback, explicitly address the still-open absolute-path / init-file / dirty-tree test threads, run the pr-finisher skill, and hand back a concise summary.

Open review context (newest first):

Branch refresh was requested. Run: https://github.com/github/gh-aw/actions/runs/31452822169

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 22.1 AIC · ⌖ 6.79 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot quick triage: there are still unresolved review threads, but you already replied with follow-up fixes on head 43adcd6f31235826c02bd2e713f4ed672e4e84f7. Please resolve the remaining maintain...

Addressed all open threads:

  1. Staged init-file test gap — added a test case that stages the generated file without committing and verifies checkCleanWorkingDirectoryIgnoring still passes while checkCleanWorkingDirectory fails.
  2. --untracked-files=all behavior gap — already fixed in a previous commit; the flag is unconditionally present on the args slice (line 569), outside the if len(ignoredPaths) > 0 block.
  3. TrackCreated vs TrackModified — already fixed; uses TrackCreated for init files.
  4. Init file list filtering — already fixed; only files confirmed written by isBootstrapInitMarkerSatisfied are returned.
  5. Absolute path resolution — already fixed; checkCleanWorkingDirectoryIgnoring converts absolute paths to git-root-relative before building pathspecs.

Latest commit: Add staged init-file test case for checkCleanWorkingDirectoryIgnoring

@pelikhan
pelikhan merged commit 7f51e41 into main Aug 11, 2026
26 checks passed
@pelikhan
pelikhan deleted the copilot/fix-gh-add-wizard-empty-repo branch August 11, 2026 03:23
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.86.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh add-wizard fails to add workflow in empty git repository

4 participants