Skip to content

Instantly share code, notes, and snippets.

@wernight
Last active December 19, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wernight/5916904 to your computer and use it in GitHub Desktop.
Save wernight/5916904 to your computer and use it in GitHub Desktop.
Gerrit `git submit` helper. Does a `git push HEAD:origin/refs/for/$current_branch_name` and supports drafts. Works in msysgit and in most Linux/Mac.
#!/bin/bash -e
#
# Gerrit `git submit` helper. Does a `git push HEAD:origin/refs/for/$current_branch_name` and supports drafts.
#
# Get latest version from https://gist.github.com/wernight/5916904
#
# Install:
# 1. Save this script under one of you path (e.g., ~/bin/ or /usr/local/bin)
# 2. Make it executable (e.g., chmod +x ~/bin/git-submit)
#
# Usage
# git submit [--draft]
#
# Author: Werner Beroux <werner@beroux.com>
#
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 $BRANCH --set-upstream-to=<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