Skip to content

fix: refuse a shallow clone instead of reading it as a first release - #244

Merged
goldbarth merged 1 commit into
mainfrom
fix/shallow-clone
Sep 23, 2026
Merged

goldbarth merged 1 commit into
mainfrom
fix/shallow-clone

Conversation

@goldbarth

Copy link
Copy Markdown
Owner

Closes #243

  • Checked where the range start is resolved: GitCliCommitReader asks git rev-parse --is-shallow-repository right after the tag resolves. The reader runs first in the pipeline, so the refusal comes before any GitHub request or model call.
  • No start named in a shallow clone is refused, whatever the previous-tag lookup would find. The clone's history ends at the fetch depth, which reads exactly like a first tag's history ending at the root, and a previous tag found inside the depth may still not be the nearest one. The message says the clone is shallow and names the three fixes: git fetch --unshallow --tags, fetch-depth: 0, GIT_DEPTH: 0.
  • --whole-history is refused by the same check: it reaches the reader with no start, and the history it would render is not the whole history. WholeHistoryException is never reached in a shallow clone, so the "first tag" advice that sent users to --whole-history no longer appears there.
  • --since <ref> still runs in a shallow clone, so a deliberately limited fetch is not blocked. It is refused with the fix when:
    • the ref is not in the fetched history ("is not in the fetched history of this shallow clone", instead of "does not resolve");
    • the fetched history does not connect it to the tag (not an ancestor in the fetched history; the connecting commits may be missing);
    • a commit from git's shallow file lies inside since..tag: the start is connected along main, but a merged branch older than the depth is cut off, so commits of the release are missing. This is conservative: a boundary commit whose real parent is the start itself is refused too, since git hides that parent and the unshallow fix covers it.
  • The fix text lives in the git adapter, next to the existing git fetch --tags hint, not in the CLI: it is about how the clone was made, not about Chartula's flags.
  • Docs: README gains an "In CI" section with fetch-depth: 0 and GIT_DEPTH: 0 (there was no CI snippet for checkout before); docs/cli.md gets "A shallow clone" under "Where a release starts"; the IReleaseCommitReader exception doc names the case.

Reproduced before the fix, the issue's steps on a real shallow clone of this repository, binary built from main:

$ git clone --depth 1 https://github.com/goldbarth/chartula.git && cd chartula
$ git fetch --depth 1 origin tag v0.1.0-preview.1
$ git rev-parse --is-shallow-repository
true
$ chartula preview --tag v0.1.0-preview.1 --repo goldbarth/chartula
Error: v0.1.0-preview.1 is the first tag, so its range is the whole history (1 commits).
  Rendered as it is, that reads as a development log rather than a release.
  --since <ref>     start the release after a tag or commit (e.g. the last state you shipped)
  --whole-history   render all of it, e.g. for a project whose history is the release
[exit code: 1]

After git fetch --unshallow --tags the same tag has 100 commits. (v0.1.0-preview.1 is in fact this repository's only tag, so the "predecessor beyond the depth" case is reproduced in the tests below, on local shallow clones.)

Verified after the fix, same clone, binary from this branch:

$ chartula preview --tag v0.1.0-preview.1 --repo goldbarth/chartula      # and with --whole-history: identical
Error: The checkout is a shallow clone: its history ends at the fetch depth, not where 'v0.1.0-preview.1' starts, so neither the previous tag nor the whole history can be read from it.
  Fetch the full history and tags: git fetch --unshallow --tags
  In GitHub Actions, check out with fetch-depth: 0; in GitLab CI, set GIT_DEPTH: 0.
[exit code: 1]

$ chartula preview --tag v0.1.0-preview.1 --repo goldbarth/chartula --since v0.0.0-nope
Error: The release start 'v0.0.0-nope' is not in the fetched history of this shallow clone.
  Fetch the full history and tags: git fetch --unshallow --tags
  In GitHub Actions, check out with fetch-depth: 0; in GitLab CI, set GIT_DEPTH: 0.
[exit code: 1]

Tests: against real shallow clones (git clone --depth N over file://, via TempGitRepository.ShallowClone): GitCliCommitReaderTests (refused without a start; --since fetched with the tag reads the range; start not fetched; start not connected; range cut off inside by a merged branch) and ShallowCloneTests (the built CLI, with and without --whole-history: exit 1, the fixes named, no "first tag", no GitHub request). The six refusal tests fail on main. Full suite 813 passing, build without warnings, dotnet format clean.

@goldbarth
goldbarth merged commit f9146c7 into main Sep 23, 2026
4 checks passed
@goldbarth
goldbarth deleted the fix/shallow-clone branch September 23, 2026 15:39
goldbarth added a commit that referenced this pull request Oct 1, 2026
…320)

Follows #319 (ADR 0004); this branch builds on it for the index row and
is rebased onto `main` once #319 is merged.

- **Why:** seven changes since September made Chartula stop where it
used to choose silently, each with its own reasoning in its pull
request, but the rule they share was written down nowhere. A contributor
adding an option or a setting could not tell whether to refuse an
ambiguous value or take the likelier reading, nor when refusing goes too
far.
- **Context** lists the seven cases in one table, each with what the
silent choice did and the change that ended it: a first tag (#198 for
#138, #282), a key sent to the other provider's host (#235), an unknown
or misindented key (#238), a shallow clone read as a first release
(#244), review mode approving unseen text (#247), two configuration
files (#287 for #278), and options a command does not take (#301).
Decided is #198, the first of them.
- **Decision:** stop and say so instead of choosing; before anything is
spent; with a message that names the cause and the fix, shown with two
real messages; ask at a terminal where the answer is the user's, and
stop naming the option without one; refuse only what Chartula can tell
for certain (an empty list, an unknown host and an unknown model id are
taken as written); refuse a setting that would have no effect. The rule
is about what the user meant, not about what the release says, which is
what flags are for.
- **Consequences** name the cost: a run that could have produced
something stops, and a CI job fails until the input says what it means.
The ADR weighs that rerun against what a silent choice cost in the seven
cases. For a new case, four questions in order, so a contributor can
apply the rule rather than match it against the examples.
- The index in `adr/README.md` lists 0005.

**Verified:**
- Each case was checked against its pull request's description and the
issue it closes (#237, #243, #233, #278, #300, #138); the dates are the
merge dates.
- Both messages are the ones `docs/cli.md` and `docs/configuration.md`
show from the built binary.
- The counter-cases were checked in the code: `ProviderHost` accepts
every host but two, `ClaudeThinkingSupport` passes an unknown model id,
#289 reads an empty list as written, and #244 still runs `--since` in a
shallow clone when the range holds.
- Every relative link and anchor in all Markdown files of the repository
resolves (script, with a negative test).

Tests: none, documentation only.
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.

A shallow clone is mistaken for a first release

1 participant