From 1d61a21b466c86ad427ba1e525831f94ceb2a9f3 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 25 Jan 2012 11:11:47 -0500 Subject: [PATCH 1/7] Support DESTDIR See http://www.gnu.org/prep/standards/html_node/DESTDIR.html for details. --- Makefile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 113482e..df9d99d 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)/etc/bash_completion.d + cp -f etc/bash_completion.sh $(DESTDIR)/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)/etc/bash_completion.d/git-extras clean: docclean From bfc3f788a16c4c3b35b056dedb835bc32ab04321 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 25 Jan 2012 11:17:31 -0500 Subject: [PATCH 2/7] Make bash_completion install respect $(PREFIX) variable --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index df9d99d..5791f2f 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,8 @@ install: cp -f $(BIN) $(DESTDIR)$(PREFIX)/$(BIN); \ ) cp -f man/git-*.1 $(DESTDIR)$(MANPREFIX) - @mkdir -p $(DESTDIR)/etc/bash_completion.d - cp -f etc/bash_completion.sh $(DESTDIR)/etc/bash_completion.d/git-extras + @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) @@ -43,7 +43,7 @@ uninstall: echo "... uninstalling $(DESTDIR)$(MANPREFIX)/$(MAN)"; \ rm -f $(DESTDIR)$(MANPREFIX)/$(MAN); \ ) - rm -f $(DESTDIR)/etc/bash_completion.d/git-extras + rm -f $(DESTDIR)$(PREFIX)/etc/bash_completion.d/git-extras clean: docclean From 86111254a473cb76c7dfa23766006be078a08ee3 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 25 Jan 2012 11:18:26 -0500 Subject: [PATCH 3/7] Added myself to AUTHORS file --- AUTHORS | 1 + 1 file changed, 1 insertion(+) 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 From a5c66eb7f44d71e7fc02e0d59943c7f6bb3222c8 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 25 Jan 2012 11:30:32 -0500 Subject: [PATCH 4/7] Added MacPorts as a way to install git-extras --- Readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Readme.md b/Readme.md index cc8fa3b..a246301 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 From 3e3b4c918c8d5b9388e2523b32f692a346451ed9 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 25 Jan 2012 11:52:08 -0500 Subject: [PATCH 5/7] Send error messages to stderr instead of stdout --- bin/git-back | 4 ++-- bin/git-bug | 4 ++-- bin/git-contrib | 2 +- bin/git-create-branch | 2 +- bin/git-delete-branch | 2 +- bin/git-delete-submodule | 6 +++--- bin/git-delete-tag | 2 +- bin/git-feature | 6 +++--- bin/git-fresh-branch | 2 +- bin/git-graft | 2 +- bin/git-pull-request | 8 ++++---- bin/git-refactor | 6 +++--- bin/git-release | 2 +- bin/git-touch | 2 +- bin/git-undo | 4 ++-- 15 files changed, 27 insertions(+), 27 deletions(-) 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-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..e9366d9 100755 --- a/bin/git-pull-request +++ b/bin/git-pull-request @@ -5,11 +5,11 @@ 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 "$request" && echo "pull request number required" 1>&2 && exit 1 +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 echo "pulling $url" curl -# $url \ | git am --signoff \ - && echo "completed pull request $request" \ No newline at end of file + && echo "completed pull request $request" 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 From 5a15aea7abf9d734c0db3bc97914283d3f8b71e2 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 8 Feb 2012 15:30:11 -0500 Subject: [PATCH 6/7] Added git-gh-oauth: script to manage oauth keys for github --- bin/git-gh-oauth | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 bin/git-gh-oauth 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 From 6fce92796c39a4d7bcd2300a1938b8632806e188 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 8 Feb 2012 15:30:46 -0500 Subject: [PATCH 7/7] Modified git-pull-request to be able to create pull requests, as well as apply them --- bin/git-pull-request | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/bin/git-pull-request b/bin/git-pull-request index e9366d9..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" 1>&2 && exit 1 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 -echo "pulling $url" -curl -# $url \ - | git am --signoff \ - && echo "completed pull request $request" +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 +