Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rework

  • Loading branch information...
commit 142f5474de74c0ada7b90e26cf070fee2339bf6e 1 parent 42752eb
Olivier Refalo authored
12 cmds/color.sh
View
@@ -6,14 +6,14 @@ g2_initializeANSI()
yellowf="${g2esc}[33m" bluef="${g2esc}[34m"; purplef="${g2esc}[35m";
cyanf="${g2esc}[36m"; whitef="${g2esc}[37m";
- blackb="${g2esc}[40m"; redb="${g2esc}[41m"; greenb="${g2esc}[42m";
- yellowb="${g2esc}[43m" blueb="${g2esc}[44m"; purpleb="${g2esc}[45m";
- cyanb="${g2esc}[46m"; whiteb="${g2esc}[47m";
+# blackb="${g2esc}[40m"; redb="${g2esc}[41m"; greenb="${g2esc}[42m";
+# yellowb="${g2esc}[43m" blueb="${g2esc}[44m"; purpleb="${g2esc}[45m";
+# cyanb="${g2esc}[46m"; whiteb="${g2esc}[47m";
boldon="${g2esc}[1m"; boldoff="${g2esc}[22m";
- italicson="${g2esc}[3m"; italicsoff="${g2esc}[23m";
- ulon="${g2esc}[4m"; uloff="${g2esc}[24m";
- invon="${g2esc}[7m"; invoff="${g2esc}[27m";
+# italicson="${g2esc}[3m"; italicsoff="${g2esc}[23m";
+# ulon="${g2esc}[4m"; uloff="${g2esc}[24m";
+# invon="${g2esc}[7m"; invoff="${g2esc}[27m";
reset="${g2esc}[0m";
}
7 cmds/g2-br.sh
View
@@ -18,11 +18,6 @@ hasDMFlag() {
echo "false"
}
-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 --numstat | wc -l) -ne 0 ]] && echo "fatal: some files were modified, either commit <ci>, <wip> or <panic>." && exit 1
-}
-
br_status() {
"$GIT_EXE" for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \
while read local remote
@@ -44,7 +39,7 @@ else
flag=$(hasDMFlag "$@")
[[ $flag = "exit" ]] && exit 1;
[[ $flag = "true" ]] && { "$GIT_EXE" branch "$@"; exit $?; }
- hasChanges
+ $("$GIT_EXE" g2haschanges) || exit 1;
shift $(( OPTIND - 1 ))
branch="${1:-/}"
2  cmds/g2-ci.sh
View
@@ -3,5 +3,5 @@
#
source "$G2_HOME/cmds/color.sh"
-[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: WIP detected, please <unwip> first." && exit 1
+$("$GIT_EXE" g2iswip) || exit 1
[[ $("$GIT_EXE" diff --cached --numstat | wc -l) -eq 0 ]] && echo_fatal "fatal: No files to commit, please <freeze> changes first." || "$GIT_EXE" commit -u "$@"
9 cmds/g2-co.sh
View
@@ -3,20 +3,15 @@
source "$G2_HOME/cmds/color.sh"
-hasChanges() {
- [[ $("$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 "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 -gt 0 ]] && {
"$GIT_EXE" abort
- hasChanges
+ $("$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 called '$1', you may want to run 'g fetch <remote_name>' to refresh from the server"
+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>'"
2  cmds/g2-continue.sh
View
@@ -12,7 +12,7 @@ state=$("$GIT_EXE" g2brstatus)
action="--continue"
if git diff-index --quiet HEAD --; then
- echo_info "The last commit brings no significant changes -- skipping"
+ echo_info "The last commit brings no significant changes -- automatically skipping"
action="--skip"
fi
4 cmds/g2-cp.sh
View
@@ -2,7 +2,5 @@
#
# Cherry picking, but forbids anything on top of wip commit
-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" g2iswip) || exit 1
"$GIT_EXE" cherry-pick "$@"
11 cmds/g2-freeze.sh
View
@@ -1,12 +1,15 @@
#!/bin/bash
#
-[[ $1 = "-m" ]] && {
- [[ -n $2 ]] && { msg=$2; shift 2; } || { echo "Usage: freeze -m message"; exit 1; }
-}
+source "$G2_HOME/cmds/color.sh"
+
+if [[ $1 = "-m" ]]; then
+ [[ -n $2 ]] && { msg=$2; shift 2; } || { echo_info "Usage: freeze -m message"; exit 1; }
+fi
+
( [[ -z "$@" ]] && "$GIT_EXE" add -A || "$GIT_EXE" add -A "$GIT_PREFIX$@" ) && {
[[ -n $msg ]] && {
- [[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: wip detected, please <unwip> and commit <ci>." && exit 1
+ $("$GIT_EXE" g2iswip) || exit 1
"$GIT_EXE" commit -m "$msg" && "$GIT_EXE" status -s
}
}
33 cmds/g2-g2am.sh
View
@@ -1,30 +1,19 @@
#!/bin/bash
#
-
source "$G2_HOME/cmds/color.sh"
-
-error() {
- echo_fatal $1
- exit 1
-}
-
[[ $("$GIT_EXE" diff --cached --numstat | wc -l) -eq 0 ]] && error "fatal: no files to amend, please <freeze> the changes to amend."
-remote=$("$GIT_EXE" g2getremote)
-if [[ -z $remote ]]; then
- "$GIT_EXE" commit --amend -C HEAD
-else
-
- if [[ $("$GIT_EXE" log $remote..HEAD --oneline | wc -l) -eq 0 ]]; then
-
- if [[ $1 = "-f" ]]; then
- read -p "warning: force amending will rewrite the branch history, please confirm (y/n)? " -n 1 -r
- echo
- [[ $REPLY != [yY]* ]] && exit 1
- else error "fatal: no local commits to amend."; fi
+$("$GIT_EXE" g2haslocalcommit)
+if [[ $? -eq 0 ]]; then
+ if [[ $1 = "-f" ]]; then
+ read -p "Warning: force amending will rewrite the history, please confirm (y/n)? " -n 1 -r
+ echo
+ [[ $REPLY != [yY]* ]] && exit 1
+ else
+ echo_fatal "fatal: no local commits to amend."
+ exit 1
fi
+fi
- "$GIT_EXE" commit --amend -C HEAD
-
-fi
+"$GIT_EXE" commit --amend -C HEAD
2  cmds/g2-g2getremote.sh
View
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# returns the upstream branch if any
+# returns the upstream branch name if any
remote=$("$GIT_EXE" rev-parse --symbolic-full-name --abbrev-ref @{u} 2> /dev/null)
[[ $remote == "@{u}" ]] && echo "" || echo $remote
17 cmds/g2-g2haschanges.sh
View
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# returns 0 if no pending changes, 1 if any (workspace or index)
+
+source "$G2_HOME/cmds/color.sh";
+
+if [[ $("$GIT_EXE" diff --cached --numstat | wc -l) -ne 0 ]]; then
+ echo_fatal "fatal: you have changes in the staging area, please commit them ${boldon}g ci -m mymessage${boldooff} or save them as a work in progress ${boldon}g wip${boldooff}.";
+ exit 1;
+fi
+
+if [[ $("$GIT_EXE" diff --numstat | wc -l) -ne 0 ]]; then
+ echo_fatal "fatal: some files were modified, either commit then ${boldon}g ci -m mymessage${boldooff}, save them as a work in progress ${boldon}g wip${boldooff} or discard them ${boldon}g panic${boldoff}.";
+ exit 1;
+fi
+
+exit 0;
8 cmds/g2-g2haslocalcommit.sh
View
@@ -0,0 +1,8 @@
+#!/bin/bash
+#
+# returns 1 local commits (commit not on the server), 0 if not, 2 no remote
+
+remote=$("$GIT_EXE" g2getremote)
+[[ -z "$remote" ]] && exit 2
+[[ $("$GIT_EXE" log $remote..HEAD --oneline | wc -l) -eq 0 ]] && exit 0
+exit 1
6 cmds/g2-g2isbehind.sh
View
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Returns true if the branch is behind its upstream branch
+# Returns 1 if the branch is behind its upstream branch, 0 if not
local=$("$GIT_EXE" branch | grep "*" | sed "s/* //")
remote=$1
@@ -8,6 +8,6 @@ remote=$1
[[ -n $remote ]] && {
"$GIT_EXE" fetch
RIGHT_AHEAD=$("$GIT_EXE" rev-list --left-right ${local}...${remote} -- 2> /dev/null | grep -c "^>")
- [[ $RIGHT_AHEAD -gt 0 ]] && echo "true" && exit
+ [[ $RIGHT_AHEAD -gt 0 ]] && exit 1;
}
-echo "false"
+exit 0;
6 cmds/g2-g2isforced.sh
View
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# returns true if the branch in parameter was forced update
+# returns 1 if the given branch was force updated, 0 if not
# if no parameters, figures the upstream branch from the tracking table
remote=$1
@@ -8,6 +8,6 @@ remote=$1
[[ -n $remote ]] && {
hash=$("$GIT_EXE" reflog $remote | head -1 | grep forced-update | cut -f 1 -d " ")
branch=$("$GIT_EXE" branch | grep "*" | sed "s/* //")
- [[ -n $hash && $("$GIT_EXE" reflog $branch | grep $hash | grep -c reset) -eq 0 ]] && echo "true" && exit 0
+ [[ -n $hash && $("$GIT_EXE" reflog $branch | grep $hash | grep -c reset) -eq 0 ]] && exit 1
}
-echo "false"
+exit 0
26 cmds/g2-g2iswip.sh
View
@@ -1,8 +1,22 @@
#!/bin/bash
-#
-# returns true if there is a wip commit at the tip of the branch
+# returns 1 if there is a wip commit at the tip of the branch, 0 if not
+# Typical usage $("$GIT_EXE" g2iswip) || exit 1
-remote=$1
-[[ -z $1 ]] && remote=$("$GIT_EXE" g2getremote)
-[[ -z $remote ]] && [[ $("$GIT_EXE" log --oneline -1 2>/dev/null | cut -f 2 -d " " | grep -c wip) -gt 0 ]] && echo "true" && exit 0
-[[ $("$GIT_EXE" log $remote..HEAD --oneline 2>/dev/null | cut -f 2 -d " " | uniq | grep -c wip) -gt 0 ]] && echo "true" || echo "false"
+source "$G2_HOME/cmds/color.sh"
+
+error() {
+ echo_fatal "fatal: Work In Progress (wip) detected, please run <g unwip> to resume progress first.";
+ exit 1;
+}
+
+remote=$1;
+[[ -z $1 ]] && remote=$("$GIT_EXE" g2getremote);
+
+wip=0;
+if [[ -z $remote ]]; then
+ [[ $("$GIT_EXE" log --oneline -1 2>/dev/null | cut -f 2 -d " " | grep -c wip) -gt 0 ]] && wip=1;
+else
+ [[ $("$GIT_EXE" log $remote..HEAD --oneline 2>/dev/null | cut -f 2 -d " " | uniq | grep -c wip) -gt 0 ]] && wip=1;
+fi
+
+[[ $wip -eq 1 ]] && error || exit 0;
2  cmds/g2-g2pull.sh
View
@@ -16,7 +16,7 @@ usage() {
n=$#;
[[ $n -eq 0 || ${!n} = -* ]] && error
-[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: pulling on a wip commit is forbidden, please <unwip> and commit <ci>" && exit 1
+$("$GIT_EXE" g2iswip) || exit 1
[[ ${!n} = */* ]] && usage
branch=${!n}
let n--
2  cmds/g2-g2push.sh
View
@@ -31,7 +31,7 @@ hasFFlag() {
fflg=$( hasFFlag "$@" )
n=$#;
[[ $fflg = "false" && $n -eq 0 ]] && error
-[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: pushing a wip commit is forbiden, please <unwip> and commit <ci>" && exit 1
+$("$GIT_EXE" g2iswip) || exit 1
[[ $fflg = "true" ]] && {
read -p "warning: you are about to force push history, please confirm (y/n)? " -n 1 -r;
echo
5 cmds/g2-g2version.sh
View
@@ -1,5 +1,4 @@
#!/bin/bash
#
-# Well speaks by itself
-echo "G2 based on" $("$GIT_EXE" version)
-
+# Well, speaks by itself
+echo "G2 is based on" $("$GIT_EXE" version)
6 cmds/g2-key.sh
View
@@ -1,18 +1,16 @@
#!/bin/bash
-#
+# displays or generates ssh keys
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..."
+ echo_info "Generating SSH keys..."
emailinput=$("$GIT_EXE" config --global --get user.email)
ssh-keygen -t rsa -P "" -C "$emailinput" -f "$HOME/.ssh/id_rsa"
displayKey
10 cmds/g2-mg.sh
View
@@ -3,7 +3,7 @@
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
+$("$GIT_EXE" g2iswip) || exit 1
# substitute "upstream" with real upstream name
declare -a v=("$@")
@@ -18,16 +18,16 @@ do
let i++
done
-[[ $("$GIT_EXE" g2isbehind) = "true" ]] && read -p "It appears the current branch is in the past, proceed with the merge (y/n)? " -n 1 -r && [[ $REPLY != [yY]* ]] && exit 0
+$("$GIT_EXE" g2isbehind) && read -p "It appears the current branch is in the past, proceed with the merge (y/n)? " -n 1 -r && [[ $REPLY != [yY]* ]] && exit 0
# merge returns 0 when it merges correctly
"$GIT_EXE" merge "$@" || {
unmerged=$("$GIT_EXE" ls-files --unmerged)
if [[ -n $unmerged ]]; then
- echo_info "info: some files need to be merged manually, please use <mt> to fix conflicts..."
- echo_info " once all resolved, <freeze> and <commit> the files."
- echo_info " note that you may <abort> at any time."
+ echo_info "A few files need to be merged manually, please use <g mt> to fix conflicts..."
+ echo_info " once all resolved, <g freeze> and <g commit> the files."
+ echo_info " note: you may abort the merge at any time with <g abort> ."
fi
exit 1;
}
1  cmds/g2-panic.sh
View
@@ -2,6 +2,7 @@
#
read -p "This action will discard all work in progress and checkout HEAD, are you sure (y/n)? " -n 1 -r
+echo
[[ $REPLY == [yY]* ]] && {
echo
"$GIT_EXE" abort
1  cmds/g2-rs.sh
View
@@ -3,6 +3,7 @@
[[ $1 == "upstream" ]] && {
read -p "warning: resetting to the upstream may erase any local changes, are you sure (y/n)? " -n 1 -r
+ echo
[[ $REPLY == [yY]* ]] && { echo
"$GIT_EXE" abort
remote=$("$GIT_EXE" g2getremote)
4 cmds/g2-setup.sh
View
@@ -30,9 +30,9 @@ fi
g2count=$("$GIT_EXE" config --global --bool --get g2.prompt.countfiles)
if [[ -z $g2count ]]; then
- read -p "Count files in the bash prompt? (true): " -e g2count
+ read -p "Count files in the bash prompt (this may cause some slowdowns)? (true): " -e g2count
else
- read -p "Count files in the bash prompt? ($g2count): " -e g2count
+ read -p "Count files in the bash prompt (this may cause some slowdowns)? ($g2count): " -e g2count
fi
g2excludes=$("$GIT_EXE" config --global --get g2.panic.excludes)
14 cmds/g2-sync.sh
View
@@ -11,24 +11,22 @@ source "$G2_HOME/cmds/color.sh"
remote=$("$GIT_EXE" g2getremote)
-[[ $("$GIT_EXE" g2iswip $remote) = "true" ]] && echo_fatal "fatal: sorry, wip commits shall not be synced. Please <unwip>, then <freeze> & commit <ci>" && exit 1;
+$("$GIT_EXE" g2iswip $remote) || exit 1;
[[ -z $remote ]] && echo_fatal "fatal: please use <track> to setup the remote/branch to track with" && exit 2
[[ $# -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" g2isforced $remote) = "true" ]] &&
- echo_fatal "abort: it appears the history of the branch was changed on the server." &&
- echo_fatal " please issue a <g rs upstream> or a <g rb $remote> to resume" &&
- exit 1;
+$("$GIT_EXE" g2isforced $remote) && echo_fatal "abort: it appears the history of the branch was changed on the server." && echo_fatal " please issue a <g rs upstream> or a <g rb $remote> 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
lchg=$(grep -c "^<" /tmp/git_upstream_status_delta);
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 "info: some files need to be merged manually, please use <g mt> to fix conflicts."
- echo_info " Once all resolved, do NOT commit, but use <g continue> to resume."
- echo_info " Note that you may <abort> at any time"
+ echo_info "A few files need to be merged manually, please use <g mt> to fix conflicts."
+ echo_info " Once all conflicts are resolved, do NOT commit, but use <g continue> to resume."
+ echo_info " Note: you may abort the merge at any time with <g abort> ."
fi
exit 1;
}
10 cmds/g2-undo.sh
View
@@ -6,13 +6,13 @@ source "$G2_HOME/cmds/color.sh"
if [ $# -lt 1 ]
then
- echo_info "Usage : g undo <file|commit|merge> <?path>"
- exit
+ echo_info "Usage : g undo <file|commit|merge> <?path>";
+ exit;
fi
-read -p "warning: the action may discard your changes, please confirm (y/n)? " -n 1 -r
-echo
-[[ $REPLY = [nN]* ]] && exit 0
+read -p "warning: the action may discard your changes, please confirm (y/n)? " -n 1 -r;
+echo;
+[[ $REPLY = [nN]* ]] && exit 0;
case "$1" in
1  cmds/g2-unfreeze.sh
View
@@ -4,6 +4,5 @@
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;
18 cmds/g2-unwip.sh
View
@@ -1,5 +1,19 @@
#!/bin/bash
#
-source "$G2_HOME/cmds/color.sh"
-[[ $("$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)
+isWIP() {
+remote=$("$GIT_EXE" g2getremote)
+if [[ -z $remote ]]; then
+ [[ $("$GIT_EXE" log --oneline -1 2>/dev/null | cut -f 2 -d " " | grep -c wip) -gt 0 ]] && wip=1
+else
+ [[ $("$GIT_EXE" log $remote..HEAD --oneline 2>/dev/null | cut -f 2 -d " " | uniq | grep -c wip) -gt 0 ]] && wip=1
+fi
+wip=0
+}
+
+isWIPå
+if [[ $wip -eq 0 ]]; then
+ echo_fatal "fatal: there is nothing to <unwip>..."
+else
+ "$GIT_EXE" log -n 1 | grep -q -c "wip" && "$GIT_EXE" reset HEAD~1
+fi
16 cmds/g2-wip.sh
View
@@ -2,9 +2,19 @@
#
source "$G2_HOME/cmds/color.sh"
-if [[ $("$GIT_EXE" g2iswip) = "true" ]]; then
- echo_info "info: amending previous wip commit..."
+isWIP() {
+remote=$("$GIT_EXE" g2getremote)
+if [[ -z $remote ]]; then
+ [[ $("$GIT_EXE" log --oneline -1 2>/dev/null | cut -f 2 -d " " | grep -c wip) -gt 0 ]] && wip=1
+else
+ [[ $("$GIT_EXE" log $remote..HEAD --oneline 2>/dev/null | cut -f 2 -d " " | uniq | grep -c wip) -gt 0 ]] && wip=1
+fi
+wip=0
+}
+
+if [[ $wip -eq 1 ]]; then
+ echo_info "Amending previous wip commit..."
"$GIT_EXE" g2am
else
- "$GIT_EXE" freeze -m wip
+ "$GIT_EXE" freeze -m "wip"
fi
4 g2.sh
View
@@ -33,7 +33,7 @@ function __g2_usage() {
${boldon}abort${boldoff} - aborts any rebase/merge
${boldon}am <?-f>${boldoff} - amends last commit with staging area
${boldon}br <?-D> <?-M> <?branch>${boldoff} - list or create branches
- ${boldon}bs${boldoff} - bisect
+ ${boldon}bs${boldoff} - bisect, aka bug finder
${boldon}co <branch>${boldoff} - switches branch (either local/remote)
${boldon}continue${boldoff} - resumes a conflict resolution
${boldon}cp <commit>${boldoff} - cherry-pick
@@ -59,7 +59,7 @@ function __g2_usage() {
${boldon}rm <params...>${boldoff} - remove files
${boldon}rs <params...>${boldoff} - reset branch status
${boldon}rs upstream${boldoff} - resets branch to upstream state
- ${boldon}rt <?params...>${boldoff} - remote management
+ ${boldon}rt <?params...>${boldoff} - git remotes management
${boldon}rv <commit>${boldoff} - reverts commits
${boldon}setup${boldoff} - configures user, key, editor, tools
${boldon}sh <?-deep>${boldoff} - show commit contents
Please sign in to comment.
Something went wrong with that request. Please try again.