From 23f69e5626e8cc67623464935ab1129f71fb16a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 27 Jun 2018 09:30:05 +0200 Subject: [PATCH] Add --no-push and --push options and DONT_PUSH environment as default to control what happens after merge --- util/git-replay-merge.sh | 69 +++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/util/git-replay-merge.sh b/util/git-replay-merge.sh index 8c43a2fb42..2371c5f973 100755 --- a/util/git-replay-merge.sh +++ b/util/git-replay-merge.sh @@ -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} " \ + " ${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 "$@"