Permalink
Browse files

Add support for non-origin remotes to push & pull

  • Loading branch information...
1 parent aae0ab5 commit bc92dbd75f772ef7ebac7632750a70c73c164e0c @jamiew committed Feb 8, 2012
Showing with 12 additions and 9 deletions.
  1. +8 −6 pull
  2. +4 −3 push
View
14 pull
@@ -6,20 +6,22 @@
# safely stashing and re-applying your local changes, if any
#
-remote="origin"
-branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
+branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') || exit $?
+remote=$(git config "branch.${branch}.remote") || exit $?
+remote_branch=$(git config "branch.${branch}.merge" | awk -F '/' '{ print $3 }') || exit $?
# Stash any local changes
stash=$(git stash)
# Update our remote
-git fetch $remote || exit 1
+git fetch $remote || exit $?
-# Pull, using rebase
-git pull --rebase $remote $branch || exit 1
+# Pull, using rebase if configured
+rebase="--rebase" # TODO disable if env-var is set
+git pull $rebase $remote $remote_branch || exit $?
# Update submodules
-git submodule update
+git submodule update || exit $?
# Pop any stashed changes
if [[ "$stash" =~ "No local changes to save" ]]; then
View
7 push
@@ -10,11 +10,12 @@
# e.g. for doing "push -f"
#
-remote="origin"
-branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
+branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') || exit $?
+remote=$(git config "branch.${branch}.remote") || exit $?
+remote_branch=$(git config "branch.${branch}.merge" | awk -F '/' '{ print $3 }') || exit $?
# Push & save output
-push=$(git push --set-upstream $* $remote $branch 2>&1)
+push=$(git push --set-upstream $* $remote $remote_branch 2>&1)
exit_code=$?
if [ $exit_code != 0 ]; then

0 comments on commit bc92dbd

Please sign in to comment.