[RFC PATCH 3/6] filter-branch: invoke post-rewrite hook
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
git-filter-branch.sh | 10 ++++++++++
t/t5407-post-rewrite-hook.sh | 20 ++++++++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 88fb0f0..531cc8e 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -358,6 +358,10 @@ while read commit parents; do
@SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
$(git write-tree) $parentstr < ../message > ../map/$commit ||
die "could not write rewritten commit"
+ new_commit=$(map $commit)
+ if test $commit != $new_commit; then
+ echo $commit $new_commit >> "$workdir"/../rewritten
+ fi
done <../revs
# If we are filtering for paths, as in the case of a subdirectory
@@ -484,6 +488,12 @@ if [ "$filter_tag_name" ]; then
fi
cd ../..
+
+if test -x "$GIT_DIR"/hooks/post-rewrite &&
+ test -s "$workdir"/../rewritten; then
+ "$GIT_DIR"/hooks/post-rewrite filter-branch < "$workdir"/../rewritten
+fi
+
rm -rf "$tempdir"
trap - 0
diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh
index 1020af9..ff23ebf 100755
--- a/t/t5407-post-rewrite-hook.sh
+++ b/t/t5407-post-rewrite-hook.sh
@@ -49,4 +49,24 @@ test_expect_success 'git commit --amend --no-post-rewrite' '
test ! -f post-rewrite.data
'
+test_expect_success 'git filter-branch' '
+ git reset --hard D &&
+ clear_hook_input &&
+ git filter-branch -f --tree-filter "touch newfile" B..HEAD &&
+ echo filter-branch >expected.args &&
+ cat >expected.data <<EOF &&
+$(git rev-parse C) $(git rev-parse HEAD^)
+$(git rev-parse D) $(git rev-parse HEAD)
+EOF
+ verify_hook_input
+'
+
+test_expect_success 'git filter-branch (no-op)' '
+ git reset --hard D &&
+ clear_hook_input &&
+ git filter-branch -f B..HEAD &&
+ test ! -f post-rewrite.args &&
+ test ! -f post-rewrite.data
+'
+
test_done
--
1.7.0.216.g74d8e