fix: warn when Git target exists but is not a valid git repository (#86)#194
Open
HeyItsGilbert wants to merge 1 commit into
Open
fix: warn when Git target exists but is not a valid git repository (#86)#194HeyItsGilbert wants to merge 1 commit into
HeyItsGilbert wants to merge 1 commit into
Conversation
Previously, if a directory already existed at the clone target but was not a git repository, `git rev-parse` returned nothing and the handler silently fell into the "we don't support moving versions" branch with null branch/commit values, producing a confusing verbose message and a no-op install. Now emits `Write-Warning` in that case so the user knows why the dependency was skipped. Also confirmed that the nesting bug from #86 (Repo/Repo on repeated runs) does not reproduce on current code; adds two Pester tests to lock in idempotency and the non-git-directory warning path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the Git dependency handler behavior when the clone target directory already exists but is not a valid git repository, replacing a confusing/silent no-op path with an explicit warning, and adds Pester coverage for the new/related behaviors.
Changes:
- Added a
Write-Warningand install short-circuit when$RepoPathexists butgit rev-parseyields no branch. - Added Pester tests for idempotency (no re-clone) and the “existing non-git directory” scenario.
- Updated
CHANGELOG.mdto document the fix and new tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Tests/Git.Type.Tests.ps1 | Adds new Pester coverage for idempotency and non-git-directory handling. |
| PSDepend/PSDependScripts/Git.ps1 | Emits a warning and skips install when an existing target directory isn’t a valid git repo. |
| CHANGELOG.md | Documents the Git handler behavior change and new tests under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+135
to
+139
| if (-not $Branch) { | ||
| Write-Warning "[$RepoPath] exists but does not appear to be a valid git repository. Skipping [$DependencyName]." | ||
| $GottaInstall = $False | ||
| } | ||
| elseif ($Version -eq $Branch -or $Version -eq $Commit) { |
Comment on lines
+103
to
+111
| InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } { | ||
| # rev-parse returns nothing (non-git directory) | ||
| Mock Invoke-ExternalCommand { } | ||
| { & $ScriptPath -Dependency $Dep } | Should -Not -Throw | ||
| } | ||
| Should -Invoke -CommandName Invoke-ExternalCommand -ModuleName PSDepend -Times 0 -ParameterFilter { | ||
| $Arguments -contains 'clone' | ||
| } | ||
| } |
Comment on lines
+92
to
+95
| Should -Invoke -CommandName Invoke-ExternalCommand -ModuleName PSDepend -Times 0 -ParameterFilter { | ||
| $Arguments -contains 'clone' | ||
| } | ||
| } |
Test Results 3 files 66 suites 1m 20s ⏱️ Results for commit 7b88c04. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Repo/Repobug was confirmed non-reproducible on current code)Write-Warningwhen$RepoPathexists butgit rev-parsereturns nothing, so users get a clear signal instead of a silent no-op with a misleading verbose messageTest plan
.\build.ps1 StageFilesthenInvoke-Pester Tests/Git.Type.Tests.ps1— all 5 tests pass🤖 Generated with Claude Code