Skip to content

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

Merged
HeyItsGilbert merged 3 commits into
mainfrom
worktree-tidy-humming-horizon
Jun 14, 2026
Merged

fix: warn when Git target exists but is not a valid git repository (#86)#194
HeyItsGilbert merged 3 commits 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

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 thread PSDepend/PSDependScripts/Git.ps1
Comment thread Tests/Git.Type.Tests.ps1
Comment thread Tests/Git.Type.Tests.ps1
@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown

Test Results

    3 files     66 suites   1m 27s ⏱️
  979 tests   925 ✅ 54 💤 0 ❌
1 311 runs  1 247 ✅ 64 💤 0 ❌

Results for commit 4c9df6a.

♻️ This comment has been updated with latest results.

@HeyItsGilbert HeyItsGilbert force-pushed the worktree-tidy-humming-horizon branch from 7b88c04 to 8bfb4ae Compare June 13, 2026 20:18
HeyItsGilbert added a commit that referenced this pull request Jun 14, 2026
- Return $false (not $null) from Test action when target exists but is
  not a valid git repository, preserving the Boolean contract
- Idempotency test now also asserts git checkout is not invoked
- Warning test mocks Write-Warning and asserts it is called with the
  expected message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
HeyItsGilbert added a commit that referenced this pull request Jun 14, 2026
- Return $false (not $null) from Test action when target exists but is
  not a valid git repository, preserving the Boolean contract
- Idempotency test now also asserts git checkout is not invoked
- Warning test mocks Write-Warning and asserts it is called with the
  expected message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@HeyItsGilbert HeyItsGilbert force-pushed the worktree-tidy-humming-horizon branch from 8386fed to e492cc0 Compare June 14, 2026 00:34
HeyItsGilbert and others added 3 commits June 13, 2026 17:39
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>
- Return $false (not $null) from Test action when target exists but is
  not a valid git repository, preserving the Boolean contract
- Idempotency test now also asserts git checkout is not invoked
- Warning test mocks Write-Warning and asserts it is called with the
  expected message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Keep a Changelog does not define a Tests category; test additions are
implementation details, not user-facing changes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@HeyItsGilbert HeyItsGilbert force-pushed the worktree-tidy-humming-horizon branch from e492cc0 to 4c9df6a Compare June 14, 2026 00:40
@HeyItsGilbert HeyItsGilbert merged commit a63780a into main Jun 14, 2026
7 checks passed
HeyItsGilbert added a commit that referenced this pull request Jun 14, 2026
- Return $false (not $null) from Test action when target exists but is
  not a valid git repository, preserving the Boolean contract
- Idempotency test now also asserts git checkout is not invoked
- Warning test mocks Write-Warning and asserts it is called with the
  expected message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@HeyItsGilbert HeyItsGilbert deleted the worktree-tidy-humming-horizon branch June 14, 2026 00:46
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