Skip to content

Refuse an Add with nothing to stage, or with both All and UpdateTrackedOnly [patch] - #213

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/172-add-guards
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/172-add-guards

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #172

What changed

GitAddBuilder.AppendVerbArguments now refuses two configurations before any process is spawned. It uses the same guard pattern as GitFetchBuilder (AllRemotes + FromRemote) and GitCheckoutBuilder (#91).

  • Nothing to stage. This means no ForPath, All or UpdateTrackedOnly was called. A bare git add prints Nothing specified, nothing added. and exits 0, so the builder used to report success having staged nothing. It now throws InvalidOperationException.
  • All() + UpdateTrackedOnly(). git rejects this with fatal: options '-A' and '-u' cannot be used together (exit 128), which doesn't name either of the calls that caused it. It now throws InvalidOperationException with a message that does.

TryExecuteAsync builds the arguments before it runs anything, so both entry points throw the same way. The interface remarks on ForPath, All and UpdateTrackedOnly describe the requirement.

Tests

  • New: RejectsAnAddWithNothingToStage, RejectsAskingForBothAllAndUpdateTrackedOnly, and RefusesAnAddWithNothingToStageBeforeRunningGitAsync. The last one goes through TryExecuteAsync and asserts that the runner was never called.
  • BuildsTheDefaultAddVector used to pin the bare vector, which is now refused. It is now BuildsTheAllAddVector, which pins add --all. The ForPath, All and UpdateTrackedOnly vectors used on their own are unchanged.
  • ExecuteThrowsWhenAPathspecMatchesNothingAsync simulates a pathspec failure but never set a path. It now calls ForPath("no/such/file.txt"), the path it describes.
  • GitRepositoryMutatingVerbTests.EveryMutatingVerbIsScopedToTheRepositoryPath now calls Add().All(), as the issue asked.
  • To show the new tests depend on the guards, I made both conditions unreachable. All three new tests failed, then passed again once the change was restored.
  • Full suite on Linux with git 2.43 and KTSU_GIT_INTEGRATION_TESTS_REQUIRED=1: 803 of 803 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BkmjSwCY4KW87X2ccQhj7T


Generated by Claude Code

…edOnly [patch]

A bare Add() ran "git add" with no pathspec, which prints "Nothing
specified, nothing added." and exits 0, so the builder reported success
having staged nothing. All() with UpdateTrackedOnly() reached git as
"options '-A' and '-u' cannot be used together" (exit 128). Both now
throw InvalidOperationException before a process is spawned, matching
the Fetch and Checkout guards.

The pathspec-failure test now sets the path it simulates, and the
mutating-verb scoping test stages with All().

Fixes #172

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BkmjSwCY4KW87X2ccQhj7T
@sonarqubecloud

Copy link
Copy Markdown

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.

Add() with no ForPath/All/UpdateTrackedOnly reports success having staged nothing, and All().UpdateTrackedOnly() reaches git as a fatal usage error

2 participants