Created
December 20, 2018 06:20
-
-
Save minhoryang/2342c29f09fb9ef8763bb64be5d029a1 to your computer and use it in GitHub Desktop.
.git/hooks/post-applypatch for rehashing with an original committer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
. git-sh-setup | |
## XXX: For rehashing with an original comitter: | |
# | |
# Backgrounds: | |
# - {commit} includes ['tree', 'parent', 'author', 'committer'] | |
# - When `git am` finished, generated an unexpected commit id. | |
# - Check `git cat-file commit HEAD` and compare it. | |
# - `git am` handled only ['tree', 'parent', 'author'] | |
# - `git format-patch` includes only these metadatas. | |
# - So the lack of 'committer' metadata caused wrong generated commit id. | |
# - Below codes run inside of `git am` | |
# - Whenever patch file pipes in. | |
# | |
# HACK: | |
PATCH_APPLYING_AUTHOR="$(git rev-parse --git-path rebase-apply/author-sciprt)" | |
if [ -r $PATCH_APPLYING_AUTHOR ] | |
then | |
# Setup the environment variables for an original committer metadata. | |
source $PATCH_APPLYING_AUTHOR | |
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE | |
export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME | |
export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL | |
export GIT_COMMITTER_DATE=$GIT_AUHTOR_DATE | |
# Commit (rehash) with an original committer metadata. | |
BEFORE="$(git rev-parse --verify --short HEAD)" | |
git commit --amend -reset-author --no-edit --no-verify --quite | |
AFTER="$(git rev-parse --verify --short HEAD)" | |
# Report to user | |
COMMIT_MSG_FILE="$(git rev-parse --git-path rebase-apply/final-commit)" | |
COMMIT_MSG="$(head -n 1 $COMMIT_MSG_FILE)" | |
echo "Rehashed: $COMMIT_MSG :: $AFTER" | |
# TODO: (WIP) Recheck! | |
EXPECTED_HASH_FILE="$(git rev-parse --git-path rebase-apply/abort-safety)" | |
if [ -r $EXPECTED_HASH_FILE ] | |
then | |
EXPECTED_HASH="$(cat $EXPECTED_HASH_FILE)" | |
if [ "$AFTER" != "$EXPECTED_HASH" ] | |
then | |
echo "" | |
echo " Warning! Mismatched when patch generated. (experimental)" | |
echo " - Before : $BEFORE" | |
echo " - After : $AFTER" | |
echo " - Expected: $EXPECTED_HASH" | |
echo "" | |
fi | |
fi | |
fi | |
# END-OF-HACK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment