From c1955dd5f54005a336c5cc52f7029de5db050b04 Mon Sep 17 00:00:00 2001 From: druckdev Date: Sat, 15 May 2021 23:17:36 +0200 Subject: [PATCH] zsh:alias:git-base-branch: Match merge commits too Merge commits should also be matched (indicated by a '-') for the case that the base branches last commit is a merge commit and another branch exists that checked out the newest commit that was merged. Example log (from `glog`): ``` * abcdef Foo (HEAD -> feature) * bcdefa Merge branch 'other-feature' into base (base) |\ | * cdefab Bar (other-feature) |/ * ... ... ``` with `git show-branch -a` output like: ``` ! [base] Merge branch 'other-feature' into base * [feature] Foo ! [other-feature] Bar --- * [feature] Foo -- [base] Merge branch 'other-feature' into base +*+ [other-feature] Bar ``` Here we want `base` to be returned instead of `other-feature` and thus '-' needs to be matched as well. --- .config/zsh/zshrc.d/30-alias.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/zsh/zshrc.d/30-alias.zsh b/.config/zsh/zshrc.d/30-alias.zsh index a16f5c6..1d62c03 100644 --- a/.config/zsh/zshrc.d/30-alias.zsh +++ b/.config/zsh/zshrc.d/30-alias.zsh @@ -34,7 +34,7 @@ alias gss='git stash' # https://nilansanjaya.wordpress.com/2017/06/02/git-find-base-branch/ git_bb='git show-branch -a 2>/dev/null' - git_bb+=' | grep "^[^[]*\*"' + git_bb+=' | grep "^[^[]*[*-].*\["' git_bb+=' | grep -v "^[^[]*\[$(git rev-parse --abbrev-ref HEAD)\]"' git_bb+=' | head -n1' git_bb+=' | sed -E "s/^[^[]*\[([^]~^]*).*$/\1/"'