Repository navigation
[DIT-13659]: CLI: refuse a scan from a dirty tree or a non-default branch - #159
Merged
laurakoye merged 5 commits intoSep 17, 2026
Conversation
jholiga
reviewed
Sep 15, 2026
jholiga
approved these changes
Sep 16, 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.
Overview
ditto scannow refuses to run unless you're on a clean checkout of the default branch. It exits 1 with one of:Uncommitted changes are present. Commit or stash them, then scan again.On branch "my-feature", but this repo's default branch is "main". Check out "main" and scan again.HEAD is detached at abc1234. Check out "main" and scan again.The check runs before we ask for an API key, so a refused scan costs nothing — no login prompt, no API call, nothing against the plan limit.
Working out the default branch. We read
origin/HEAD, falling back to a localmainormaster. That ref is recorded when you clone and never updates on its own, so a default branch renamed since would refuse a checkout that's actually correct — and name a branch that no longer exists. To avoid that, a mismatch is confirmed against the remote withgit ls-remote --symref origin HEADbefore we refuse. Successful scans never make that call; the round trip is only paid on the path that's about to stop you. If the remote is unreachable we fall back to the local ref and say so in the message.Still scans as before:
origin/HEADand no localmainormaster, usually one that was never cloned or whose default is named something likedevelop. Blocking there would refuse a checkout that's probably fine, with an error that can't say which branch to switch to.Context
A scan records the commit and branch it read, and code links point at them. A scan from a dirty tree or a feature branch points at lines the default branch never had, so the next scan reports those links as changed or removed, with no obvious cause.
Closes DIT-13659.
Screenshots
Test Plan
Testing successfully completed locally via:
npx jest— full suite greengit checkout --detach HEAD, then scan → exits 1, names the sha