Created
December 5, 2014 00:04
-
-
Save jenseng/34b6b1e48b83270aef39 to your computer and use it in GitHub Desktop.
gerrit-submit-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/bash | |
set -e | |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) # what if no branch? | |
COMMON_ANCESTOR=$(git merge-base HEAD origin/master) | |
NUM_COMMITS=$(expr $(git log --pretty=oneline|sed -n "/$COMMON_ANCESTOR/{=; q;}") - 1) | |
GIT_DIR=$(git rev-parse --show-toplevel)/.git | |
# make sure our commit message dir and message file exist ... that way the | |
# message (and Change-Id) will persist from one gerrit push to the next | |
COMMIT_MSG_DIR=$GIT_DIR/gerrit_squashes | |
COMMIT_MSG=$COMMIT_MSG_DIR/$CURRENT_BRANCH | |
mkdir -p $COMMIT_MSG_DIR | |
touch $COMMIT_MSG | |
# detach so we don't mess up our feature branch | |
git checkout $(git show --pretty=%H -s) >/dev/null 2>&1 | |
# squash the commits from this branch into one | |
git reset --soft HEAD~$NUM_COMMITS | |
git commit -F $COMMIT_MSG -e && cat $GIT_DIR/COMMIT_EDITMSG | grep -v -E '^#' > $COMMIT_MSG | |
git push origin HEAD:refs/for/master | |
git checkout $CURRENT_BRANCH >/dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment