SELF="${SELF/-/ }"
STATE_FILE=".git/REPLAY_MERGE"
+DONT_PUSH=${DONT_PUSH:=false}
die() {
for MESSAGE in "$@"; do
die "Usage:" \
"" \
" ${SELF} <merge_commit_id> <target_remote> <target_branch>" \
+ " ${SELF} --no-push" \
" ${SELF} --continue" \
" ${SELF} --abort"
}
"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."
}
go() {
+ if [[ $# -ne 3 ]]; then
+ die_with_usage
+ fi
+ die_if_in_progress
# Process parameters.
SOURCE_COMMIT="$1"
TARGET_REMOTE="$2"
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
}
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 "$@"