From 35985041247dc3e6bdbfcb9839ef8ecfe6299373 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Fri, 5 Jun 2009 15:39:43 +0200 Subject: [Funcs/GIT] better rebasing prompt --- 01_Functions.zsh | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/01_Functions.zsh b/01_Functions.zsh index 8de4e29..84a55e1 100644 --- a/01_Functions.zsh +++ b/01_Functions.zsh @@ -73,7 +73,7 @@ preprint() get_git_branch () { - local my_git_branch REBASE + local my_git_branch if [ ! -z "$DO_NOT_CHECK_GIT_BRANCH" ] then @@ -84,25 +84,19 @@ get_git_branch () GIT_DIR=$(git-rev-parse --git-dir) - # Rebase in progress ? - REBASE=""; - [ -e $GIT_DIR/../.dotest/rebasing \ - -o -d $GIT_DIR/rebase-merge ] && \ - REBASE="rebase:" - # Get current working GIT branch - my_git_branch="$REBASE$(git-branch 2>&- | grep -E '^\* ' | cut -c3-)" + my_git_branch="$(git-branch 2>&- | grep -E '^\* ' | cut -c3-)" - if [ "$my_git_branch" != "$REBASE" ] + if [ "$my_git_branch" != "" ] then # If not on a working GIT branch, get the named current commit-ish inside parenthesis - [ "$my_git_branch" = "$REBASE(no branch)" ] &&\ - my_git_branch="($REBASE$(git-name-rev HEAD 2>&- | awk '{ print $2 }' | sed 's,^tags/,,;s,^remotes/,,'))" + [ "$my_git_branch" = "(no branch)" ] &&\ + my_git_branch="($(git-name-rev HEAD 2>&- | awk '{ print $2 }' | sed 's,^tags/,,;s,^remotes/,,'))" # If neither on a named commit-ish, show commit-id - if [ "$my_git_branch" = "(${REBASE}undefined)" ] + if [ "$my_git_branch" = "(undefined)" ] then - my_git_branch="($REBASE$(git-rev-parse --verify HEAD 2>&-))" + my_git_branch="($(git-rev-parse --verify HEAD 2>&-))" fi else # Initial commit @@ -114,6 +108,35 @@ get_git_branch () fi fi + # Rebase in progress ? + if [ -d $GIT_DIR/rebase-merge -o -d $GIT_DIR/rebase-apply ] + then + local rebase current last + local REBASE_DIR + + if [ -d $GIT_DIR/rebase-merge ] + then + REBASE_DIR=$GIT_DIR/rebase-merge + else + REBASE_DIR=$GIT_DIR/rebase-apply + fi + + if [ -d $GIT_DIR/rebase-merge ] + then + current=$(< $REBASE_DIR/done wc -l) + last=$(( $current + $(< $REBASE_DIR/git-rebase-todo grep -v "^#\|^[[:blank:]]*$" | wc -l) )) + rebase=$rebase$rebase_in_progress": " + else + current=$(cat $REBASE_DIR/next) + last=$(cat $REBASE_DIR/last) + fi + + # Then the result + rebase="[rebase $current/$last: "$(git-name-rev $(cat $REBASE_DIR/onto) | awk '{ print $2 }')".."$(basename $(cat $REBASE_DIR/head-name))"]" + + [ $current -gt 1 ] && my_git_branch=$rebase" "$my_git_branch || my_git_branch=$rebase + fi + if [ "$(git-status 2>&- | grep "new file" | head -n1)" != "" ] ; then # ADDED FILES my_git_branch=$my_git_branch" (+)" -- cgit v1.2.3