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.
This commit is contained in:
2021-05-15 22:52:33 +02:00
parent f58c5fdb27
commit ed215a35f7

View File

@@ -34,10 +34,10 @@
alias gss='git stash' alias gss='git stash'
# https://nilansanjaya.wordpress.com/2017/06/02/git-find-base-branch/ # https://nilansanjaya.wordpress.com/2017/06/02/git-find-base-branch/
git_bb='git show-branch -a 2>/dev/null' 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+=' | grep -v "^[^[]*\[$(git rev-parse --abbrev-ref HEAD)\]"'
git_bb+=' | head -n1' git_bb+=' | head -n1'
git_bb+=' | sed -E "s/^.*\[([^^~\]*)([~^].*)?\].*$/\1/"' git_bb+=' | sed -E "s/^[^[]*\[([^]~^]*).*$/\1/"'
alias git-base-branch="$git_bb" alias git-base-branch="$git_bb"
unset git_bb unset git_bb
# https://stackoverflow.com/a/1549155 # https://stackoverflow.com/a/1549155