From ed215a35f7d965185f6bb939053e728ffdd16080 Mon Sep 17 00:00:00 2001 From: druckdev Date: Sat, 15 May 2021 22:52:33 +0200 Subject: [PATCH] zsh:alias:git-base-branch: Make regexs more robust Fixes (in order of the patterns that were touched): - Only match `*` that come between BOL and the branch name in brackets, as another branch could be checked out at a commit containing a `*` - Only throw out commits that were committed on our current branch and not those that contain the branch name in the message (e.g. `test`). - Only match until first bracket as the commit message could also contain a pattern like `[.*]` that would be matched instead. --- .config/zsh/zshrc.d/30-alias.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.config/zsh/zshrc.d/30-alias.zsh b/.config/zsh/zshrc.d/30-alias.zsh index da182a0..a16f5c6 100644 --- a/.config/zsh/zshrc.d/30-alias.zsh +++ b/.config/zsh/zshrc.d/30-alias.zsh @@ -34,10 +34,10 @@ 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 -v "$(git rev-parse --abbrev-ref HEAD)"' + git_bb+=' | grep "^[^[]*\*"' + git_bb+=' | grep -v "^[^[]*\[$(git rev-parse --abbrev-ref HEAD)\]"' git_bb+=' | head -n1' - git_bb+=' | sed -E "s/^.*\[([^^~\]*)([~^].*)?\].*$/\1/"' + git_bb+=' | sed -E "s/^[^[]*\[([^]~^]*).*$/\1/"' alias git-base-branch="$git_bb" unset git_bb # https://stackoverflow.com/a/1549155