Skip to content

Commit f738863

Browse files
committed
Fix splitting force push
1 parent 09badb7 commit f738863

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

scripts/split-webentor-core.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ git subtree split --prefix=packages/webentor-core -b split/webentor-core-mirror
3030

3131
MIRROR_URL="https://x-access-token:${CORE_MIRROR_TOKEN}@github.com/${CORE_MIRROR_REPO}.git"
3232

33-
# Force-with-lease protects against clobbering unexpected remote state changes.
34-
git push "$MIRROR_URL" split/webentor-core-mirror:main --force-with-lease
33+
# Query mirror remote state and use an explicit lease against its current main tip.
34+
REMOTE_MAIN_SHA="$(git ls-remote --heads "$MIRROR_URL" main | awk '{print $1}')"
35+
if [ -n "$REMOTE_MAIN_SHA" ]; then
36+
git push "$MIRROR_URL" split/webentor-core-mirror:main --force-with-lease="main:${REMOTE_MAIN_SHA}"
37+
else
38+
# First mirror run can target repos where main does not exist yet.
39+
git push "$MIRROR_URL" split/webentor-core-mirror:main --force
40+
fi
3541
git push "$MIRROR_URL" "split/webentor-core-mirror:refs/tags/${TAG}" --force
3642

3743
echo "Mirrored packages/webentor-core to ${CORE_MIRROR_REPO} with tag ${TAG}."

scripts/split-webentor-setup.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ git subtree split --prefix=packages/webentor-setup -b split/webentor-setup-mirro
2929

3030
MIRROR_URL="https://x-access-token:${SETUP_MIRROR_TOKEN}@github.com/${SETUP_MIRROR_REPO}.git"
3131

32-
git push "$MIRROR_URL" split/webentor-setup-mirror:main --force-with-lease
32+
# Query mirror remote state and use an explicit lease against its current main tip.
33+
REMOTE_MAIN_SHA="$(git ls-remote --heads "$MIRROR_URL" main | awk '{print $1}')"
34+
if [ -n "$REMOTE_MAIN_SHA" ]; then
35+
git push "$MIRROR_URL" split/webentor-setup-mirror:main --force-with-lease="main:${REMOTE_MAIN_SHA}"
36+
else
37+
# First mirror run can target repos where main does not exist yet.
38+
git push "$MIRROR_URL" split/webentor-setup-mirror:main --force
39+
fi
3340
git push "$MIRROR_URL" "split/webentor-setup-mirror:refs/tags/${TAG}" --force
3441

3542
echo "Mirrored packages/webentor-setup to ${SETUP_MIRROR_REPO} with tag ${TAG}."

scripts/split-webentor-starter.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ git subtree split --prefix=packages/webentor-starter -b split/webentor-starter-m
2929

3030
MIRROR_URL="https://x-access-token:${STARTER_MIRROR_TOKEN}@github.com/${STARTER_MIRROR_REPO}.git"
3131

32-
git push "$MIRROR_URL" split/webentor-starter-mirror:main --force-with-lease
32+
# Query mirror remote state and use an explicit lease against its current main tip.
33+
REMOTE_MAIN_SHA="$(git ls-remote --heads "$MIRROR_URL" main | awk '{print $1}')"
34+
if [ -n "$REMOTE_MAIN_SHA" ]; then
35+
git push "$MIRROR_URL" split/webentor-starter-mirror:main --force-with-lease="main:${REMOTE_MAIN_SHA}"
36+
else
37+
# First mirror run can target repos where main does not exist yet.
38+
git push "$MIRROR_URL" split/webentor-starter-mirror:main --force
39+
fi
3340
git push "$MIRROR_URL" "split/webentor-starter-mirror:refs/tags/${TAG}" --force
3441

3542
echo "Mirrored packages/webentor-starter to ${STARTER_MIRROR_REPO} with tag ${TAG}."

0 commit comments

Comments
 (0)