Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the release.sh workflow by adding pre-flight Git checks before proceeding with the release/tagging steps, helping prevent releases from an incorrect local state.
Changes:
- Add a guard requiring the current branch to be
main. - Require a clean working tree before releasing.
- Fetch
originand ensure localmainmatchesorigin/mainbefore continuing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fi | ||
|
|
||
| git fetch origin | ||
| if [[ -n "$(git diff HEAD origin/main)" ]]; then |
There was a problem hiding this comment.
The up-to-date check uses git diff HEAD origin/main, which compares trees only. It can be empty even when HEAD is a different commit than origin/main (same tree, different history), causing the release tags to be created from the wrong commit. Consider verifying commit equality (e.g., compare git rev-parse HEAD vs git rev-parse origin/main, or otherwise ensure HEAD exactly matches the remote tip).
| if [[ -n "$(git diff HEAD origin/main)" ]]; then | |
| head_commit="$(git rev-parse HEAD)" | |
| origin_main_commit="$(git rev-parse origin/main)" | |
| if [[ "${head_commit}" != "${origin_main_commit}" ]]; then |
| fi | ||
|
|
||
| git fetch origin | ||
| if [[ -n "$(git diff HEAD origin/main)" ]]; then |
There was a problem hiding this comment.
[[ -n "$(git diff HEAD origin/main)" ]] materializes the entire diff output into a shell variable, which is unnecessary and can be slow/memory-heavy on large diffs. Prefer a quiet check (e.g., git diff --quiet ...) and branch on the exit status.
| if [[ -n "$(git diff HEAD origin/main)" ]]; then | |
| if ! git diff --quiet HEAD origin/main; then |
| git fetch origin | ||
| if [[ -n "$(git diff HEAD origin/main)" ]]; then | ||
| echo "Local main is not up to date with origin/main. Pull first." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
There was a problem hiding this comment.
The script now hardcodes origin/main (both in git fetch origin and in the comparison). This is a behavioral regression vs git pull because it will fail for clones that don't have a remote named origin or where main tracks a different upstream. Consider deriving the upstream ref from main’s configured tracking branch (e.g., @{u}) and fetching that, or emitting a clear error if no upstream is configured.
| git fetch origin | |
| if [[ -n "$(git diff HEAD origin/main)" ]]; then | |
| echo "Local main is not up to date with origin/main. Pull first." >&2 | |
| exit 1 | |
| fi | |
| upstream_ref="$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null || true)" | |
| if [[ -z "${upstream_ref}" ]]; then | |
| echo "The main branch has no configured upstream. Configure a tracking branch first." >&2 | |
| exit 1 | |
| fi | |
| upstream_remote="${upstream_ref%%/*}" | |
| git fetch "${upstream_remote}" | |
| if [[ -n "$(git diff HEAD "${upstream_ref}")" ]]; then | |
| echo "Local main is not up to date with ${upstream_ref}. Pull first." >&2 | |
| exit 1 | |
| fi |
Using git rev-parse ensures we detect divergence even when tree content is identical across different commits, and avoids materializing the full diff output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Provides actionable error messages so the user knows whether to pull, push, or rebase when local main doesn't match origin/main. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
No description provided.