]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add --no-push and --push options and DONT_PUSH environment as default to control...
authorOndřej Surý <ondrej@sury.org>
Wed, 27 Jun 2018 07:30:05 +0000 (09:30 +0200)
committerEvan Hunt <each@isc.org>
Wed, 11 Jul 2018 03:44:12 +0000 (20:44 -0700)
util/git-replay-merge.sh

index 8c43a2fb421e09d93f700e05a191780f172a3a84..2371c5f973d136f640f39e3e5850af583f57df33 100755 (executable)
@@ -15,6 +15,7 @@ SELF="$(basename $0)"
 SELF="${SELF/-/ }"
 
 STATE_FILE=".git/REPLAY_MERGE"
+DONT_PUSH=${DONT_PUSH:=false}
 
 die() {
        for MESSAGE in "$@"; do
@@ -27,6 +28,7 @@ die_with_usage() {
        die "Usage:"                                                            \
            ""                                                                  \
            "   ${SELF} <merge_commit_id> <target_remote> <target_branch>"      \
+           "   ${SELF} --no-push"                                              \
            "   ${SELF} --continue"                                             \
            "   ${SELF} --abort"
 }
@@ -45,6 +47,13 @@ die_with_continue_instructions() {
            "Use \"${SELF} --abort\" to abort the replay."
 }
 
+die_before_push() {
+       die ""                                                                          \
+           "Replay finished locally.  Now check the result in ${REPLAY_BRANCH}."       \
+           "When done, run \"${SELF} --continue\" to push and create MR in gitlab."    \
+           "Use \"${SELF} --abort\" to abort the replay."
+}
+
 die_if_wrong_dir() {
        if [[ ! -d ".git" ]]; then
                die "You need to run this command from the toplevel of the working tree."
@@ -85,6 +94,10 @@ branch_exists() {
 }
 
 go() {
+       if [[ $# -ne 3 ]]; then
+               die_with_usage
+       fi
+       die_if_in_progress
        # Process parameters.
        SOURCE_COMMIT="$1"
        TARGET_REMOTE="$2"
@@ -155,12 +168,16 @@ resume() {
                fi
        fi
 
+       if [[ "$DONT_PUSH" = "true" ]]; then
+               die_before_push
+       fi
+
        git push ${TARGET_REMOTE} -u ${REPLAY_BRANCH}:${REPLAY_BRANCH}
 
        REPLAY_COMMIT_TITLE="$(git show --format="%b" "${SOURCE_COMMIT}" 2>&1 | head -1)"
 
        gitlab create_merge_request 1 "${REPLAY_COMMIT_TITLE}" "{source_branch: '${REPLAY_BRANCH}', target_branch: '${TARGET_BRANCH}'}"
-       
+
        cleanup
        exit 0
 }
@@ -176,24 +193,32 @@ cleanup() {
        rm -f "${STATE_FILE}"
 }
 
-case "$1" in
-       "--abort")
-               die_if_not_in_progress
-               source "${STATE_FILE}"
-               cleanup
-               ;;
-       "--continue")
-               verify_gitlab_cli
-               die_if_not_in_progress
-               source "${STATE_FILE}"
-               resume
-               ;;
-       *)
-               if [[ $# -ne 3 ]]; then
-                       die_with_usage
-               fi
-               verify_gitlab_cli
-               die_if_in_progress
-               go "$@"
-               ;;
-esac
+next_action="go"
+while [[ $# -gt 3 ]]; do
+       case "$1" in
+               "--abort")
+                       die_if_not_in_progress
+                       source "${STATE_FILE}"
+                       next_action="cleanup"
+                       ;;
+               "--continue")
+                       verify_gitlab_cli
+                       die_if_not_in_progress
+                       source "${STATE_FILE}"
+                       next_action="resume"
+                       ;;
+               "--no-push")
+                       DONT_PUSH=true
+                       ;;
+               "--push")
+                       DONT_PUSH=false
+                       ;;
+       esac
+       shift
+done
+
+if [[ "DONT_PUSH" = "false" ]]; then
+       verify_gitlab_cli
+fi
+
+$next_action "$@"