Skip to content

fix(cli): Start the set-commits fallback at the previous release - #2478

Merged
BYK merged 2 commits into
getsentry:mainfrom
srednoff888-art:fix/set-commits-previous-release
Nov 27, 2026
Merged

BYK merged 2 commits into
getsentry:mainfrom
srednoff888-art:fix/set-commits-previous-release

Conversation

@srednoff888-art

Copy link
Copy Markdown
Contributor

Fixes #2472.

Summary

Without a flag, when no repository integration matches, release set-commits now sends the local commits since the previous release's last commit. Before, it always sent the last --initial-depth commits, so consecutive releases shared commits.

Changes

  • The fallback asks for the previous release's commit (getPreviousReleaseCommit, already used by --auto) and reads <commit>..HEAD. All three fallback paths do this, including the cached "no repository integration" one. The range bounds itself, so --initial-depth doesn't cut it.
  • It reads the last --initial-depth commits, as before, when there is no previous release or its commit isn't an ancestor of HEAD: a shallow clone, rewritten history, another branch or another repository. In that last group it warns. sentry-cli v2 needed --ignore-missing for this and failed otherwise; I followed the issue and fall back.
  • New isInHeadHistory() in lib/git.ts (git merge-base --is-ancestor), which rejects option-like refs like getMergeBase does.
  • An empty range says there are no commits since the previous release, instead of "Check the ref" for a ref the user didn't pass.
  • --help describes the fallback. Explicit --local, --from, --path, --auto and --commit don't change.

The fallback makes one more request, previous-with-commits. A failed request counts as no previous release, as in --auto.

Tests

New tests run the command in a temporary git repository with the API mocked: the range, the cached path, an empty range, the unmatched repository, and the four cases that keep --initial-depth. Three of them fail without the change; the four --initial-depth cases pin behavior that stays.

On Windows, test/commands/release, test/lib/git* and test/lib/api/releases.test.ts give 169 passed and 6 failed. The same 6 fail on main here: they build the repository path from URL.pathname, which is /G:/…. Oxlint and Oxfmt are clean on the changed files, and tsc reports nothing in the changed source files. I didn't run the full quality gate.

🤖 Generated with Claude Code

The local fallback always read the last --initial-depth commits, so
consecutive releases shared commits. Read the commits since the previous
release's last commit, and use --initial-depth only without one in the
local history.

Fixes getsentry#2472

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

@srednoff888-art is attempting to deploy a commit to the Sentry Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 23, 2026

@sentry-junior sentry-junior Bot 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.

Thanks @srednoff888-art, and thanks @JPeer264 for the clear issue. The approach is right: it matches what sentry-cli v2 did with previous-with-commits and keeps the --initial-depth fallback that #2472 asks for. I'd take this once the points below are handled.

About the 2 failing checks. Both are Vercel (Vercel – cli, Vercel – sentry-local) asking a Sentry team member to authorize a deploy from a fork. They don't say anything about the code. The checks that matter (Test, Warden, Dependency Review, Secret Scan) haven't run: they show action_required, so a maintainer has to approve the workflows for this fork. Locally on 4ee8a542 I ran typecheck and lint for packages/cli (both pass) plus test/commands/release, test/lib/git* and test/lib/api/releases.test.ts (175 passed). The full CLI unit run fails only in test/commands/dashboard/widget/preservation.test.ts, which times out on main in the same environment too.

Changes I'd ask for:

  1. Don't send the request when the range is empty. Sentry ignores an empty commits list (if commit_list: in src/sentry/releases/endpoints/organization_release_details.py), so it does no harm. But it's a wasted PUT, and v2 skipped it and printed "No commits found. Leaving release alone." (inline comment).
  2. Reword the empty-range message. previous-with-commits returns the given release itself when that release already has commits (see the docstring in src/sentry/issues/endpoints/organization_release_previous_commits.py). Re-running set-commits for the same version is common, for example when several bundler-plugin builds share one release. In that case the commit is this release's own last commit, so "the previous release's commit" is misleading (inline comment).
  3. Optional: add a log.debug("Could not read the previous release's commit", error) to the silent catch in getPreviousReleaseCommit (packages/cli/src/lib/api/releases.ts) and drop its grandfathered no-silent-catch disable (#1531). The default fallback depends on it now, so a failed lookup that quietly drops to --initial-depth should be visible with --verbose.

Not blocking, a follow-up at most. If a release is re-run under the same version after new commits land, the range is only the new commits. Sentry's set_commits replaces the release's commit list (ReleaseCommit.objects.filter(release=release).delete() in src/sentry/models/releases/set_commits.py), so the commits sent earlier drop off. v2 behaves the same, so this keeps parity. The response includes version, so a later change could detect that the returned release is this one and handle that case on purpose.

The tests run against a real temp repository and cover the cached path, the unmatched repository, other-branch commits and option-like SHAs, which is good.

const commits = getCommitLog(cwd, { depth, paths, from });
if (commits.length === 0) {
if (commits.length === 0 && sincePreviousRelease) {
log.info(`No commits since the previous release's commit ${from}.`);

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.

Two things here.

  1. With sincePreviousRelease, an empty range still falls through to setCommitsLocal(org, version, []). Sentry treats an empty list as a no-op, so it's only a wasted request. v2 returned early ("Leaving release alone"). Could this skip the PUT and return the current release instead (getRelease is already exported)?
  2. previous-with-commits also returns this release when it already has commits, so on a re-run from is this release's own last commit. Something like No new commits since ${from}, the last commit Sentry has for this release or the one before it. would be accurate in both cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both done in f53e281. With an empty range setCommitsFromLocal now logs No new commits since <sha>, the last commit Sentry has for this release or the one before it. Leaving the release alone. and returns getRelease(org, version) instead of sending the PUT. The test for that case now checks that setCommitsLocal isn't called, and it fails without the change.

When the previous release's commit is HEAD, set-commits sent an empty
commit list. Sentry ignores it, so skip the request and return the
release, as sentry-cli v2 did. The commit can also be this release's own
last commit, so say so in the message. Log why the previous release's
commit could not be read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@srednoff888-art

Copy link
Copy Markdown
Contributor Author

Thanks for the review. f53e281 handles the three points:

  1. An empty range since the previous release's commit no longer sends the PUT. It returns the release from getRelease, like v2's "Leaving release alone".
  2. The message now says the commit is the last one Sentry has for this release or the one before it.
  3. The catch in getPreviousReleaseCommit logs Could not read the previous release's commit at debug level, and its no-silent-catch disable is gone.

test/commands/release, test/lib/api/releases.test.ts and test/lib/git* pass here except six set-commits tests that run in the repository's own folder, which fail the same way on main on this Windows machine (/G:/... is not seen as a git checkout). oxlint and oxfmt are clean on the changed files. I'll leave the re-run case you mention as not blocking for a follow-up.

@sentry-junior sentry-junior Bot 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.

Thanks @srednoff888-art, f53e281 handles all three points. With an empty range it skips the PUT and returns getRelease, which is a GET on the release details endpoint and accepts org:ci tokens, so CI tokens still work. The message is accurate for re-runs now, and the catch logs at debug level without the grandfathered disable.

On f53e281, CLI typecheck and lint pass, and test/commands/release, test/lib/git* and test/lib/api/releases.test.ts pass on Linux (175 tests), including the set-commits tests that need a git checkout. It also merges cleanly with current main. Nothing more from me. The re-run case is fine as a follow-up.

@BYK
BYK merged commit 25acf0a into getsentry:main Nov 27, 2026
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

release set-commits: the local fallback ignores the previous release's commit

2 participants