diff --git a/AUTHORS b/AUTHORS index a74a7c7..07efc19 100644 --- a/AUTHORS +++ b/AUTHORS @@ -19,3 +19,4 @@ Patches and Suggestions - Alex McHale - Gert Van Gool - Devin Withers +- David Baumgold diff --git a/Makefile b/Makefile index 113482e..5791f2f 100644 --- a/Makefile +++ b/Makefile @@ -7,17 +7,17 @@ MAN_HTML = $(MANS:.md=.html) MAN_PAGES = $(MANS:.md=.1) install: - @mkdir -p $(MANPREFIX) - @mkdir -p $(PREFIX)/bin - @echo "... installing bins to $(PREFIX)/bin" - @echo "... installing man pages to $(MANPREFIX)" + @mkdir -p $(DESTDIR)$(MANPREFIX) + @mkdir -p $(DESTDIR)$(PREFIX)/bin + @echo "... installing bins to $(DESTDIR)$(PREFIX)/bin" + @echo "... installing man pages to $(DESTDIR)$(MANPREFIX)" @$(foreach BIN, $(BINS), \ echo "... installing `basename $(BIN)`"; \ - cp -f $(BIN) $(PREFIX)/$(BIN); \ + cp -f $(BIN) $(DESTDIR)$(PREFIX)/$(BIN); \ ) - cp -f man/git-*.1 $(MANPREFIX) - @mkdir -p /etc/bash_completion.d - cp -f etc/bash_completion.sh /etc/bash_completion.d/git-extras + cp -f man/git-*.1 $(DESTDIR)$(MANPREFIX) + @mkdir -p $(DESTDIR)$(PREFIX)/etc/bash_completion.d + cp -f etc/bash_completion.sh $(DESTDIR)$(PREFIX)/etc/bash_completion.d/git-extras docs: $(MAN_HTML) $(MAN_PAGES) @@ -36,14 +36,14 @@ man/%.1: man/%.md uninstall: @$(foreach BIN, $(BINS), \ - echo "... uninstalling $(PREFIX)/$(BIN)"; \ - rm -f $(PREFIX)/$(BIN); \ + echo "... uninstalling $(DESTDIR)$(PREFIX)/$(BIN)"; \ + rm -f $(DESTDIR)$(PREFIX)/$(BIN); \ ) @$(foreach MAN, $(MAN_PAGES), \ - echo "... uninstalling $(MANPREFIX)/$(MAN)"; \ - rm -f $(MANPREFIX)/$(MAN); \ + echo "... uninstalling $(DESTDIR)$(MANPREFIX)/$(MAN)"; \ + rm -f $(DESTDIR)$(MANPREFIX)/$(MAN); \ ) - rm -f /etc/bash_completion.d/git-extras + rm -f $(DESTDIR)$(PREFIX)/etc/bash_completion.d/git-extras clean: docclean diff --git a/Readme.md b/Readme.md index a26802c..b2234e9 100644 --- a/Readme.md +++ b/Readme.md @@ -16,6 +16,12 @@ One-liner: $ curl https://raw.github.com/visionmedia/git-extras/master/bin/git-extras | INSTALL=y sh ``` +[MacPorts](http://www.macports.org/) + +```bash +$ sudo port install git-extras +``` + [Brew](github.com/mxcl/homebrew/) (buggy): ```bash diff --git a/bin/git-back b/bin/git-back index 300e016..e4f73ca 100755 --- a/bin/git-back +++ b/bin/git-back @@ -4,8 +4,8 @@ if test $# -eq 0; then git reset --soft HEAD~1 else if `echo $1 | grep -q [^[:digit:]]`; then - echo $1 is not a number + echo "$1 is not a number" 1>&2 else git reset --soft HEAD~$1 fi -fi \ No newline at end of file +fi diff --git a/bin/git-bug b/bin/git-bug index c86adc0..d46b93e 100755 --- a/bin/git-bug +++ b/bin/git-bug @@ -1,7 +1,7 @@ #!/bin/sh if test "$1" = "finish"; then - test -z $2 && echo "bug required." && exit 1 + test -z $2 && echo "bug required." 1>&2 && exit 1 branch=bug/$2 git merge --no-ff $branch && git delete-branch $branch else @@ -9,4 +9,4 @@ else branch=bug/$1 git checkout -b $branch &> /dev/null git checkout $branch &> /dev/null -fi \ No newline at end of file +fi diff --git a/bin/git-contrib b/bin/git-contrib index 23c130e..07ea48d 100755 --- a/bin/git-contrib +++ b/bin/git-contrib @@ -2,7 +2,7 @@ user="$*" -test -z "$user" && echo "user name required." && exit 1 +test -z "$user" && echo "user name required." 1>&2 && exit 1 count=`git log --oneline --pretty="format: %an" | grep "$user" | wc -l` test $count -eq 0 && echo "$user did not contribute." && exit 1 diff --git a/bin/git-create-branch b/bin/git-create-branch index ca05dc4..fae0e19 100755 --- a/bin/git-create-branch +++ b/bin/git-create-branch @@ -1,7 +1,7 @@ #!/bin/sh branch=$1 -test -z $branch && echo "branch required." && exit 1 +test -z $branch && echo "branch required." 1>&2 && exit 1 git push origin origin:refs/heads/$branch git fetch origin diff --git a/bin/git-delete-branch b/bin/git-delete-branch index 78f62cb..ec0070e 100755 --- a/bin/git-delete-branch +++ b/bin/git-delete-branch @@ -1,6 +1,6 @@ #!/bin/sh branch=$1 -test -z $branch && echo "branch required." && exit 1 +test -z $branch && echo "branch required." 1>&2 && exit 1 git branch -D $branch git branch -d -r origin/$branch && git push origin :$branch diff --git a/bin/git-delete-submodule b/bin/git-delete-submodule index 8b80e35..ac5f451 100755 --- a/bin/git-delete-submodule +++ b/bin/git-delete-submodule @@ -2,11 +2,11 @@ submodule=$1 -test -z $submodule && echo "submodule required" && exit 1 -test ! -f .gitmodules && echo ".gitmodules file not found" && exit 2 +test -z $submodule && echo "submodule required" 1>&2 && exit 1 +test ! -f .gitmodules && echo ".gitmodules file not found" 1>&2 && exit 2 NAME=$(echo $submodule | sed 's/\/$//g') -test -z $(git config --file=.gitmodules submodule.$NAME.url) && echo "submodule not found" && exit 3 +test -z $(git config --file=.gitmodules submodule.$NAME.url) && echo "submodule not found" 1>&2 && exit 3 git config --remove-section submodule.$NAME git config --file=.gitmodules --remove-section submodule.$NAME diff --git a/bin/git-delete-tag b/bin/git-delete-tag index 470e378..506a575 100755 --- a/bin/git-delete-tag +++ b/bin/git-delete-tag @@ -1,5 +1,5 @@ #!/bin/sh tagname=$1 -test -z $tagname && echo "tag required." && exit 1 +test -z $tagname && echo "tag required." 1>&2 && exit 1 git tag -d $tagname && git push origin :refs/tags/$tagname diff --git a/bin/git-feature b/bin/git-feature index 42e6b3a..aa33d9d 100755 --- a/bin/git-feature +++ b/bin/git-feature @@ -1,12 +1,12 @@ #!/bin/sh if test "$1" = "finish"; then - test -z $2 && echo "feature required." && exit 1 + test -z $2 && echo "feature required." 1>&2 && exit 1 branch=feature/$2 git merge --no-ff $branch && git delete-branch $branch else - test -z $1 && echo "feature required." && exit 1 + test -z $1 && echo "feature required." 1>&2 && exit 1 branch=feature/$1 git checkout -b $branch &> /dev/null git checkout $branch &> /dev/null -fi \ No newline at end of file +fi diff --git a/bin/git-fresh-branch b/bin/git-fresh-branch index e8dd7e0..3d847c7 100755 --- a/bin/git-fresh-branch +++ b/bin/git-fresh-branch @@ -2,7 +2,7 @@ branch=$1 -test -z $branch && echo "branch required." && exit 1 +test -z $branch && echo "branch required." 1>&2 && exit 1 git symbolic-ref HEAD refs/heads/$branch rm .git/index diff --git a/bin/git-gh-oauth b/bin/git-gh-oauth new file mode 100644 index 0000000..30d9b2a --- /dev/null +++ b/bin/git-gh-oauth @@ -0,0 +1,17 @@ +#!/bin/sh + +user=`git config github.user` +test -z "$user" && echo "failed to fetch github.user" 1>&2 && exit 1 +oauthToken=`git config github.oauthToken` +if [ -z $oauthToken ] ; then + echo "Github oAuth token not found. Creating a new one." + stty_orig=`stty -g` + stty -echo + printf "Github password:" + read passwd + stty $stty_orig + url="https://api.github.com/authorizations" + oauthToken=$(curl -# -u "$user:$passwd" $url -d '{"scopes": ["repo", "user", "gist"]}' | jshon -e token | sed -e 's/"//g') + git config --global github.oauthToken $oauthToken +fi +echo $oauthToken diff --git a/bin/git-graft b/bin/git-graft index 83a5d20..5a6c90e 100755 --- a/bin/git-graft +++ b/bin/git-graft @@ -3,7 +3,7 @@ src=$1 dst=$2 -test -z $src && echo "source branch required." && exit 1 +test -z $src && echo "source branch required." 1>&2 && exit 1 git checkout $dst \ && git merge --no-ff $src \ diff --git a/bin/git-pull-request b/bin/git-pull-request index 2a5bf3d..eb67b28 100755 --- a/bin/git-pull-request +++ b/bin/git-pull-request @@ -1,15 +1,42 @@ #!/bin/sh -request=$1 +# check if arg 1 is a number or not +echo $1 | egrep "^[[:digit:]]+$" > /dev/null +is_not_number=$? repo=${PWD##*/} user=`git config github.user` -url="https://github.com/$user/$repo/pull/$request.patch" -test -z "$request" && echo "pull request number required" && exit 1 -test -z "$repo" && echo "failed to detect repo" && exit 2 -test -z "$user" && echo "failed to fetch github.user" && exit 3 +test -z "$repo" && echo "failed to detect repo" 1>&2 && exit 2 +test -z "$user" && echo "failed to fetch github.user" 1>&2 && exit 3 + +if [ ! $is_not_number ] ; then + # apply existing pull request + url="https://github.com/$user/$repo/pull/$1.patch" + echo "pulling $url" + curl -# $url \ + | git am --signoff \ + && echo "completed pull request $request" +else + # push + branchname=`git branch --no-color | sed -n -e 's/^\* \(.*\)/\1/p'` + echo "git push origin $branchname" + git push origin $branchname + + # create new pull request + url="https://api.github.com/repos/$user/$repo/pulls" + echo "creating pull request" + oauthToken=`git gh-oauth` + body="{\"title\": \"$branchname\", \"head\": \"$user:$branchname\", \"base\": \"master\"}" + curl_result=$(curl -H "Authorization: token $oauthToken" $url -d "$body" --silent \ + --write-out "%{http_code}") + json=`echo ${curl_result} | sed 's/...$//'` + http_code=`echo ${curl_request} | perl -pe 's/(.*)(...)$/$2/'` + if [ "${http_code:0:1}" == "2" ] ; then + pr_num=`echo "$json" | jshon -e number` + echo "Created pull request #${pr_num}" + else + echo "$json" | jshon -e message + echo "$json" + fi +fi -echo "pulling $url" -curl -# $url \ - | git am --signoff \ - && echo "completed pull request $request" \ No newline at end of file diff --git a/bin/git-refactor b/bin/git-refactor index 68182f2..2b50fc4 100755 --- a/bin/git-refactor +++ b/bin/git-refactor @@ -1,12 +1,12 @@ #!/bin/sh if test "$1" = "finish"; then - test -z $2 && echo "refactor required." && exit 1 + test -z $2 && echo "refactor required." 1>&2 && exit 1 branch=refactor/$2 git merge --no-ff $branch && git delete-branch $branch else - test -z $1 && echo "refactor required." && exit 1 + test -z $1 && echo "refactor required." 1>&2 && exit 1 branch=refactor/$1 git checkout -b $branch &> /dev/null git checkout $branch &> /dev/null -fi \ No newline at end of file +fi diff --git a/bin/git-release b/bin/git-release index f0feed0..df7f354 100755 --- a/bin/git-release +++ b/bin/git-release @@ -18,5 +18,5 @@ if test $# -gt 0; then && hook post-release \ && echo "... complete" else - echo "tag required" && exit 1 + echo "tag required" 1>&2 && exit 1 fi diff --git a/bin/git-touch b/bin/git-touch index 42c1cf3..5a1fe1d 100755 --- a/bin/git-touch +++ b/bin/git-touch @@ -2,7 +2,7 @@ filename="$*" -test -z "$filename" && echo "filename required" && exit 1 +test -z "$filename" && echo "filename required" 1>&2 && exit 1 touch "$filename" \ && git add "$filename" diff --git a/bin/git-undo b/bin/git-undo index 363ec73..613dc53 100755 --- a/bin/git-undo +++ b/bin/git-undo @@ -4,8 +4,8 @@ if test $# -eq 0; then git reset --hard HEAD~1 else if `echo $1 | grep -q [^[:digit:]]`; then - echo $1 is not a number + echo "$1 is not a number" 1>&2 else git reset --hard HEAD~$1 fi -fi \ No newline at end of file +fi