From 79bd6873fb86149e9e4926e490aec5c0ad521510 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 26 Oct 2015 18:56:29 +0100 Subject: [PATCH] Added script to cherry-pick a commit to multiple tags --- tools/cherry_pick_to_tags.sh | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tools/cherry_pick_to_tags.sh diff --git a/tools/cherry_pick_to_tags.sh b/tools/cherry_pick_to_tags.sh new file mode 100644 index 00000000..62ae2aeb --- /dev/null +++ b/tools/cherry_pick_to_tags.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# Copyright 2014 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +# Exit if anything fails +set -e + +if [ "$#" -lt 2 ]; then + echo "Usage: $0 COMMIT_HASH TAGS" >&2 + exit 1 +fi + +branch_name=$(git symbolic-ref -q HEAD) +branch_name=${branch_name##refs/heads/} +branch_name=${branch_name:-HEAD} + +commit="$1" + +echo "current branch $branch_name" +echo "commit hash $commit" + +shift + +for tag in "$@"; do + echo "UPDATING TAG $tag" + { + # backup the tag in case it doesn't exist in origin + git tag backup_"$tag" "$tag" + # delete it to get the most recent version from origin + git tag -d "$tag" + git fetch --tags + git branch tmp_update_tag_"$tag" "$tag" + # the tag seems exists in origin, delete the backup + git tag -d backup_"$tag" + + # cherry pick commit and update tag + git checkout tmp_update_tag_"$tag" + git cherry-pick -x "$commit" + git tag -f "$tag" HEAD + + # switch back to previous branch + git checkout "$branch_name" + git branch -D tmp_update_tag_"$tag" + + # push the updated tag + git push origin "$tag" --force + } >/dev/null +done