Skip to content
Browse files

allow g co <hash>

  • Loading branch information...
1 parent 35b816e commit 92a8d95d6fae7a476437290145c4e04d1bcb1715 @orefalo committed
Showing with 15 additions and 12 deletions.
  1. +1 −1 README.md
  2. +14 −11 cmds/g2-co.sh
View
2 README.md
@@ -409,7 +409,6 @@ Distributed under the GNU General Public License, version 2.0.
* 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
-* allow g co <hash>
* g2-co: check if branch is local then checkout branch, if remote checkout -b branch origin/branch
* doc: provide basic guidance on how a commit is performed using g2
* doc: add typical solutions:
@@ -422,6 +421,7 @@ Distributed under the GNU General Public License, version 2.0.
## FIXED / DONE
+* allow g co <hash>
* Many commands are now colorized
* Added tips of the day
* fix issue with --set-upstream being deprecated
View
25 cmds/g2-co.sh
@@ -3,15 +3,18 @@
source "$G2_HOME/cmds/color.sh"
-isBranch=$("$GIT_EXE" branch -a | grep -c "$1")
-[[ $isBranch -gt 0 ]] && {
- "$GIT_EXE" abort
- $("$GIT_EXE" g2haschanges) || exit 1
- g2excludes=$("$GIT_EXE" config --global --get g2.panic.excludes)
- "$GIT_EXE" checkout "$@" && "$GIT_EXE" clean -fdx $g2excludes
- exit $?;
-}
-
-echo_info "There is no branch named '$1', you may want to run 'g fetch <remote_name>' to refresh from the server"
-echo_info "If you are trying to revert a file, consider 'g undo <file>'"
+if [ "$(echo "$1" | grep -e "^[0-9A-Fa-f]*$")" == "$1" ]; then
+ "$GIT_EXE" checkout $*
+else
+ isBranch=$("$GIT_EXE" branch -a | grep -c "$1")
+ [[ $isBranch -gt 0 ]] && {
+ "$GIT_EXE" abort
+ $("$GIT_EXE" g2haschanges) || exit 1
+ g2excludes=$("$GIT_EXE" config --global --get g2.panic.excludes)
+ "$GIT_EXE" checkout "$@" && "$GIT_EXE" clean -fdx $g2excludes
+ exit $?;
+ }
+ echo_info "There is no branch named '$1', you may want to run 'g fetch <remote_name>' to refresh from the server"
+ echo_info "If you are trying to revert a file, consider 'g undo <file>'"
+fi

0 comments on commit 92a8d95

Please sign in to comment.
Something went wrong with that request. Please try again.