blob: e565d2bbeb5a0f404bbce4908e10d1e5b543a9e5 [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
Austin Schuh357b6432021-11-04 22:41:16 -070016export SIGNOFF="Signed-off-by: $(git config --get user.name) <$(git config --get user.email)>"
17
Austin Schuhab681672019-09-20 00:29:31 -070018GIT_DIR=$(readlink -f "$(git rev-parse --git-dir)")
19TMP_MSG="${GIT_DIR}/COMMIT_MSG_REWRITE"
20
Austin Schuh357b6432021-11-04 22:41:16 -070021git filter-branch -f --msg-filter \
22 "cat | git interpret-trailers --trailer \"$SIGNOFF\" > ${TMP_MSG} && \"${GIT_DIR}/hooks/commit-msg\" ${TMP_MSG} && \
Austin Schuhab681672019-09-20 00:29:31 -070023 cat \"${TMP_MSG}\"" HEAD...HEAD~1
24
25rm -rf "${TMP_MSG}"