Repository navigation
Open
Labels
featureRequest or implement a new featureRequest or implement a new feature
Milestone
Description
Summary
Make the semver script robust when running on local feature/topic branches by preferring local branch SHAs first and falling back to remote lookups only when necessary. This reduces reliance on remote queries (git ls-remote / GitHub API) and avoids failures like:
Error: branch 'marcuscastelo/issue1382' does not exist in remote https://github.com/marcuscastelo/macroflows
Motivation
Currently .scripts/semver.sh attempts to resolve branch SHAs via remote lookups which can:
- Fail when the local branch exists only in the local clone (e.g. feature branches not pushed yet).
- Unnecessarily consume GitHub API or remote git queries, contributing to rate limit/quota usage.
We want the script to:
- Try resolving branch/commit info locally (fast, offline-capable).
- If local resolution fails, fall back to remote lookups as a secondary option.
Current behavior
get_sha_for_branchcallsgit ls-remote "$REPO_URL" "refs/heads/$branch"and exits with an error if the branch is not present remotely.- This causes the script to fail for local-only branches and increases remote request usage.
Example observed error:
Error: branch 'marcuscastelo/issue1382' does not exist in remote https://github.com/marcuscastelo/macroflows
Proposed solution
Change .scripts/semver.sh so that get_sha_for_branch:
- First attempts a local resolution:
- Use
git rev-parse --verify "refs/heads/$branch"orgit show-ref --verify -- "refs/heads/$branch"to get a local SHA. - If the branch name may include remote/namespace prefixes, also try
git rev-parse --verify "$branch"andgit rev-parse --verify "origin/$branch"as sensible local fallbacks.
- Use
- If local resolution fails, then perform the remote
git ls-remotelookup (current behavior). - When falling back to remote, prefer
git ls-remoteover GitHub API calls where possible to reduce API quota usage. Only use GitHub API for operations that require it (e.g., listing branches for rc discovery), and add retry/backoff as already present.
Additionally:
- Update
get_current_branchand other functions to prefer local information when available. - Add robust error messages that clearly indicate whether a local or remote lookup failed.
- Add unit-testable helper functions (where reasonable for a shell script) or at least a test-mode (
--test) verification path that simulates local vs remote behavior.
Implementation notes
Suggested implementation changes inside .scripts/semver.sh:
- Update
get_sha_for_branch()to something like:- Try
git rev-parse --verify --quiet "refs/heads/$branch"-> if found, use that SHA. - Try
git rev-parse --verify --quiet "$branch"(handles detached HEAD/refs) -> if found, use it. - Fallback to
git ls-remote "$REPO_URL" "refs/heads/$branch"(current behavior).
- Try
- When falling back to remote, keep the existing error handling and messages.
- Where commit counts are calculated (e.g.,
get_commit_count_between), prefergit rev-list --count <from>..<to>when both SHAs are available locally; otherwise, fall back to the existing GitHub compare endpoint with retry/backoff.
Acceptance criteria
- Running
.scripts/semver.shon a local-only branch no longer fails with "branch ... does not exist in remote ..." — it produces a dev/rc version as expected. - Remote lookups only happen if necessary (local resolution fails).
- Existing behaviors (rc/stable discovery) remain unchanged for branches pushed remotely.
- Error handling and debug logs remain informative and preserve current retry/backoff logic for remote calls.
- Tests or manual verification steps documented in the PR description.
Files to change
.scripts/semver.sh— prefer local branch resolution, add local-based commit count logic where applicable.
Suggested follow-ups
- Add a small integration test that creates a local branch and runs the script to assert it resolves a dev version without pushing.
- Document the fallback behavior in
docs/or the script header.
Metadata
Metadata
Assignees
Labels
featureRequest or implement a new featureRequest or implement a new feature
Activity