diff --git a/cmds/color.sh b/cmds/color.sh index d0bc4a38..7ae3d553 100755 --- a/cmds/color.sh +++ b/cmds/color.sh @@ -23,4 +23,10 @@ g2_initializeANSI echo_fatal() { echo -e "${redf}$1${reset}"; +} + + +echo_info() +{ +echo -e "${boldon}$1${reset}"; } \ No newline at end of file diff --git a/cmds/g2-g2help.sh b/cmds/g2-g2help.sh index 4571dc4d..c82d01f6 100755 --- a/cmds/g2-g2help.sh +++ b/cmds/g2-g2help.sh @@ -1,4 +1,8 @@ #!/bin/bash # -echo "You can find all necessary help at http://orefalo.github.com/g2 & http://www.github.com/orefalo/g2" \ No newline at end of file +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 \ No newline at end of file diff --git a/cmds/g2-g2pull.sh b/cmds/g2-g2pull.sh index fffecc93..1ec0fb4d 100755 --- a/cmds/g2-g2pull.sh +++ b/cmds/g2-g2pull.sh @@ -1,19 +1,26 @@ #!/bin/bash # +source "$G2_HOME/cmds/color.sh" + error() { - echo "fatal: use to synchronize the current branch" - echo "remember, hing applies to the working branch, ing applies when merging feature branches." + echo_fatal "fatal: use to synchronize the current branch" + echo_info "remember, hing applies to the working branch, ing applies when merging feature branches." + exit 1 +} + +usage() { + echo_fatal "Usage: pull " exit 1 } n=$#; [[ $n -eq 0 || ${!n} = -* ]] && error -[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: pulling on a wip commit is forbidden, please and commit " && exit 1 -[[ ${!n} = */* ]] && echo "Usage: pull " && exit 1 +[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: pulling on a wip commit is forbidden, please and commit " && exit 1 +[[ ${!n} = */* ]] && usage branch=${!n} let n-- -[[ n -gt 0 && ${!n} != -* ]] && rmt=${!n} || { echo "Usage: pull " && exit 1; } +[[ n -gt 0 && ${!n} != -* ]] && rmt=${!n} || usage to="$rmt/$branch" remote=$("$GIT_EXE" g2getremote) if [[ -z $remote ]]; then diff --git a/cmds/g2-g2push.sh b/cmds/g2-g2push.sh index 537ba47c..36dfa584 100755 --- a/cmds/g2-g2push.sh +++ b/cmds/g2-g2push.sh @@ -4,8 +4,15 @@ # forbids wip commits from being pushed # forbids push to the working branch +source "$G2_HOME/cmds/color.sh" + error() { - echo "fatal: sorry you can't use in this context, please use the command to synchronize the current branch" + echo_fatal "fatal: sorry you can't use in this context, please use the command to synchronize the current branch" + exit 1 +} + +usage() { + echo_fatal "Usage: push " exit 1 } @@ -24,7 +31,7 @@ hasFFlag() { fflg=$( hasFFlag "$@" ) n=$#; [[ $fflg = "false" && $n -eq 0 ]] && error -[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: pushing a wip commit is forbiden, please and commit " && exit 1 +[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: pushing a wip commit is forbiden, please and commit " && exit 1 [[ $fflg = "true" ]] && { read -p "warning: you are about to force push history, please confirm (y/n)? " -n 1 -r; echo @@ -33,10 +40,10 @@ n=$#; } branch=${!n} -[[ $branch = */* ]] && echo "Usage: push " && exit 1 +[[ $branch = */* ]] && usage let n-- -[[ $n -gt 0 && ${!n} != -* ]] && rmt=${!n} || { echo "Usage: push " && exit 1; } +[[ $n -gt 0 && ${!n} != -* ]] && rmt=${!n} || usage to="$rmt/$branch" remote=$("$GIT_EXE" g2getremote) if [[ -z $remote ]]; then diff --git a/cmds/g2-key.sh b/cmds/g2-key.sh index cb352864..c4988bcd 100755 --- a/cmds/g2-key.sh +++ b/cmds/g2-key.sh @@ -1,16 +1,26 @@ #!/bin/bash # +source "$G2_HOME/cmds/color.sh" + +displayKey() { + + echo -e -n "${yellowf}" + cat "$HOME/.ssh/id_rsa.pub" + echo -e -n "${reset}" + +} + gen() { echo "Generating SSH keys..." emailinput=$("$GIT_EXE" config --global --get user.email) ssh-keygen -t rsa -P "" -C "$emailinput" -f "$HOME/.ssh/id_rsa" - cat "$HOME/.ssh/id_rsa.pub" + displayKey } 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 if [[ -f $HOME/.ssh/id_rsa.pub ]]; then read -p "Regenerate SSH Key (y/n)? " -n 1 -r diff --git a/cmds/g2-mg.sh b/cmds/g2-mg.sh index 1582cab9..e0eecc5f 100755 --- a/cmds/g2-mg.sh +++ b/cmds/g2-mg.sh @@ -1,7 +1,9 @@ #!/bin/bash # -[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: merging on a wip commit is forbiden, please and commit first..." && exit 1 +source "$G2_HOME/cmds/color.sh" + +[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: merging on a wip commit is forbiden, please and commit first..." && exit 1 # substitute "upstream" with real upstream name declare -a v=("$@") @@ -10,7 +12,7 @@ for a in "${v[@]}" do [[ "$a" = "upstream" ]] && { remote=$("$GIT_EXE" g2getremote) - [[ -z $remote ]] && echo "fatal: upstream not found, please setup tracking for this branch, ie. " && exit 1 + [[ -z $remote ]] && echo_fatal "fatal: upstream not found, please setup tracking for this branch, ie. " && exit 1 set -- "${@:1:$i}" "origin/master" "${@:($i+2)}"; } && break let i++ @@ -23,9 +25,9 @@ done unmerged=$("$GIT_EXE" ls-files --unmerged) if [[ -n $unmerged ]]; then - echo "info: some files need to be merged manually, please use to fix conflicts..." - echo " once all resolved, and the files." - echo " note that you may at any time." + echo_info "info: some files need to be merged manually, please use to fix conflicts..." + echo_info " once all resolved, and the files." + echo_info " note that you may at any time." fi exit 1; } diff --git a/cmds/g2-sync.sh b/cmds/g2-sync.sh index fd2dca6f..c0a2c7c0 100755 --- a/cmds/g2-sync.sh +++ b/cmds/g2-sync.sh @@ -2,19 +2,22 @@ # # Performs a fetch, rebase, push with a bunch of validations # + +source "$G2_HOME/cmds/color.sh" + [[ $1 == "upstream" ]] && pullOnly=true && shift -[[ $# -gt 0 ]] && echo "Usage: " && echo "Remember, hing applies to the working branch, when ing applies when merging feature branches" && exit 1 +[[ $# -gt 0 ]] && echo_fatal "Usage: " && echo_fatal "Remember, hing applies to the working branch, when ing applies when merging feature branches" && exit 1 remote=$("$GIT_EXE" g2getremote) -[[ $("$GIT_EXE" g2iswip $remote) = "true" ]] && echo "fatal: sorry, wip commits shall not be synced. Please , then & commit " && exit 1; -[[ -z $remote ]] && echo "fatal: please use to setup the remote/branch to track with" && exit 2 -[[ $# -ne 0 ]] && echo "fatal: sorry, you may only against the tracking remote/branch, use or to deal with other branches." && exit 3 +[[ $("$GIT_EXE" g2iswip $remote) = "true" ]] && echo_fatal "fatal: sorry, wip commits shall not be synced. Please , then & commit " && exit 1; +[[ -z $remote ]] && echo_fatal "fatal: please use to setup the remote/branch to track with" && exit 2 +[[ $# -ne 0 ]] && echo_fatal "fatal: sorry, you may only against the tracking remote/branch, use or to deal with other branches." && exit 3 "$GIT_EXE" fetch || exit $?; [[ $("$GIT_EXE" g2isforced $remote) = "true" ]] && - echo "abort: it appears the history of the branch was changed on the server." && - echo " please issue a or a to resume" && + echo_fatal "abort: it appears the history of the branch was changed on the server." && + echo_fatal " please issue a or a to resume" && exit 1; branch=$("$GIT_EXE" branch | grep "*" | sed "s/* //") "$GIT_EXE" rev-list --left-right $branch...$remote -- 2> /dev/null > /tmp/git_upstream_status_delta @@ -23,9 +26,9 @@ rchg=$(grep -c "^>" /tmp/git_upstream_status_delta); [[ $rchg -gt 0 ]] && { "$GIT_EXE" rebase $remote || { unmerged=$("$GIT_EXE" ls-files --unmerged) if [[ -n $unmerged ]]; then - echo "info: some files need to be merged manually, please use to fix conflicts." - echo " Once all resolved, do NOT commit, but use to resume." - echo " Note that you may at any time" + echo_info "info: some files need to be merged manually, please use to fix conflicts." + echo_info " Once all resolved, do NOT commit, but use to resume." + echo_info " Note that you may at any time" fi exit 1; } diff --git a/g2-install.sh b/g2-install.sh index 9c523963..4c123b45 100755 --- a/g2-install.sh +++ b/g2-install.sh @@ -15,8 +15,8 @@ export G2_HOME=$DIR source ./cmds/color.sh tips=( -"${italicson}g sync${italicsoff} 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 sync${boldoff} adds your changes to the tip of the branch and synchronizes with the servers both ways." +"${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} is safer than git as it prompts before destructive actions." "run ${boldon}g setup${boldoff} to configure git." @@ -34,7 +34,8 @@ tips=( "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}." "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}.." @@ -51,7 +52,7 @@ alias git=__g2_eval; 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 diff --git a/g2.sh b/g2.sh index 7eaca6e9..dbe47e0b 100644 --- a/g2.sh +++ b/g2.sh @@ -14,6 +14,8 @@ GIT_EXE=$(which git) [[ -z "$GIT_EXE" ]] && echo "Sorry git not found in the PATH"; export GIT_EXE +source "$G2_HOME/cmds/color.sh" + function __g2_contains() { local n=$# local value=${!n} @@ -27,50 +29,49 @@ function __g2_contains() { } function __g2_usage() { - cat << EOF -Usage: - abort - aborts any rebase/merge - am - amends last commit with staging area - br - list or create branches - bs - bisect - co - switches branch (either local/remote) - continue - resumes a conflict resolution - cp - cherry-pick - ci - commit - clone - clone a remote repository - df/dt - compares files - fetch - synchronizes remote branches - freeze/unfreeze - freeze/unfreeze files - gc - garbage collects: run fsck & gc - gp - grep - gui - launches the GUI - ig - adds to gitignore & removes from source control - init - init a repository - key - displays/generates your ssh public key - mg - merge - mt - fixes conflicts by opening a visual mergetool - mv - move (rename) a file - lg - displays commit log - ls - list files under source control - panic - gets you back on HEAD, cleans all untracked files - pull/push - deals with other branches - rb or - rebase - rm - remove - rs - reset - rs upstream - resets branch to upstream state - rt - remote - rv - revert - setup - configures user, key, editor, tools - sh - show commit contents - sm - submodule - ss - stash - st - status - sync - syncs working branch: fetch, rebase & push - tg - tag - track - shows/set tracking - undo |commit |merge - reverts changes - wip/unwip - save/restore work in progress to branch -EOF + echo -e "G2 Usage: + ${boldon}abort${boldoff} - aborts any rebase/merge + ${boldon}am ${boldoff} - amends last commit with staging area + ${boldon}br ${boldoff} - list or create branches + ${boldon}bs${boldoff} - bisect + ${boldon}co ${boldoff} - switches branch (either local/remote) + ${boldon}continue${boldoff} - resumes a conflict resolution + ${boldon}cp ${boldoff} - cherry-pick + ${boldon}ci ${boldoff} - commit + ${boldon}clone ${boldoff} - clone a remote repository + ${boldon}df/dt ${boldoff} - compares files + ${boldon}fetch${boldoff} - gets changes sitting on the server + ${boldon}freeze/unfreeze ${boldoff} - freeze/unfreeze files + ${boldon}gc${boldoff} - garbage collects: run fsck & gc + ${boldon}gp${boldoff} - grep + ${boldon}gui${boldoff} - launches the GUI + ${boldon}ig ${boldoff} - adds to gitignore & removes from source control + ${boldon}init ${boldoff} - init a repository + ${boldon}key ${boldoff} - displays/generates your ssh public key + ${boldon}mg ${boldoff} - merge + ${boldon}mt ${boldoff} - fixes conflicts by opening a visual mergetool + ${boldon}mv${boldoff} - move (rename) a file + ${boldon}lg${boldoff} - displays commit log + ${boldon}ls ${boldoff} - list files under source control + ${boldon}panic${boldoff} - gets you back on HEAD, cleans all untracked files + ${boldon}pull/push ${boldoff} - deals with other branches + ${boldon}rb or ${boldoff} - rebase + ${boldon}rm ${boldoff} - remove files + ${boldon}rs ${boldoff} - reset branch status + ${boldon}rs upstream${boldoff} - resets branch to upstream state + ${boldon}rt ${boldoff} - remote management + ${boldon}rv ${boldoff} - reverts commits + ${boldon}setup${boldoff} - configures user, key, editor, tools + ${boldon}sh ${boldoff} - show commit contents + ${boldon}sm ${boldoff} - submodule + ${boldon}ss ${boldoff} - stash + ${boldon}st ${boldoff} - status + ${boldon}sync ${boldoff} - syncs working branch: fetch, rebase & push + ${boldon}tg${boldoff} - tag + ${boldon}track ${boldoff} - shows/set tracking + ${boldon}undo |commit |merge${boldoff} - reverts changes + ${boldon}wip/unwip${boldoff} - save/restore work in progress to branch" + return 0; }