Skip to content

Commit

Permalink
coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Refalo committed Mar 3, 2013
1 parent c21d177 commit 42752eb
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -422,6 +422,7 @@ Distributed under the GNU General Public License, version 2.0.


## FIXED / DONE ## FIXED / DONE


* Many commands are now colorized
* Added tips of the day * Added tips of the day
* fix issue with --set-upstream being deprecated * fix issue with --set-upstream being deprecated
* fix warning when running: g track <remote/branch> * fix warning when running: g track <remote/branch>
Expand Down
4 changes: 3 additions & 1 deletion cmds/g2-abort.sh
Expand Up @@ -2,4 +2,6 @@
# #
# Aborts a merge or rebase # Aborts a merge or rebase


[[ ! $("$GIT_EXE" rev-parse --git-dir 2> /dev/null) ]] && echo "fatal: Not a Git Repository" || ("$GIT_EXE" merge --abort 2> /dev/null || "$GIT_EXE" rebase --abort 2> /dev/null) source "$G2_HOME/cmds/color.sh"

[[ ! $("$GIT_EXE" rev-parse --git-dir 2> /dev/null) ]] && echo_fatal "fatal: Not a Git Repository" || ("$GIT_EXE" merge --abort 2> /dev/null || "$GIT_EXE" rebase --abort 2> /dev/null)
5 changes: 3 additions & 2 deletions cmds/g2-ci.sh
@@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# #
source "$G2_HOME/cmds/color.sh"


[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: WIP detected, please <unwip> first." && exit 1 [[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: WIP detected, please <unwip> first." && exit 1
[[ $("$GIT_EXE" diff --cached --numstat | wc -l) -eq 0 ]] && echo "fatal: No files to commit, please <freeze> changes first." || "$GIT_EXE" commit -u "$@" [[ $("$GIT_EXE" diff --cached --numstat | wc -l) -eq 0 ]] && echo_fatal "fatal: No files to commit, please <freeze> changes first." || "$GIT_EXE" commit -u "$@"
10 changes: 6 additions & 4 deletions cmds/g2-co.sh
@@ -1,9 +1,11 @@
#!/bin/bash #!/bin/bash
# #


source "$G2_HOME/cmds/color.sh"

hasChanges() { hasChanges() {
[[ $("$GIT_EXE" diff --cached --numstat | wc -l) -ne 0 ]] && echo "fatal: staged changed detected, please commit <ci> or <wip> them." && exit 1 [[ $("$GIT_EXE" diff --cached --numstat | wc -l) -ne 0 ]] && echo_fatal "fatal: staged changed detected, please commit <ci> or <wip> them." && exit 1
[[ $("$GIT_EXE" diff --numstat | wc -l) -ne 0 ]] && echo "fatal: some files were changed in this branch, either commit <ci>, <wip> or <panic>." && exit 1 [[ $("$GIT_EXE" diff --numstat | wc -l) -ne 0 ]] && echo_fatal "fatal: some files were changed in this branch, either commit <ci>, <wip> or <panic>." && exit 1
} }


isBranch=$("$GIT_EXE" branch -a | grep -c "$1") isBranch=$("$GIT_EXE" branch -a | grep -c "$1")
Expand All @@ -15,6 +17,6 @@ isBranch=$("$GIT_EXE" branch -a | grep -c "$1")
exit $?; exit $?;
} }


echo "There is no branch called '$1', you may want to run 'g fetch <remote_name>' to refresh from the server" echo_info "There is no branch called '$1', you may want to run 'g fetch <remote_name>' to refresh from the server"
echo "If you are trying to revert a file, consider 'g undo <file>'" echo_info "If you are trying to revert a file, consider 'g undo <file>'"


6 changes: 4 additions & 2 deletions cmds/g2-continue.sh
Expand Up @@ -4,13 +4,15 @@
# Unlike git, it detects what needs to be resumed: rebase or merge # Unlike git, it detects what needs to be resumed: rebase or merge
# and smartly run the right command # and smartly run the right command


source "$G2_HOME/cmds/color.sh"

state=$("$GIT_EXE" g2brstatus) state=$("$GIT_EXE" g2brstatus)


