diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-10-16 14:48:52 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-10-18 12:40:47 -0700 |
commit | 589b32ae19046cefa8aa4cb872a777fdea11e2c0 (patch) | |
tree | 23520ed7280b49d1eba86dc3dc2703653581c286 /bin/git-merge-ff | |
parent | f36a286d9ecba1b1c3e8856606e3a9570d03e78d (diff) | |
download | dotfiles-589b32ae19046cefa8aa4cb872a777fdea11e2c0.tar.gz |
git-merge-ff: handle branches checked out in other worktrees
Diffstat (limited to 'bin/git-merge-ff')
-rwxr-xr-x | bin/git-merge-ff | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/bin/git-merge-ff b/bin/git-merge-ff index 3d58a662..a367573c 100755 --- a/bin/git-merge-ff +++ b/bin/git-merge-ff @@ -12,6 +12,8 @@ # which avoids an error when there is a filename and branch with the # same name +# modified by spwhitton to handle branches checked out in other worktrees + _usage() { echo "Usage: git merge-ff <branch> [<committish-to-merge>]" 1>&2 exit 1 @@ -33,8 +35,11 @@ _merge_ff() { _usage fi - if [ "$(git symbolic-ref HEAD)" = "refs/heads/$branch" ]; then - git merge $quiet --ff-only "$commit" + worktree=$(git worktree list --porcelain | perl -000 -wn \ + -e'm#^branch refs/heads/'"$branch"'$#m && m#^worktree (.+)$#m && print $1') + + if [ -n "$worktree" ]; then + git -C "$worktree" merge $quiet --ff-only "$commit" else if [ "$(git merge-base $branch_orig_hash $commit_orig_hash)" != "$branch_orig_hash" ]; then echo "Error: merging $commit into $branch would not be a fast-forward" 1>&2 |