blob: a3e53723c6a33349fea83dca8503ac19d4f70fc0 [file] [log] [blame]
Austin Schuhab681672019-09-20 00:29:31 -07001#!/bin/bash
2#
3# Coppied from:
4# https://stackoverflow.com/questions/40297499/pushing-squashed-subtree-change-to-gerrit
5#
6# This command re-writes the history after doing a git subtree {pull|add}
7# to add Gerrit Change-Id lines to the squash commit message.
8#
9# It assumes that HEAD is the merge commit merging the subtree into HEAD.
10# The original HEAD commit will be backed up under refs/original, which
11# is helpful if something goes wrong.
12
13set -e
14set -o pipefail
15
16GIT_DIR=$(readlink -f "$(git rev-parse --git-dir)")
17TMP_MSG="${GIT_DIR}/COMMIT_MSG_REWRITE"
18
19git filter-branch --msg-filter \
20 "cat > ${TMP_MSG} && \"${GIT_DIR}/hooks/commit-msg\" ${TMP_MSG} && \
21 cat \"${TMP_MSG}\"" HEAD...HEAD~1
22
23rm -rf "${TMP_MSG}"