Skip to content

Commit

Permalink
many coloring changes and enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Refalo committed Mar 3, 2013
1 parent c2e2284 commit c21d177
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 74 deletions.
6 changes: 6 additions & 0 deletions cmds/color.sh
Expand Up @@ -23,4 +23,10 @@ g2_initializeANSI
echo_fatal() echo_fatal()
{ {
echo -e "${redf}$1${reset}"; echo -e "${redf}$1${reset}";
}


echo_info()
{
echo -e "${boldon}$1${reset}";
} }
6 changes: 5 additions & 1 deletion cmds/g2-g2help.sh
@@ -1,4 +1,8 @@
#!/bin/bash #!/bin/bash
# #


echo "You can find all necessary help at http://orefalo.github.com/g2 & http://www.github.com/orefalo/g2" echo "You can find all necessary help at http://orefalo.github.com/g2 & http://www.github.com/orefalo/g2"

if [ $(uname -s) = "Darwin" ]; then
open "http://orefalo.github.com/g2"
fi
17 changes: 12 additions & 5 deletions cmds/g2-g2pull.sh
@@ -1,19 +1,26 @@
#!/bin/bash #!/bin/bash
# #


source "$G2_HOME/cmds/color.sh"

error() { error() {
echo "fatal: use <sync> to synchronize the current branch" echo_fatal "fatal: use <sync> to synchronize the current branch"
echo "remember, <sync>hing applies to the working branch, <pull>ing applies when merging feature branches." echo_info "remember, <sync>hing applies to the working branch, <pull>ing applies when merging feature branches."
exit 1
}

usage() {
echo_fatal "Usage: pull <?opts> <remote> <branch>"
exit 1 exit 1
} }


