summaryrefslogtreecommitdiff
path: root/bin/git-merge-ff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-10-16 14:48:52 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-10-18 12:40:47 -0700
commit589b32ae19046cefa8aa4cb872a777fdea11e2c0 (patch)
tree23520ed7280b49d1eba86dc3dc2703653581c286 /bin/git-merge-ff
parentf36a286d9ecba1b1c3e8856606e3a9570d03e78d (diff)
downloaddotfiles-589b32ae19046cefa8aa4cb872a777fdea11e2c0.tar.gz
git-merge-ff: handle branches checked out in other worktrees
Diffstat (limited to 'bin/git-merge-ff')
-rwxr-xr-xbin/git-merge-ff9
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