Austin Schuh | ab68167 | 2019-09-20 00:29:31 -0700 | [diff] [blame] | 1 | #!/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 | |
| 13 | set -e |
| 14 | set -o pipefail |
| 15 | |
Austin Schuh | 357b643 | 2021-11-04 22:41:16 -0700 | [diff] [blame] | 16 | export SIGNOFF="Signed-off-by: $(git config --get user.name) <$(git config --get user.email)>" |
| 17 | |
Austin Schuh | ab68167 | 2019-09-20 00:29:31 -0700 | [diff] [blame] | 18 | GIT_DIR=$(readlink -f "$(git rev-parse --git-dir)") |
| 19 | TMP_MSG="${GIT_DIR}/COMMIT_MSG_REWRITE" |
| 20 | |
Austin Schuh | 357b643 | 2021-11-04 22:41:16 -0700 | [diff] [blame] | 21 | git filter-branch -f --msg-filter \ |
| 22 | "cat | git interpret-trailers --trailer \"$SIGNOFF\" > ${TMP_MSG} && \"${GIT_DIR}/hooks/commit-msg\" ${TMP_MSG} && \ |
Austin Schuh | ab68167 | 2019-09-20 00:29:31 -0700 | [diff] [blame] | 23 | cat \"${TMP_MSG}\"" HEAD...HEAD~1 |
| 24 | |
| 25 | rm -rf "${TMP_MSG}" |