From 79bd6873fb86149e9e4926e490aec5c0ad521510 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 26 Oct 2015 18:56:29 +0100 Subject: [PATCH 1/3] 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 From 2a83b3440ef7df83817e75ce0a5ab5f26a63642e Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 27 Oct 2015 01:04:54 +0100 Subject: [PATCH 2/3] Split script to allow switching branches & simplify code --- tools/cherry_pick_to_tags.sh | 47 ++++--------------------- tools/cherry_pick_to_tags_internal.sh | 50 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 41 deletions(-) create mode 100644 tools/cherry_pick_to_tags_internal.sh diff --git a/tools/cherry_pick_to_tags.sh b/tools/cherry_pick_to_tags.sh index 62ae2aeb..0425363a 100644 --- a/tools/cherry_pick_to_tags.sh +++ b/tools/cherry_pick_to_tags.sh @@ -12,44 +12,9 @@ # 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 +# Copy internal script to a temporary untracked file because an untracked +# file is kept by git when switching branches (that way we can update tags +# where this script doesn't exist). +cp "cherry_pick_to_tags_internal.sh" "cherry_pick_to_tags_internal_tmp.sh" +sh "cherry_pick_to_tags_internal_tmp.sh" $* +rm "cherry_pick_to_tags_internal_tmp.sh" diff --git a/tools/cherry_pick_to_tags_internal.sh b/tools/cherry_pick_to_tags_internal.sh new file mode 100644 index 00000000..2ba9efa7 --- /dev/null +++ b/tools/cherry_pick_to_tags_internal.sh @@ -0,0 +1,50 @@ +#!/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" + +# update tags +git fetch --tags + +shift +for tag in "$@"; do + echo "UPDATING TAG $tag" + { + git branch tmp_update_tag_"$tag" "$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 From d082f802f4c4695a4374eaeadbc325832e94ccd2 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 13 Nov 2015 18:10:53 +0100 Subject: [PATCH 3/3] Move scripts to `scripts` folder --- {tools => scripts}/cherry_pick_to_tags.sh | 0 {tools => scripts}/cherry_pick_to_tags_internal.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {tools => scripts}/cherry_pick_to_tags.sh (100%) rename {tools => scripts}/cherry_pick_to_tags_internal.sh (100%) diff --git a/tools/cherry_pick_to_tags.sh b/scripts/cherry_pick_to_tags.sh similarity index 100% rename from tools/cherry_pick_to_tags.sh rename to scripts/cherry_pick_to_tags.sh diff --git a/tools/cherry_pick_to_tags_internal.sh b/scripts/cherry_pick_to_tags_internal.sh similarity index 100% rename from tools/cherry_pick_to_tags_internal.sh rename to scripts/cherry_pick_to_tags_internal.sh