[[ $state = "rebase" ]] && { [[ $state = "rebase" ]] && {


action="--continue" action="--continue"
if git diff-index --quiet HEAD --; then if git diff-index --quiet HEAD --; then
echo "The last commit brings no significant changes -- skipping" echo_info "The last commit brings no significant changes -- skipping"
action="--skip" action="--skip"
fi fi


Expand All @@ -21,5 +23,5 @@ state=$("$GIT_EXE" g2brstatus)
[[ $state = "merge" ]] && { [[ $state = "merge" ]] && {
# Count the number of unmerged files # Count the number of unmerged files
count=$("$GIT_EXE" ls-files --unmerged | wc -l) count=$("$GIT_EXE" ls-files --unmerged | wc -l)
[[ $count -ne 0 ]] && echo "I am afraid you still have unmerged files, please run <g mt> to resolv conflicts" ||"$GIT_EXE" commit [[ $count -ne 0 ]] && echo_fatal "I am afraid you still have unmerged files, please run <g mt> to resolve conflicts" ||"$GIT_EXE" commit
} }
4 changes: 3 additions & 1 deletion cmds/g2-cp.sh
Expand Up @@ -2,5 +2,7 @@
# #
# Cherry picking, but forbids anything on top of wip commit # Cherry picking, but forbids anything on top of wip commit


[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: Cherry Picking on a WIP commit is forbiden, please <unwip> and commit <ci>" && exit 1 source "$G2_HOME/cmds/color.sh"

[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: Cherry Picking on a WIP commit is forbiden, please <unwip> and commit <ci>" && exit 1
"$GIT_EXE" cherry-pick "$@" "$GIT_EXE" cherry-pick "$@"
4 changes: 2 additions & 2 deletions cmds/g2-g2add.sh
@@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
# #

source "$G2_HOME/cmds/color.sh"
echo "You don't <add> with G2, you <freeze> and <unfreeze>" echo_fatal "Don't use <add> with G2, <freeze> and <unfreeze> are powerfull commands"
5 changes: 4 additions & 1 deletion cmds/g2-g2am.sh
@@ -1,8 +1,11 @@
#!/bin/bash #!/bin/bash
# #


source "$G2_HOME/cmds/color.sh"


error() { error() {
echo $1 echo_fatal $1
exit 1 exit 1
} }


Expand Down
4 changes: 3 additions & 1 deletion cmds/g2-g2brstatus.sh
Expand Up @@ -2,9 +2,11 @@
# #
# Internal command that return "rebase", "merge" or "false" # Internal command that return "rebase", "merge" or "false"


source "$G2_HOME/cmds/color.sh"

GDIR=$("$GIT_EXE" rev-parse --git-dir 2> /dev/null) GDIR=$("$GIT_EXE" rev-parse --git-dir 2> /dev/null)


[[ ! $GDIR ]] && echo "fatal: Not a Git Repository" && exit 1 [[ ! $GDIR ]] && echo_fatal "fatal: Not a Git Repository" && exit 1
[[ -d "$GDIR/rebase-merge" || -d "$GDIR/rebase-apply" ]] && echo "rebase" && exit 0 [[ -d "$GDIR/rebase-merge" || -d "$GDIR/rebase-apply" ]] && echo "rebase" && exit 0
[[ -f "$GDIR/MERGE_HEAD" ]] && echo "merge" && exit 0 [[ -f "$GDIR/MERGE_HEAD" ]] && echo "merge" && exit 0
echo "false" echo "false"
4 changes: 3 additions & 1 deletion cmds/g2-g2help.sh
@@ -1,7 +1,9 @@
#!/bin/bash #!/bin/bash
# #


echo "You can find all necessary help at http://orefalo.github.com/g2 & http://www.github.com/orefalo/g2" source "$G2_HOME/cmds/color.sh"

echo -e "You can find all necessary help at ${boldon}http://orefalo.github.com/g2${boldoff} & ${boldon}http://www.github.com/orefalo/g2${reset}"


if [ $(uname -s) = "Darwin" ]; then if [ $(uname -s) = "Darwin" ]; then
open "http://orefalo.github.com/g2" open "http://orefalo.github.com/g2"
Expand Down
2 changes: 1 addition & 1 deletion cmds/g2-panic.sh
@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# #


read -p "Remove all un-tracked files and checkout HEAD, are you sure (y/n)? " -n 1 -r read -p "This action will discard all work in progress and checkout HEAD, are you sure (y/n)? " -n 1 -r
[[ $REPLY == [yY]* ]] && { [[ $REPLY == [yY]* ]] && {
echo echo
"$GIT_EXE" abort "$GIT_EXE" abort
Expand Down
4 changes: 3 additions & 1 deletion cmds/g2-rb.sh
@@ -1,14 +1,16 @@
#!/bin/bash #!/bin/bash
# #


source "$G2_HOME/cmds/color.sh"

# substitute "upstream" with real upstream name # substitute "upstream" with real upstream name
declare -a v=("$@") declare -a v=("$@")
declare i=0 declare i=0
for a in "${v[@]}" for a in "${v[@]}"
do do
[[ "$a" = "upstream" ]] && { [[ "$a" = "upstream" ]] && {
remote=$("$GIT_EXE" g2getremote) remote=$("$GIT_EXE" g2getremote)
[[ -z $remote ]] && echo "fatal: upstream not found, please setup tracking for this branch, ie. <g track remote/branch>" && exit 1 [[ -z $remote ]] && echo_fatal "fatal: upstream not found, please setup tracking for this branch, ie. <g track remote/branch>" && exit 1
set -- "${@:1:$i}" "origin/master" "${@:($i+2)}"; set -- "${@:1:$i}" "origin/master" "${@:($i+2)}";
} && break } && break
let i++ let i++
Expand Down
8 changes: 5 additions & 3 deletions cmds/g2-undo.sh
Expand Up @@ -2,9 +2,11 @@
# #
# easy undo a file, a commit or a merge # easy undo a file, a commit or a merge


source "$G2_HOME/cmds/color.sh"

if [ $# -lt 1 ] if [ $# -lt 1 ]
then then
echo "Usage : g undo <file|commit|merge> <?path>" echo_info "Usage : g undo <file|commit|merge> <?path>"
exit exit
fi fi


Expand All @@ -16,12 +18,12 @@ case "$1" in


"commit") "commit")
#TODO: Validate local commits #TODO: Validate local commits
echo "Undoing last commit and reverting changes to the staging area." echo_info "Undoing last commit and reverting changes to the staging area."
"$GIT_EXE" reset --soft HEAD^ "$GIT_EXE" reset --soft HEAD^
;; ;;
"merge") "merge")
#TODO: Validate local commits #TODO: Validate local commits
echo "Reverting back prior to the last merge." echo_info "Reverting back prior to the last merge."
"$GIT_EXE" reset --hard ORIG_HEAD "$GIT_EXE" reset --hard ORIG_HEAD
;; ;;
*) *)
Expand Down
4 changes: 3 additions & 1 deletion cmds/g2-unfreeze.sh
@@ -1,7 +1,9 @@
#!/bin/bash #!/bin/bash
# #


([[ -z "$@" ]] && ("$GIT_EXE" reset -q HEAD > /dev/null || echo "fatal: first commit must be unfrozen file by file.") || ("$GIT_EXE" reset -q HEAD -- $@ > /dev/null || "$GIT_EXE" rm -q --cached $@)) source "$G2_HOME/cmds/color.sh"

([[ -z "$@" ]] && ("$GIT_EXE" reset -q HEAD > /dev/null || echo_fatal "fatal: first commit must be unfrozen file by file.") || ("$GIT_EXE" reset -q HEAD -- $@ > /dev/null || "$GIT_EXE" rm -q --cached $@))


"$GIT_EXE" status -s; "$GIT_EXE" status -s;


3 changes: 2 additions & 1 deletion cmds/g2-unwip.sh
@@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
# #
source "$G2_HOME/cmds/color.sh"


[[ $("$GIT_EXE" g2iswip) = "false" ]] && echo "fatal: there is nothing to <unwip>..." || ("$GIT_EXE" log -n 1 | grep -q -c wip && "$GIT_EXE" reset HEAD~1) [[ $("$GIT_EXE" g2iswip) = "false" ]] && echo_fatal "fatal: there is nothing to <unwip>..." || ("$GIT_EXE" log -n 1 | grep -q -c wip && "$GIT_EXE" reset HEAD~1)
3 changes: 2 additions & 1 deletion cmds/g2-wip.sh
@@ -1,8 +1,9 @@
#!/bin/bash #!/bin/bash
# #
source "$G2_HOME/cmds/color.sh"


if [[ $("$GIT_EXE" g2iswip) = "true" ]]; then if [[ $("$GIT_EXE" g2iswip) = "true" ]]; then
echo "info: amending previous wip commit..." echo_info "info: amending previous wip commit..."
"$GIT_EXE" g2am "$GIT_EXE" g2am
else else
"$GIT_EXE" freeze -m wip "$GIT_EXE" freeze -m wip
Expand Down

0 comments on commit 42752eb

Please sign in to comment.