From e0949a2d329b434999fdb285c2461ad880c7f337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 4 Dec 2019 15:32:10 +0100 Subject: shellrc.d/git: fix problem with / in gitbmerge --- shellrc.d/git | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/shellrc.d/git b/shellrc.d/git index 2dac8bb..1c1de0a 100644 --- a/shellrc.d/git +++ b/shellrc.d/git @@ -1,5 +1,12 @@ # vim: ft=sh: +# Get path to worktree for git branch +_gitbworktree() { + git worktree list --porcelain | \ + awk -v ref="refs/heads/$1" \ + '/^worktree / { worktree = $2 }; /^branch / { if ($2 == ref) { print worktree }}' +} + # Automatic branch merger (merge branch, push it to server and remove branch) # Expects name of the branch as argument # It fails if it's not fast forward merge and if there is fixup! commit. @@ -9,9 +16,10 @@ gitbmerge() ( echo "First squash fixups!" exit 1 fi - local WT="$(git worktree list | sed -nE "/\[$1\]/{s/([^ ]+) .*/\1/p}")" - if [ -n "$WT" ]; then - rm -r "$WT" + local wt + wt="$(_gitbworktree "$1")" + if [ -n "$wt" ]; then + rm -r "$wt" git worktree prune fi git merge --ff-only "$1" && git push && git branch -d "$1" && git push origin :"$1" -- cgit v1.2.3