From e6ff5751b5bde3a510dacf874421c05d570cd92c Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 26 Jun 2022 12:13:02 -0700 Subject: [PATCH] Add a script for rebasing crate branches --- scripts/rebase.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 scripts/rebase.sh diff --git a/scripts/rebase.sh b/scripts/rebase.sh new file mode 100755 index 0000000..ef1381b --- /dev/null +++ b/scripts/rebase.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -e + +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." + +if ! git diff-index --quiet HEAD; then + echo "Not running rebase.sh because git working directory is dirty" >&2 + exit 1 +fi + +if [ -z "$1" ]; then + echo "Usage: scripts/rebase.sh [crate]..." >&2 + exit 1 +fi + +base=$(git rev-parse HEAD) +push=() + +( + set -x + git fetch --quiet origin --tags +) + +for crate in "$@"; do + ( + set -x + git tag -d "$crate" &>/dev/null || true + git checkout --quiet origin/"$crate" + git rebase --quiet "$base" + ) + push+=("$(git rev-parse HEAD):refs/heads/$crate") +done + +( + set -x + git checkout --quiet "$base" +) + +git push origin --force-with-lease "${push[@]}"