dotfiles/script/branchname

24 lines
476 B
Plaintext
Raw Permalink Normal View History

#!/usr/bin/env bash
#
# branchname - print current branchname, including during rebase
#
# https://stackoverflow.com/questions/34213120/find-branch-name-during-git-rebase
set -e
branchname=$(git bn)
if [ "$branchname" = "HEAD" ]; then
2023-10-07 08:43:32 +00:00
if ! branchoutput=$(git branch --list | grep rebasing); then
exit 1
fi
regex="rebasing ([^)]+)\)"
if [[ $branchoutput =~ $regex ]]; then
branchname="${BASH_REMATCH[1]}"
else
exit 2
fi
fi
2023-10-07 08:43:32 +00:00
printf "%s" "$branchname"