Repository navigation
Return an empty Log() on a repository with no commits yet [patch] - #236
Merged
Merged
Conversation
On an unborn HEAD, git log exits 128 ("does not have any commits yet", or
"unknown revision 'HEAD'" once ExcludingRemoteTrackingRefs names HEAD), while
IncludingAllRefs on the same repository exits 0 with no output. So Log()
returned an empty list or threw depending only on the options chosen.
When log fails and the caller named no revision of their own, Log() now probes
`rev-parse --verify -q HEAD`. Exit 1 (HEAD does not resolve) means unborn, and
the result is an empty list. Any other failure, and any explicit ForRevision,
still throws as before. The probe runs only after a failure, so the common
case still costs one invocation.
Fixes #233
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018CRjG9vX7hK9TShFL3iJh3
Resolve GitRoundTripTests.cs: main added RevParse tag-peeling tests at the same spot as this branch's unborn-HEAD Log tests; keep both. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MBvWhCTdazHGpnqRd3FD7s
|
This was referenced Oct 19, 2026
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.



Fixes #233
Problem
On a freshly initialised repository (unborn HEAD),
git logexits 128. WhetherLog()threw or returned an empty list depended only on which options the caller chose:Log()does not have any commits yet)Log().ForPath(p)Log().ExcludingRemoteTrackingRefs()unknown revision 'HEAD')Log().IncludingAllRefs()Log().ForRevision("does-not-exist")Change
GitLogBuildernow overridesExecuteAsyncandTryExecuteAsync. Whengit logfails and the caller named no revision (and did not ask forIncludingAllRefs, which already succeeds), it probesgit rev-parse --verify -q HEAD:GitCommandExceptionor returns the original failed result.The probe runs only after
loghas already failed, so a normalLog()still costs one git invocation. I used a probe instead of matching error text, because the two failures carry different messages. This follows the triage note.Tests
LogReturnsAnEmptyListBeforeTheFirstCommitAsync: on anInit()-only repository,Log(),Log().ForPath(...),Log().ExcludingRemoteTrackingRefs()andLog().IncludingAllRefs()all return an empty list, andTryExecuteAsyncsucceeds.LogStillRefusesAnUnknownRevisionBeforeTheFirstCommitAsync:ForRevision("does-not-exist")still throwsGitCommandExceptionand still fails throughTryExecuteAsync.With the builder change reverted, the first test fails. With it in place, the full suite passes: 885 tests, 0 failed (
dotnet test, git 2.43).Generated by Claude Code