-
Notifications
You must be signed in to change notification settings - Fork 495
Allow add-wizard to initialize empty repositories #51895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
247cb0a
Initial plan
Copilot 9d46170
Fix add wizard in uninitialized repositories
Copilot 474f1a9
Cover tracked initialization files
Copilot dbbb8ac
Merge branch 'main' into copilot/fix-gh-add-wizard-empty-repo
github-actions[bot] 2851505
Fix initialized file tracking: use absolute paths and TrackCreated
Copilot 5490c0e
Propagate errors from filepath.Abs and filepath.Rel
Copilot 43adcd6
Add git integration tests for absolute path handling in init tracking
Copilot 3279750
Merge branch 'main' into copilot/fix-gh-add-wizard-empty-repo
github-actions[bot] 9ed2d80
Add staged init-file test case for checkCleanWorkingDirectoryIgnoring
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,88 @@ func TestGetCurrentBranchNotInRepo(t *testing.T) { | |
| assert.Error(t, err, "getCurrentBranch should return an error when not in a git repository") | ||
| } | ||
|
|
||
| func TestCheckCleanWorkingDirectoryIgnoring(t *testing.T) { | ||
| tmpDir := testutil.TempDir(t, "test-*") | ||
|
|
||
| originalDir, err := os.Getwd() | ||
| require.NoError(t, err) | ||
| defer func() { | ||
| require.NoError(t, os.Chdir(originalDir)) | ||
| }() | ||
|
|
||
| require.NoError(t, os.Chdir(tmpDir)) | ||
| require.NoError(t, exec.Command("git", "init").Run()) | ||
| require.NoError(t, exec.Command("git", "config", "user.name", "Test User").Run()) | ||
| require.NoError(t, exec.Command("git", "config", "user.email", "test@example.com").Run()) | ||
|
|
||
| generatedFile := filepath.Join(".github", "skills", "agentic-workflows", "SKILL.md") | ||
| require.NoError(t, os.MkdirAll(filepath.Dir(generatedFile), 0755)) | ||
| require.NoError(t, os.WriteFile(generatedFile, []byte("generated"), 0644)) | ||
|
|
||
| require.NoError(t, checkCleanWorkingDirectoryIgnoring(false, []string{generatedFile})) | ||
| require.ErrorContains(t, checkCleanWorkingDirectory(false), "working directory has uncommitted changes") | ||
|
|
||
| // Staged (but not committed) init file should also be excluded. | ||
| require.NoError(t, exec.Command("git", "add", generatedFile).Run()) | ||
| require.NoError(t, checkCleanWorkingDirectoryIgnoring(false, []string{generatedFile})) | ||
| require.ErrorContains(t, checkCleanWorkingDirectory(false), "working directory has uncommitted changes") | ||
|
|
||
| require.NoError(t, exec.Command("git", "commit", "-m", "initial commit").Run()) | ||
| require.NoError(t, os.WriteFile(generatedFile, []byte("updated"), 0644)) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] The test creates a 💡 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. |
||
| require.NoError(t, checkCleanWorkingDirectoryIgnoring(false, []string{generatedFile})) | ||
| require.ErrorContains(t, checkCleanWorkingDirectory(false), "working directory has uncommitted changes") | ||
|
|
||
| require.NoError(t, os.WriteFile("README.md", []byte("user file"), 0644)) | ||
| require.ErrorContains( | ||
| t, | ||
| checkCleanWorkingDirectoryIgnoring(false, []string{generatedFile}), | ||
| "working directory has uncommitted changes", | ||
| ) | ||
| } | ||
|
|
||
| // TestCheckCleanWorkingDirectoryIgnoringAbsolutePaths verifies that absolute | ||
| // paths are accepted when the current directory is a subdirectory of the repo. | ||
| // This is the case when the wizard is invoked from a nested directory and | ||
| // ensureAddRepositoryInitializedWithDetails returns absolute paths. | ||
| func TestCheckCleanWorkingDirectoryIgnoringAbsolutePaths(t *testing.T) { | ||
| repoDir := testutil.TempDir(t, "test-*") | ||
|
|
||
| originalDir, err := os.Getwd() | ||
| require.NoError(t, err) | ||
| defer func() { | ||
| require.NoError(t, os.Chdir(originalDir)) | ||
| }() | ||
|
|
||
| require.NoError(t, os.Chdir(repoDir)) | ||
| require.NoError(t, exec.Command("git", "init").Run()) | ||
| require.NoError(t, exec.Command("git", "config", "user.name", "Test User").Run()) | ||
| require.NoError(t, exec.Command("git", "config", "user.email", "test@example.com").Run()) | ||
|
|
||
| // Create the init file at the repo root. | ||
| generatedFile := filepath.Join(".github", "skills", "agentic-workflows", "SKILL.md") | ||
| require.NoError(t, os.MkdirAll(filepath.Dir(generatedFile), 0755)) | ||
| require.NoError(t, os.WriteFile(generatedFile, []byte("generated"), 0644)) | ||
| absGenerated := filepath.Join(repoDir, generatedFile) | ||
|
|
||
| // Create a subdirectory and cd into it to simulate a nested invocation. | ||
| subDir := filepath.Join(repoDir, "subdir") | ||
| require.NoError(t, os.MkdirAll(subDir, 0755)) | ||
| require.NoError(t, os.Chdir(subDir)) | ||
|
|
||
| // Passing the absolute path from a nested CWD should still exclude the file. | ||
| require.NoError(t, checkCleanWorkingDirectoryIgnoring(false, []string{absGenerated})) | ||
| require.ErrorContains(t, checkCleanWorkingDirectory(false), "working directory has uncommitted changes") | ||
|
|
||
| // An unrelated untracked file must still be detected even when the init file is excluded. | ||
| require.NoError(t, os.WriteFile(filepath.Join(repoDir, "README.md"), []byte("user file"), 0644)) | ||
| require.ErrorContains( | ||
| t, | ||
| checkCleanWorkingDirectoryIgnoring(false, []string{absGenerated}), | ||
| "working directory has uncommitted changes", | ||
| ) | ||
| } | ||
|
|
||
| func TestCreateAndSwitchBranch(t *testing.T) { | ||
| tmpDir := testutil.TempDir(t, "test-*") | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/diagnosing-bugs]
--untracked-files=allis added togit statusonly whenignoredPathsis non-empty. The baselinecheckCleanWorkingDirectorypath 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=allregardless of whether paths are excluded:@copilot please address this.