Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Validate that we are in a git repo before any action is run

  • Loading branch information...
commit 8431cd406600c24b06601fa5b375e1bd70a73c8e 1 parent f592be8
@orefalo authored
View
2  README.md
@@ -412,7 +412,6 @@ Distributed under the GNU General Public License, version 2.0.
##TODO
-* g track in non repo -> should warn early, also applies to other cmds
* 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
@@ -422,6 +421,7 @@ Distributed under the GNU General Public License, version 2.0.
## FIXED / DONE
+* Validate that we are in a git repo before any action is run
* Homebrew fomula is now live
* allow g co <hash>
* Many commands are now colorized
View
2  cmds/g2-abort.sh
@@ -2,6 +2,8 @@
#
# Aborts a merge or rebase
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
[[ ! $("$GIT_EXE" rev-parse --git-dir 2> /dev/null) ]] && fatal "Not a Git Repository" || ("$GIT_EXE" merge --abort 2> /dev/null || "$GIT_EXE" rebase --abort 2> /dev/null)
View
2  cmds/g2-br.sh
@@ -4,6 +4,8 @@
#
# Can also delete, rename and create branches (wizards)
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
hasDMFlag() {
View
2  cmds/g2-co.sh
@@ -1,6 +1,8 @@
#!/bin/bash
#
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
if [ "$(echo "$1" | grep -e "^[0-9A-Fa-f]*$")" == "$1" ]; then
View
2  cmds/g2-continue.sh
@@ -4,6 +4,8 @@
# Unlike git, it detects what needs to be resumed: rebase or merge
# and smartly run the right command
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
state=$("$GIT_EXE" g2brstatus)
View
2  cmds/g2-cp.sh
@@ -2,5 +2,7 @@
#
# Cherry picking, but forbids anything on top of wip commit
+"$GIT_EXE" rev-parse || exit 1
+
"$GIT_EXE" g2iswip || exit 1
"$GIT_EXE" cherry-pick "$@"
View
1  cmds/g2-freeze.sh
@@ -1,5 +1,6 @@
#!/bin/bash
#
+"$GIT_EXE" rev-parse || exit 1
source "$G2_HOME/cmds/color.sh"
View
2  cmds/g2-g2add.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#
source "$G2_HOME/cmds/color.sh"
-fatal "Don't use ${boldon}add${boldoff} with G2, ${boldon}freeze${boldoff} and ${boldon}unfreeze${boldoff} are powerfull commands"
+fatal "Please don't use ${boldon}add${boldoff} with G2, ${boldon}freeze${boldoff} and ${boldon}unfreeze${boldoff} are more powerfull commands"
View
3  cmds/g2-g2am.sh
@@ -1,5 +1,8 @@
#!/bin/bash
#
+
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
[[ $("$GIT_EXE" diff --cached --numstat | wc -l) -eq 0 ]] && error "No files to amend, please use ${boldon}g freeze${boldoff} to stage the changes to amend."
View
2  cmds/g2-g2gc.sh
@@ -2,4 +2,6 @@
#
# Cleans up the repository
+"$GIT_EXE" rev-parse || exit 1
+
"$GIT_EXE" fetch --all -p && "$GIT_EXE" fsck && "$GIT_EXE" reflog expire --expire=now --all && "$GIT_EXE" gc --aggressive --prune=now
View
2  cmds/g2-g2getremote.sh
@@ -2,5 +2,7 @@
#
# returns the upstream branch name if any
+"$GIT_EXE" rev-parse || exit 1
+
remote=$("$GIT_EXE" rev-parse --symbolic-full-name --abbrev-ref @{u} 2> /dev/null)
[[ $remote == "@{u}" ]] && echo "" || echo $remote
View
2  cmds/g2-g2haschanges.sh
@@ -2,6 +2,8 @@
#
# returns 0 if no pending changes, 1 if any (workspace or index)
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh";
if [[ $("$GIT_EXE" diff --cached --numstat | wc -l) -ne 0 ]]; then
View
2  cmds/g2-g2haslocalcommit.sh
@@ -2,6 +2,8 @@
#
# returns 1 local commits (commit not on the server), 0 if not, 2 no remote
+"$GIT_EXE" rev-parse || exit 1
+
remote=$("$GIT_EXE" g2getremote)
[[ -z "$remote" ]] && exit 2
[[ $("$GIT_EXE" log $remote..HEAD --oneline | wc -l) -eq 0 ]] && exit 0
View
2  cmds/g2-g2isbehind.sh
@@ -2,6 +2,8 @@
#
# Returns 0 if the branch is behind its upstream branch, 1 if not
+"$GIT_EXE" rev-parse || exit 1
+
local=$("$GIT_EXE" branch | grep "*" | sed "s/* //")
remote=$1
[[ -z $1 ]] && remote=$("$GIT_EXE" g2getremote)
View
2  cmds/g2-g2isforced.sh
@@ -3,6 +3,8 @@
# returns 0 if the given branch was force updated, 1 if not
# if no parameters, figures the upstream branch from the tracking table
+"$GIT_EXE" rev-parse || exit 1
+
remote=$1
[[ -z $1 ]] && remote=$("$GIT_EXE" g2getremote)
[[ -n $remote ]] && {
View
2  cmds/g2-g2iswip.sh
@@ -2,6 +2,8 @@
# returns 1 if there is a wip commit at the tip of the branch, 0 if not
# Typical usage $("$GIT_EXE" g2iswip) || exit 1
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
remote=$1;
View
2  cmds/g2-g2pull.sh
@@ -1,6 +1,8 @@
#!/bin/bash
#
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
err() {
View
2  cmds/g2-g2push.sh
@@ -4,6 +4,8 @@
# forbids wip commits from being pushed
# forbids push to the working branch
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
err() {
View
2  cmds/g2-ig.sh
@@ -2,6 +2,8 @@
#
# Ignores a file and automatically adds it to gitignore & removes from source control
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
[[ -z "$@" ]] && echo_info "Usage: ignore [file]" || { ([ ! -e .gitignore ] && touch .gitignore); echo "$GIT_PREFIX$1" >> .gitignore && echo "Ignoring file $1" && "$GIT_EXE" rm --cached "$GIT_PREFIX$@" > /dev/null 2>&1 && "$GIT_EXE" st; }
View
1  cmds/g2-mg.sh
@@ -1,6 +1,7 @@
#!/bin/bash
#
+
source "$G2_HOME/cmds/color.sh"
"$GIT_EXE" g2iswip || exit 1
View
2  cmds/g2-panic.sh
@@ -1,6 +1,8 @@
#!/bin/bash
#
+"$GIT_EXE" rev-parse || exit 1
+
read -p "This action will discard all work in progress and checkout HEAD, are you sure (y/n)? " -n 1 -r
echo
[[ $REPLY == [yY]* ]] && {
View
2  cmds/g2-rb.sh
@@ -1,6 +1,8 @@
#!/bin/bash
#
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
# substitute "upstream" with real upstream name
View
1  cmds/g2-rs.sh
@@ -1,5 +1,6 @@
#!/bin/bash
#
+"$GIT_EXE" rev-parse || exit 1
source "$G2_HOME/cmds/color.sh"
View
2  cmds/g2-sh.sh
@@ -3,6 +3,8 @@
# Displays the details of a commit, can take a hash as parameter
# use -deep to display contents
+"$GIT_EXE" rev-parse || exit 1
+
[[ $1 == "-deep" ]] && shift || flag="--name-only"
[[ -z $1 ]] && br="HEAD" || br=$1
[[ -n $flag ]] && { "$GIT_EXE" show --pretty="format:" $flag $br | sort | uniq; } || "$GIT_EXE" show $br;
View
2  cmds/g2-sync.sh
@@ -3,6 +3,8 @@
# Performs a fetch, rebase, push with a bunch of validations
#
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
[[ $1 == "upstream" ]] && pullOnly=true && shift
View
3  cmds/g2-track.sh
@@ -1,5 +1,8 @@
#!/bin/bash
#
+
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
if [[ $# -eq 1 ]]; then
View
2  cmds/g2-undo.sh
@@ -2,6 +2,8 @@
#
# easy undo a file, a commit or a merge
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
if [ $# -lt 1 ]
View
2  cmds/g2-unfreeze.sh
@@ -1,6 +1,8 @@
#!/bin/bash
#
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
([[ -z "$@" ]] && ("$GIT_EXE" reset -q HEAD > /dev/null || fatal "The first commit must be unfrozen ${boldon}file by file${boldoff}. Sorry about that...") || ("$GIT_EXE" reset -q HEAD -- $@ > /dev/null || "$GIT_EXE" rm -q --cached $@))
View
2  cmds/g2-unwip.sh
@@ -1,6 +1,8 @@
#!/bin/bash
#
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
"$GIT_EXE" g2iswip > /dev/null
View
3  cmds/g2-wip.sh
@@ -1,5 +1,8 @@
#!/bin/bash
#
+
+"$GIT_EXE" rev-parse || exit 1
+
source "$G2_HOME/cmds/color.sh"
"$GIT_EXE" g2iswip > /dev/null
Please sign in to comment.
Something went wrong with that request. Please try again.