n=$#; n=$#;
[[ $n -eq 0 || ${!n} = -* ]] && error [[ $n -eq 0 || ${!n} = -* ]] && error
[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: pulling on a wip commit is forbidden, please <unwip> and commit <ci>" && exit 1 [[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: pulling on a wip commit is forbidden, please <unwip> and commit <ci>" && exit 1
[[ ${!n} = */* ]] && echo "Usage: pull <?opts> <remote> <branch>" && exit 1 [[ ${!n} = */* ]] && usage
branch=${!n} branch=${!n}
let n-- let n--
[[ n -gt 0 && ${!n} != -* ]] && rmt=${!n} || { echo "Usage: pull <remote> <branch>" && exit 1; } [[ n -gt 0 && ${!n} != -* ]] && rmt=${!n} || usage
to="$rmt/$branch" to="$rmt/$branch"
remote=$("$GIT_EXE" g2getremote) remote=$("$GIT_EXE" g2getremote)
if [[ -z $remote ]]; then if [[ -z $remote ]]; then
Expand Down
15 changes: 11 additions & 4 deletions cmds/g2-g2push.sh
Expand Up @@ -4,8 +4,15 @@
# forbids wip commits from being pushed # forbids wip commits from being pushed
# forbids push to the working branch # forbids push to the working branch


source "$G2_HOME/cmds/color.sh"

error() { error() {
echo "fatal: sorry you can't use <push> in this context, please use the <sync> command to synchronize the current branch" echo_fatal "fatal: sorry you can't use <push> in this context, please use the <sync> command to synchronize the current branch"
exit 1
}

usage() {
echo_fatal "Usage: push <?opts> <remote> <branch>"
exit 1 exit 1
} }


Expand All @@ -24,7 +31,7 @@ hasFFlag() {
fflg=$( hasFFlag "$@" ) fflg=$( hasFFlag "$@" )
n=$#; n=$#;
[[ $fflg = "false" && $n -eq 0 ]] && error [[ $fflg = "false" && $n -eq 0 ]] && error
[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: pushing a wip commit is forbiden, please <unwip> and commit <ci>" && exit 1 [[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: pushing a wip commit is forbiden, please <unwip> and commit <ci>" && exit 1
[[ $fflg = "true" ]] && { [[ $fflg = "true" ]] && {
read -p "warning: you are about to force push history, please confirm (y/n)? " -n 1 -r; read -p "warning: you are about to force push history, please confirm (y/n)? " -n 1 -r;
echo echo
Expand All @@ -33,10 +40,10 @@ n=$#;
} }


branch=${!n} branch=${!n}
[[ $branch = */* ]] && echo "Usage: push <?opts> <remote> <branch>" && exit 1 [[ $branch = */* ]] && usage


let n-- let n--
[[ $n -gt 0 && ${!n} != -* ]] && rmt=${!n} || { echo "Usage: push <?opts> <remote> <branch>" && exit 1; } [[ $n -gt 0 && ${!n} != -* ]] && rmt=${!n} || usage
to="$rmt/$branch" to="$rmt/$branch"
remote=$("$GIT_EXE" g2getremote) remote=$("$GIT_EXE" g2getremote)
if [[ -z $remote ]]; then if [[ -z $remote ]]; then
Expand Down
14 changes: 12 additions & 2 deletions cmds/g2-key.sh
@@ -1,16 +1,26 @@
#!/bin/bash #!/bin/bash
# #


source "$G2_HOME/cmds/color.sh"

displayKey() {

echo -e -n "${yellowf}"
cat "$HOME/.ssh/id_rsa.pub"
echo -e -n "${reset}"

}

gen() { gen() {
echo "Generating SSH keys..." echo "Generating SSH keys..."
emailinput=$("$GIT_EXE" config --global --get user.email) emailinput=$("$GIT_EXE" config --global --get user.email)
ssh-keygen -t rsa -P "" -C "$emailinput" -f "$HOME/.ssh/id_rsa" ssh-keygen -t rsa -P "" -C "$emailinput" -f "$HOME/.ssh/id_rsa"
cat "$HOME/.ssh/id_rsa.pub" displayKey
} }




if [[ $1 != -gen ]]; then if [[ $1 != -gen ]]; then
[[ ! -f $HOME/.ssh/id_rsa.pub ]] && echo "fatal: SSH key not found: $HOME/.ssh/id_rsa.pub" || cat "$HOME/.ssh/id_rsa.pub" [[ ! -f $HOME/.ssh/id_rsa.pub ]] && echo_fatal "fatal: SSH key not found: $HOME/.ssh/id_rsa.pub" || displayKey
else else
if [[ -f $HOME/.ssh/id_rsa.pub ]]; then if [[ -f $HOME/.ssh/id_rsa.pub ]]; then
read -p "Regenerate SSH Key (y/n)? " -n 1 -r read -p "Regenerate SSH Key (y/n)? " -n 1 -r
Expand Down
12 changes: 7 additions & 5 deletions cmds/g2-mg.sh
@@ -1,7 +1,9 @@
#!/bin/bash #!/bin/bash
# #


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

[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: merging on a wip commit is forbiden, please <unwip> and commit <ci> first..." && exit 1


# substitute "upstream" with real upstream name # substitute "upstream" with real upstream name
declare -a v=("$@") declare -a v=("$@")
Expand All @@ -10,7 +12,7 @@ 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 All @@ -23,9 +25,9 @@ done


unmerged=$("$GIT_EXE" ls-files --unmerged) unmerged=$("$GIT_EXE" ls-files --unmerged)
if [[ -n $unmerged ]]; then if [[ -n $unmerged ]]; then
echo "info: some files need to be merged manually, please use <mt> to fix conflicts..." echo_info "info: some files need to be merged manually, please use <mt> to fix conflicts..."
echo " once all resolved, <freeze> and <commit> the files." echo_info " once all resolved, <freeze> and <commit> the files."
echo " note that you may <abort> at any time." echo_info " note that you may <abort> at any time."
fi fi
exit 1; exit 1;
} }
21 changes: 12 additions & 9 deletions cmds/g2-sync.sh
Expand Up @@ -2,19 +2,22 @@
# #
# Performs a fetch, rebase, push with a bunch of validations # Performs a fetch, rebase, push with a bunch of validations
# #

source "$G2_HOME/cmds/color.sh"

[[ $1 == "upstream" ]] && pullOnly=true && shift [[ $1 == "upstream" ]] && pullOnly=true && shift


[[ $# -gt 0 ]] && echo "Usage: <sync>" && echo "Remember, <sync>hing applies to the working branch, when <pull>ing applies when merging feature branches" && exit 1 [[ $# -gt 0 ]] && echo_fatal "Usage: <sync>" && echo_fatal "Remember, <sync>hing applies to the working branch, when <pull>ing applies when merging feature branches" && exit 1


remote=$("$GIT_EXE" g2getremote) remote=$("$GIT_EXE" g2getremote)


[[ $("$GIT_EXE" g2iswip $remote) = "true" ]] && echo "fatal: sorry, wip commits shall not be synced. Please <unwip>, then <freeze> & commit <ci>" && exit 1; [[ $("$GIT_EXE" g2iswip $remote) = "true" ]] && echo_fatal "fatal: sorry, wip commits shall not be synced. Please <unwip>, then <freeze> & commit <ci>" && exit 1;
[[ -z $remote ]] && echo "fatal: please use <track> to setup the remote/branch to track with" && exit 2 [[ -z $remote ]] && echo_fatal "fatal: please use <track> to setup the remote/branch to track with" && exit 2
[[ $# -ne 0 ]] && echo "fatal: sorry, you may only <sync> against the tracking remote/branch, use <pull> or <push> to deal with other branches." && exit 3 [[ $# -ne 0 ]] && echo_fatal "fatal: sorry, you may only <sync> against the tracking remote/branch, use <pull> or <push> to deal with other branches." && exit 3
"$GIT_EXE" fetch || exit $?; "$GIT_EXE" fetch || exit $?;
[[ $("$GIT_EXE" g2isforced $remote) = "true" ]] && [[ $("$GIT_EXE" g2isforced $remote) = "true" ]] &&
echo "abort: it appears the history of the branch was changed on the server." && echo_fatal "abort: it appears the history of the branch was changed on the server." &&
echo " please issue a <g rs upstream> or a <g rb $remote> to resume" && echo_fatal " please issue a <g rs upstream> or a <g rb $remote> to resume" &&
exit 1; exit 1;
branch=$("$GIT_EXE" branch | grep "*" | sed "s/* //") branch=$("$GIT_EXE" branch | grep "*" | sed "s/* //")
"$GIT_EXE" rev-list --left-right $branch...$remote -- 2> /dev/null > /tmp/git_upstream_status_delta "$GIT_EXE" rev-list --left-right $branch...$remote -- 2> /dev/null > /tmp/git_upstream_status_delta
Expand All @@ -23,9 +26,9 @@ rchg=$(grep -c "^>" /tmp/git_upstream_status_delta);
[[ $rchg -gt 0 ]] && { "$GIT_EXE" rebase $remote || { [[ $rchg -gt 0 ]] && { "$GIT_EXE" rebase $remote || {
unmerged=$("$GIT_EXE" ls-files --unmerged) unmerged=$("$GIT_EXE" ls-files --unmerged)
if [[ -n $unmerged ]]; then if [[ -n $unmerged ]]; then
echo "info: some files need to be merged manually, please use <g mt> to fix conflicts." echo_info "info: some files need to be merged manually, please use <g mt> to fix conflicts."
echo " Once all resolved, do NOT commit, but use <g continue> to resume." echo_info " Once all resolved, do NOT commit, but use <g continue> to resume."
echo " Note that you may <abort> at any time" echo_info " Note that you may <abort> at any time"
fi fi
exit 1; exit 1;
} }
Expand Down
9 changes: 5 additions & 4 deletions g2-install.sh
Expand Up @@ -15,8 +15,8 @@ export G2_HOME=$DIR
source ./cmds/color.sh source ./cmds/color.sh


tips=( tips=(
"${italicson}g sync${italicsoff} adds your changes to the tip of the branch and synchronizes with the servers both ways." "${boldon}g sync${boldoff} adds your changes to the tip of the branch and synchronizes with the servers both ways."
"${italicson}g freeze${italicsoff} is a handy command to litteraly freeze the state of the repository." "${boldon}g freeze${boldoff} is a handy command to freeze all the changes in one shot."
"${boldon}g2${boldoff} saves time by providing high level commands." "${boldon}g2${boldoff} saves time by providing high level commands."
"${boldon}g2${boldoff} is safer than git as it prompts before destructive actions." "${boldon}g2${boldoff} is safer than git as it prompts before destructive actions."
"run ${boldon}g setup${boldoff} to configure git." "run ${boldon}g setup${boldoff} to configure git."
Expand All @@ -34,7 +34,8 @@ tips=(
"Need to display your ssh public key? try ${boldon}g key${boldoff}." "Need to display your ssh public key? try ${boldon}g key${boldoff}."
"${boldon}g2${boldoff} is just easier at undoing things: try ${boldon}g undo commit${boldoff} or ${boldon}g undo merge${boldoff}." "${boldon}g2${boldoff} is just easier at undoing things: try ${boldon}g undo commit${boldoff} or ${boldon}g undo merge${boldoff}."
"When lost, ${boldon}g panic${boldoff} is the easiest way to get you back on track." "When lost, ${boldon}g panic${boldoff} is the easiest way to get you back on track."
); "Use ${boldon}g track${boldoff} to review how local/remote branches are setup."
"Unlike git, ${boldon}g2${boldoff} actions only apply to the current branch.");


echo -n -e "Installing ${boldon}G2${boldoff}.." echo -n -e "Installing ${boldon}G2${boldoff}.."


Expand All @@ -51,7 +52,7 @@ alias git=__g2_eval;


echo " Enjoy!" echo " Enjoy!"


echo -e "${boldon}Tip of the day${boldoff} : ${tips[RANDOM % ${#tips[@]}]} ${reset}" echo -e "${boldon}Tip of the day${boldoff}: ${tips[RANDOM % ${#tips[@]}]} ${reset}"




cd $OLDpwd cd $OLDpwd
89 changes: 45 additions & 44 deletions g2.sh
Expand Up @@ -14,6 +14,8 @@ GIT_EXE=$(which git)
[[ -z "$GIT_EXE" ]] && echo "Sorry git not found in the PATH"; [[ -z "$GIT_EXE" ]] && echo "Sorry git not found in the PATH";
export GIT_EXE export GIT_EXE


source "$G2_HOME/cmds/color.sh"

function __g2_contains() { function __g2_contains() {
local n=$# local n=$#
local value=${!n} local value=${!n}
Expand All @@ -27,50 +29,49 @@ function __g2_contains() {
} }


function __g2_usage() { function __g2_usage() {
cat << EOF echo -e "G2 Usage:
Usage: ${boldon}abort${boldoff} - aborts any rebase/merge
abort - aborts any rebase/merge ${boldon}am <?-f>${boldoff} - amends last commit with staging area
am <?-f> - amends last commit with staging area ${boldon}br <?-D> <?-M> <?branch>${boldoff} - list or create branches
br <?-D> <?-M> <?branch> - list or create branches ${boldon}bs${boldoff} - bisect
bs - bisect ${boldon}co <branch>${boldoff} - switches branch (either local/remote)
co <branch> - switches branch (either local/remote) ${boldon}continue${boldoff} - resumes a conflict resolution
continue - resumes a conflict resolution ${boldon}cp <commit>${boldoff} - cherry-pick
cp <commit> - cherry-pick ${boldon}ci <?params...>${boldoff} - commit
ci <?params...> - commit ${boldon}clone <url>${boldoff} - clone a remote repository
clone <url> - clone a remote repository ${boldon}df/dt <?params...> <file>${boldoff} - compares files
df/dt <?params...> <file> - compares files ${boldon}fetch${boldoff} - gets changes sitting on the server
fetch - synchronizes remote branches ${boldon}freeze/unfreeze <?-m comment> <?file>${boldoff} - freeze/unfreeze files
freeze/unfreeze <?-m comment> <?file> - freeze/unfreeze files ${boldon}gc${boldoff} - garbage collects: run fsck & gc
gc - garbage collects: run fsck & gc ${boldon}gp${boldoff} - grep
gp - grep ${boldon}gui${boldoff} - launches the GUI
gui - launches the GUI ${boldon}ig <file>${boldoff} - adds to gitignore & removes from source control
ig <file> - adds to gitignore & removes from source control ${boldon}init <folder>${boldoff} - init a repository
init <folder> - init a repository ${boldon}key <?-gen>${boldoff} - displays/generates your ssh public key
key <?-gen> - displays/generates your ssh public key ${boldon}mg <?params...> <branch>${boldoff} - merge
mg <?params...> <branch> - merge ${boldon}mt <?params...>${boldoff} - fixes conflicts by opening a visual mergetool
mt <?params...> - fixes conflicts by opening a visual mergetool ${boldon}mv${boldoff} - move (rename) a file
mv - move (rename) a file ${boldon}lg${boldoff} - displays commit log
lg - displays commit log ${boldon}ls <?params...>${boldoff} - list files under source control
ls <?params...> - list files under source control ${boldon}panic${boldoff} - gets you back on HEAD, cleans all untracked files
panic - gets you back on HEAD, cleans all untracked files ${boldon}pull/push <?opts> <remote> <branch>${boldoff} - deals with other branches
pull/push <?opts> <remote> <branch> - deals with other branches ${boldon}rb <?params...> <branch> or <upstream>${boldoff} - rebase
rb <?params...> <branch> or <upstream> - rebase ${boldon}rm <params...>${boldoff} - remove files
rm <params...> - remove ${boldon}rs <params...>${boldoff} - reset branch status
rs <params...> - reset ${boldon}rs upstream${boldoff} - resets branch to upstream state
rs upstream - resets branch to upstream state ${boldon}rt <?params...>${boldoff} - remote management
rt <?params...> - remote ${boldon}rv <commit>${boldoff} - reverts commits
rv <commit> - revert ${boldon}setup${boldoff} - configures user, key, editor, tools
setup - configures user, key, editor, tools ${boldon}sh <?-deep>${boldoff} - show commit contents
sh <?-deep> - show commit contents ${boldon}sm <?params...>${boldoff} - submodule
sm <?params...> - submodule ${boldon}ss <?params>${boldoff} - stash
ss <?params> - stash ${boldon}st <?params...>${boldoff} - status
st <?params...> - status ${boldon}sync <?upstream>${boldoff} - syncs working branch: fetch, rebase & push
sync <?upstream> - syncs working branch: fetch, rebase & push ${boldon}tg${boldoff} - tag
tg - tag ${boldon}track <?upstream_branch>${boldoff} - shows/set tracking
track <?upstream_branch> - shows/set tracking ${boldon}undo <file>|commit <hash>|merge${boldoff} - reverts changes
undo <file>|commit <hash>|merge - reverts changes ${boldon}wip/unwip${boldoff} - save/restore work in progress to branch"
wip/unwip - save/restore work in progress to branch
EOF
return 0; return 0;
} }


Expand Down

0 comments on commit c21d177

Please sign in to comment.