Permalink
Browse files

make the prompt smarter, it can now show rebase, am, merge..etc... st…

…ates
  • Loading branch information...
1 parent ad35186 commit 742e4be8547fa068468c5c984b1861b1c37a6bf8 @orefalo committed May 12, 2013
Showing with 69 additions and 67 deletions.
  1. +2 −1 README.md
  2. +1 −0 g2-install.sh
  3. +66 −66 g2-prompt.sh
View
@@ -413,7 +413,7 @@ Distributed under the GNU General Public License, version 2.0.
##TODO
-* git-prompt: detect rebase, rather than displaying detached-branch
+
* g remote: when resetting origin, prompt user to override existing
* g track origin/blabla - if origin/blabla not setup, prompt user to fetch from origin
* g br newbranch (from a branch with no remote) -> does prompt to create the branch
@@ -423,6 +423,7 @@ Distributed under the GNU General Public License, version 2.0.
## FIXED / DONE
+* git-prompt: detect rebase, rather than displaying detached-branch
* Validate that we are in a git repo before any action is run
* Homebrew fomula is now live
* allow g co <hash>
View
@@ -13,6 +13,7 @@ OLDpwd=$PWD
cd $DIR
export G2_HOME=$DIR
+export GIT_PS1_DESCRIBE_STYLE=branch
source ./cmds/color.sh
View
@@ -338,60 +338,73 @@ parse_g2_status() {
#### GET GIT OP
- local modified untracked added init detached
+ local modified added init detached
- $("$GIT_EXE" ls-tree HEAD &>/dev/null)
- [[ $? -eq 128 ]] && init=init || {
+ # Figures the state of the repo
+ local op=""
+ local branch=""
+ local step=""
+ local total=""
- if ! grep -q "^ref:" $git_dir/HEAD 2>/dev/null; then
- detached=detached
- fi
- [[ $(( $untracked_files + $modified_files + $added_files )) -eq 0 ]] && clean=clean || {
- [[ $untracked_files -gt 0 ]] && untracked=untracked;
- [[ $modified_files -gt 0 ]] && modified=modified;
- [[ $added_files -gt 0 ]] && added=added;
- }
- }
+ $("$GIT_EXE" ls-tree HEAD &>/dev/null)
+ [[ $? -eq 128 ]] && init=init || {
- local op
- if [[ -d "$git_dir/.dotest" ]] ; then
+ if [ -d "$git_dir/rebase-merge" ]; then
- if [[ -f "$git_dir/.dotest/rebasing" ]] ; then
+ step=$(cat "$git_dir/rebase-merge/msgnum")
+ total=$(cat "$git_dir/rebase-merge/end")
+ branch="$(cat "$git_dir/rebase-merge/head-name") $step/$total"
+ if [ -f "$git_dir/rebase-merge/interactive" ]; then
+ op="rebase -i"
+ else
+ op="rebase -m"
+ fi
+ else
+ if [ -d "$git_dir/rebase-apply" ]; then
+ step=$(cat "$git_dir/rebase-apply/next")
+ total=$(cat "$git_dir/rebase-apply/last")
+ if [ -f "$git_dir/rebase-apply/rebasing" ]; then
op="rebase"
-
- elif [[ -f "$git_dir/.dotest/applying" ]] ; then
+ elif [ -f "$git_dir/rebase-apply/applying" ]; then
op="am"
-
- else
+ else
op="am/rebase"
-
+ fi
+ elif [ -f "$git_dir/MERGE_HEAD" ]; then
+ op="merge"
+ elif [ -f "$git_dir/CHERRY_PICK_HEAD" ]; then
+ op="cherrypick"
+ elif [ -f "$git_dir/REVERT_HEAD" ]; then
+ op="revert"
+ elif [ -f "$git_dir/BISECT_LOG" ]; then
+ op="bisect"
fi
- elif [[ -f "$git_dir/.dotest-merge/interactive" ]] ; then
- op="rebase -i"
- # ??? branch="$(cat "$git_dir/.dotest-merge/head-name")"
-
- elif [[ -d "$git_dir/.dotest-merge" ]] ; then
- op="rebase -m"
- # ??? branch="$(cat "$git_dir/.dotest-merge/head-name")"
-
- # lvv: not always works. Should ./.dotest be used instead?
- elif [[ -f "$git_dir/MERGE_HEAD" ]] ; then
- op="merge"
- # ??? branch="$(git symbolic-ref HEAD 2>/dev/null)"
-
- elif [[ -f "$git_dir/index.lock" ]] ; then
- op="locked"
-
- else
- [[ -f "$git_dir/BISECT_LOG" ]] && op="bisect"
- # ??? branch="$(git symbolic-ref HEAD 2>/dev/null)" || \
- # branch="$(git describe --exact-match HEAD 2>/dev/null)" || \
- # branch="$(cut -c1-7 "$git_dir/HEAD")..."
- fi
-
-
+ branch="$($GIT_EXE symbolic-ref HEAD 2>/dev/null)" || {
+ [ -z "$op" ] && op="detached" && detached=detached
+ branch="$(
+ case "${GIT_PS1_DESCRIBE_STYLE-}" in
+ (contains)
+ $GIT_EXE describe --contains HEAD ;;
+ (branch)
+ $GIT_EXE describe --contains --all HEAD ;;
+ (describe)
+ $GIT_EXE describe HEAD ;;
+ (* | default)
+ $GIT_EXE describe --tags --exact-match HEAD ;;
+ esac 2>/dev/null)" ||
+
+ branch="$(cut -c1-7 "$git_dir/HEAD" 2>/dev/null)..." ||
+ branch="unknown"
+
+ if [ -n "$step" ] && [ -n "$total" ]; then
+ branch="$branch $step/$total"
+ fi
+ branch="[$branch]"
+ }
+ fi
+ }
#### GET GIT HEX-REVISION
local rawhex=""
if [[ $rawhex_len -gt 0 ]] ; then
@@ -400,45 +413,32 @@ parse_g2_status() {
rawhex="=$hex_vcs_color${rawhex:0:$rawhex_len}"
fi
- #### branch
- local branch=$("$GIT_EXE" branch | grep "*" | sed "s/* //")
- branch=${branch/#master/M}
-
- # another method of above:
- # branch=$(git symbolic-ref -q HEAD || { echo -n "detached:" ; git name-rev --name-only HEAD 2>/dev/null; } )
- # branch=${branch#refs/heads/}
+ #### remove junk from branch name, substitute master to M
+ branch=${branch/#refs\/heads\//}
+ branch=${branch/#master/M}
### compose vcs_info
-
local vcs_info
if [ $init ]; then
vcs_info=${WHITE}init
else
- if [ "$detached" ] ; then
- branch="<detached:$("$GIT_EXE" name-rev --name-only HEAD 2>/dev/null)"
- elif [ "$op" ]; then
- branch="$op:$branch"
- if [ "$op" == "merge" ] ; then
- branch+="<--$("$GIT_EXE" name-rev --name-only $(<$git_dir/MERGE_HEAD))"
- fi
- #branch="<$branch>"
- fi
- vcs_info="$branch$rawhex"
+ if [ "$op" ]; then
+ branch="$op:$branch"
+ fi
+ vcs_info="$branch$rawhex"
fi
### status: choose primary (for branch color)
- # unset status
local status=${op:+op}
status=${status:-$detached}
status=${status:-$clean}
status=${status:-$modified}
status=${status:-$added}
status=${status:-$untracked}
status=${status:-$init}
- # at least one should be set
- : ${status?prompt internal error: git status}
+ # at least one should be set
+ : ${status?prompt internal error: git status}
eval vcs_color="\${${status}_vcs_color}"
- # no def: vcs_color=${vcs_color:-$WHITE} # default
### file list
local status_info=""

0 comments on commit 742e4be

Please sign in to comment.