Skip to content

Commit 5e25efc

Browse files
committed
handle existing branch better if unreleased
1 parent 1fe9c05 commit 5e25efc

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

scripts/release/tag_version.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,24 @@ else
169169
if [[ ${prev_increment} == patch ]]; then
170170
error "Release branch ${release_branch} already exists, impossible upgrade from \"${prev_increment}\" to \"${increment}\" detected. Please check your ref (${ref_name}) and that no incompatible commits were cherry-picked."
171171
fi
172-
error "Release branch ${release_branch} already exists, please check your ref."
173172
fi
174173

175-
log "Creating new release branch"
176-
maybedryrun "$dry_run" git checkout -b "${release_branch}" "${ref}"
174+
if [[ -n ${remote_branch_exists} ]]; then
175+
error "Release branch ${release_branch} already exists on remote, please check your ref."
176+
fi
177+
178+
if [[ -n ${local_branch_exists} ]]; then
179+
# If it exists, ensure that this release branch points to the provided ref.
180+
release_branch_ref=$(git rev-parse "${release_branch}")
181+
if [[ ${release_branch_ref} != "${ref}" ]]; then
182+
error "Local release branch ${release_branch} already exists, but does not point to the provided ref (${ref_name})."
183+
fi
184+
log "Using existing release branch"
185+
maybedryrun "$dry_run" git checkout "${release_branch}"
186+
else
187+
log "Creating new release branch"
188+
maybedryrun "$dry_run" git checkout -b "${release_branch}" "${ref}"
189+
fi
177190
fi
178191

179192
# Ensure the ref is in the release branch.

0 commit comments

Comments
 (0)