Merge ElementsProject/secp256k1-zkp#239: sync-upstream: allows providing the local branch via cli

05b207e969f9b4181061dd3fba749b6df06de718 sync-upstream: allows providing the local branch via cli (Jonas Nick)

Pull request description:

ACKs for top commit:
  real-or-random:
    ACK 05b207e969f9b4181061dd3fba749b6df06de718

Tree-SHA512: b02f3fdf6565943cea2b93a0b2b0a38c30bb3c94873d0c4ed2ad276c75f3dc610911d1c9c076c8b7fd3a5baf83aa1ab66ec86415333cf58fe8f07c64fa74656f
This commit is contained in:
Tim Ruffing 2023-07-17 15:47:02 +02:00
commit 533571d6cf
No known key found for this signature in database
GPG Key ID: 8C461CCD293F6011

View File

@ -3,12 +3,13 @@
set -eou pipefail
help() {
echo "$0 range [end]"
echo " merges every merge commit present in upstream and missing locally."
echo "$0 [-b <branch>] range [end]"
echo " merges every merge commit present in upstream and missing in <branch> (default: master)."
echo " If the optional [end] commit is provided, only merges up to [end]."
echo " If the optional [-b branch] provided, then ."
echo
echo "$0 select <commit> ... <commit>"
echo " merges every selected merge commit"
echo "$0 [-b <branch>] select <commit> ... <commit>"
echo " merges every selected merge commit into <branch> (default: master)"
echo
echo "This tool creates a branch and a script that can be executed to create the"
echo "PR automatically. The script requires the github-cli tool (aka gh)."
@ -17,12 +18,9 @@ help() {
exit 1
}
if [ "$#" -lt 1 ]; then
help
fi
REMOTE=upstream
REMOTE_BRANCH="$REMOTE/master"
LOCAL_BRANCH="master"
# Makes sure you have a remote "upstream" that is up-to-date
setup() {
ret=0
@ -41,7 +39,7 @@ setup() {
}
range() {
RANGESTART_COMMIT=$(git merge-base "$REMOTE_BRANCH" master)
RANGESTART_COMMIT=$(git merge-base "$REMOTE_BRANCH" "$LOCAL_BRANCH")
RANGEEND_COMMIT=$(git rev-parse "$REMOTE_BRANCH")
if [ "$#" = 1 ]; then
RANGEEND_COMMIT=$1
@ -57,18 +55,37 @@ range() {
esac
}
# Process -b <branch> argument
while getopts "b:" opt; do
case $opt in
b)
LOCAL_BRANCH=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
# Shift off the processed options
shift $((OPTIND -1))
if [ "$#" -lt 1 ]; then
help
fi
case $1 in
range)
shift
setup
range "$@"
REPRODUCE_COMMAND="$0 range $RANGEEND_COMMIT"
REPRODUCE_COMMAND="$0 range -b $LOCAL_BRANCH $RANGEEND_COMMIT"
;;
select)
shift
setup
COMMITS=$*
REPRODUCE_COMMAND="$0 select $@"
REPRODUCE_COMMAND="$0 select -b $LOCAL_BRANCH $@"
;;
help)
help
@ -96,7 +113,7 @@ echo "-----------------------------------"
echo "$BODY"
echo "-----------------------------------"
# Create branch from PR commit and create PR
git checkout master
git checkout "$LOCAL_BRANCH"
git pull --autostash
git checkout -b temp-merge-"$PRNUM"
@ -115,7 +132,7 @@ cat <<EOT > "$FNAME"
#!/bin/sh
gh pr create -t '$TITLE' -b '$BODY' --web
# Remove temporary branch
git checkout master
git checkout "$LOCAL_BRANCH"
git branch -D temp-merge-"$PRNUM"
EOT
chmod +x "$FNAME"