Skip to content

fix: warn when Git target exists but is not a valid git repository (#86)#194

Open
HeyItsGilbert wants to merge 1 commit into
mainfrom
worktree-tidy-humming-horizon
Open

fix: warn when Git target exists but is not a valid git repository (#86)#194
HeyItsGilbert wants to merge 1 commit into
mainfrom
worktree-tidy-humming-horizon

Conversation

@HeyItsGilbert

Copy link
Copy Markdown
Member

Summary

  • Closes Running PSDepend multiple times results in subfolders created instead  #86 (the nested Repo/Repo bug was confirmed non-reproducible on current code)
  • Adds an explicit Write-Warning when $RepoPath exists but git rev-parse returns nothing, so users get a clear signal instead of a silent no-op with a misleading verbose message
  • Two new Pester tests: idempotency (second run does not re-clone) and non-git-directory (warning emitted, no clone attempted)

Test plan

  • .\build.ps1 StageFiles then Invoke-Pester Tests/Git.Type.Tests.ps1 — all 5 tests pass
  • Manual repro attempt with a local bare repo: 3 consecutive installs produce no nesting

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 13, 2026 04:11

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

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-Warning and install short-circuit when $RepoPath exists but git rev-parse yields no branch.
  • Added Pester tests for idempotency (no re-clone) and the “existing non-git directory” scenario.
  • Updated CHANGELOG.md to 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 thread Tests/Git.Type.Tests.ps1
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 thread Tests/Git.Type.Tests.ps1
Comment on lines +92 to +95
Should -Invoke -CommandName Invoke-ExternalCommand -ModuleName PSDepend -Times 0 -ParameterFilter {
$Arguments -contains 'clone'
}
}
@github-actions

Copy link
Copy Markdown

Test Results

    3 files     66 suites   1m 20s ⏱️
  967 tests   909 ✅ 58 💤 0 ❌
1 296 runs  1 228 ✅ 68 💤 0 ❌

Results for commit 7b88c04.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running PSDepend multiple times results in subfolders created instead

2 participants