Created
October 18, 2012 22:24
-
-
Save wernight/3915147 to your computer and use it in GitHub Desktop.
'git submit' which pushes to Gerrit matching branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# | |
# Save this file as ~/bin/git-submit | |
# | |
# Usage: git submit [--draft] [remote] | |
# Example: | |
# 'git submit' executed on a Git branch tracking origin/master will push to refs/for/master. | |
# | |
REMOTE=origin | |
GERRIT_REFS=for | |
for i | |
do | |
if [[ "$i" == "--draft" ]] | |
then | |
GERRIT_REFS=drafts | |
else | |
REMOTE=$i | |
fi | |
done | |
BRANCH=`git symbolic-ref HEAD` | |
case $BRANCH in | |
refs/heads/*) | |
BRANCH=${BRANCH:11} | |
;; | |
*) | |
echo "I can't figure out which branch you are on." | |
exit 1 | |
;; | |
esac | |
REMOTE_BRANCH=`git config --get "branch.$BRANCH.merge"` | |
if [ -z $REMOTE_BRANCH ] | |
then | |
echo "There is no tracking information for the current branch." | |
echo "If you wish to set tracking information for this branch you can do so with:" | |
echo "" | |
echo " git branch --set-upstream $BRANCH <remote>/<branch>" | |
echo "" | |
exit 1 | |
fi | |
# (optional) Remove refs/heads/ | |
case $REMOTE_BRANCH in | |
refs/heads/*) | |
REMOTE_BRANCH=${REMOTE_BRANCH:11} | |
;; | |
esac | |
echo git push $REMOTE HEAD:refs/$GERRIT_REFS/$REMOTE_BRANCH | |
git push $REMOTE HEAD:refs/$GERRIT_REFS/$REMOTE_BRANCH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment