diff --git a/scripts/pr.sh b/scripts/pr.sh index d764d44..d0705a6 100755 --- a/scripts/pr.sh +++ b/scripts/pr.sh @@ -99,14 +99,17 @@ await_merge() { # await_merge : waits up to 40 minutes die "the pull request of $1 is not merged after 40 minutes: gh pr checks $1" } -# Back on main after the merge; in a worktree main is checked out elsewhere, -# so this continues detached on origin/main. +# Back on main after the merge, when the local main can simply follow +# origin/main. Otherwise (main is checked out in another worktree, or holds +# commits origin/main lacks) this continues detached on origin/main and leaves +# the local main as it is. leave_branch() { git fetch --quiet origin main - if git switch --quiet main 2>/dev/null; then - git pull --quiet --ff-only + if git merge-base --is-ancestor main origin/main 2>/dev/null && git switch --quiet main 2>/dev/null; then + git merge --quiet --ff-only origin/main else git switch --quiet --detach origin/main + echo "==> continuing detached on origin/main; the local main is left as it is" fi git branch -D "$1" >/dev/null 2>&1 || true } diff --git a/scripts/test_pr.sh b/scripts/test_pr.sh index 0020750..4a1d2d0 100755 --- a/scripts/test_pr.sh +++ b/scripts/test_pr.sh @@ -201,6 +201,16 @@ git -C "$repo" switch -q main git -C "$repo" commit -q --allow-empty -m "local only" check "release: refused on a main ahead of origin" 1 release patch x VERSION release.yml VERSION +setup VERSION 1.2.3 +ci_tag v1.2.4 +git -C "$repo" switch -q main +git -C "$repo" commit -q --allow-empty -m "unpushed work on the local main" +local_main=$(git -C "$repo" rev-parse main) +git -C "$repo" switch -q feat +check "release: a local main with unpushed commits does not stop it" 0 release patch x VERSION release.yml VERSION +expect "release: the local main is left as it was" test "$(git -C "$repo" rev-parse main)" = "$local_main" +expect "release: continues detached on origin/main" test "$(git -C "$repo" rev-parse --abbrev-ref HEAD)" = HEAD + setup VERSION 1.2.3 ci_tag v2.0.0 check "release: major" 0 release major x VERSION release.yml VERSION