From db87352742519a2fbe9e43ef3091442c61754791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Kr=C4=99cicki?= Date: Thu, 30 May 2019 10:08:36 +0200 Subject: [PATCH] util/git-replay-merge.sh: make the tool compatible with git worktrees --- util/git-replay-merge.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/util/git-replay-merge.sh b/util/git-replay-merge.sh index 729e60d351..7091d770aa 100755 --- a/util/git-replay-merge.sh +++ b/util/git-replay-merge.sh @@ -14,7 +14,6 @@ set -e SELF="$(basename $0)" SELF="${SELF/-/ }" -STATE_FILE=".git/REPLAY_MERGE" DONT_PUSH=${DONT_PUSH:=false} DONT_ACCEPT=${DONT_ACCEPT:=false} @@ -40,13 +39,6 @@ die_with_usage() { " ${SELF} --abort" } -verify_gitlab_cli() { - which gitlab >/dev/null 2>&1 || \ - die "You need to have gitlab cli installed and configured: "\ - "" \ - "$ gem install --user-install gitlab" -} - die_with_continue_instructions() { die "" \ "Replay interrupted. Conflicts need to be fixed manually." \ @@ -62,7 +54,7 @@ die_before_push() { } die_if_wrong_dir() { - if [[ ! -d ".git" ]]; then + if [[ ! -d "$WORKDIR" ]]; then die "You need to run this command from the toplevel of the working tree." fi } @@ -90,6 +82,21 @@ die_if_local_behind_target() { fi } +get_workdir() { + DOTGIT="$(git rev-parse --show-toplevel)/.git" + if [[ -f "${WORKDIR}" ]]; then + sed -n 's/^gitdir: //p' "${DOTGIT}" + fi + echo "${DOTGIT}" +} + +verify_gitlab_cli() { + which gitlab >/dev/null 2>&1 || \ + die "You need to have gitlab cli installed and configured: "\ + "" \ + "$ gem install --user-install gitlab" +} + branch_exists() { ESCAPED_BRANCH_NAME=${1//\//\\\/} BRANCH_REGEX="/^(remotes\/)?${ESCAPED_BRANCH_NAME}$/" @@ -211,7 +218,7 @@ cleanup() { rm -f "${STATE_FILE}" } -cd $(git rev-parse --show-toplevel) +STATE_FILE="$(get_workdir)/REPLAY_MERGE" next_action="go" while [[ $# -ge 1 ]]; do