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 | |
| 16 | GIT_DIR=$(readlink -f "$(git rev-parse --git-dir)") |
| 17 | TMP_MSG="${GIT_DIR}/COMMIT_MSG_REWRITE" |
| 18 | |
| 19 | git filter-branch --msg-filter \ |
| 20 | "cat > ${TMP_MSG} && \"${GIT_DIR}/hooks/commit-msg\" ${TMP_MSG} && \ |
| 21 | cat \"${TMP_MSG}\"" HEAD...HEAD~1 |
| 22 | |
| 23 | rm -rf "${TMP_MSG}" |