blob: e565d2bbeb5a0f404bbce4908e10d1e5b543a9e5 [file] [log] [blame]
#!/bin/bash
#
# Coppied from:
# https://stackoverflow.com/questions/40297499/pushing-squashed-subtree-change-to-gerrit
#
# This command re-writes the history after doing a git subtree {pull|add}
# to add Gerrit Change-Id lines to the squash commit message.
#
# It assumes that HEAD is the merge commit merging the subtree into HEAD.
# The original HEAD commit will be backed up under refs/original, which
# is helpful if something goes wrong.
set -e
set -o pipefail
export SIGNOFF="Signed-off-by: $(git config --get user.name) <$(git config --get user.email)>"
GIT_DIR=$(readlink -f "$(git rev-parse --git-dir)")
TMP_MSG="${GIT_DIR}/COMMIT_MSG_REWRITE"
git filter-branch -f --msg-filter \
"cat | git interpret-trailers --trailer \"$SIGNOFF\" > ${TMP_MSG} && \"${GIT_DIR}/hooks/commit-msg\" ${TMP_MSG} && \
cat \"${TMP_MSG}\"" HEAD...HEAD~1
rm -rf "${TMP_MSG}"