@matheusbsbs / matheus-bagliano / commits / 96e19488f1
Fork 0

rebase: invoke post-rewrite hook

We have to deal with two separate code paths: a normal rebase, which actually goes through git-am; and rebase {-m|-s}. The only small issue with both is that they need to remember the original sha1 across a possible conflict resolution. rebase -m already puts this information in $dotest/current, and we just introduce a similar file for git-am. Note that in git-am, the hook really only runs when coming from git-rebase: the code path that sets the $dotest/original-commit file is guarded by a test for $dotest/rebasing. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Mar 12, 2010 at 18:04 UTC 96e19488f1e8f3964f5f329248852864b4ee4541
3 files changed +45
git-am.sh
+10
@@ -573,6 +573,7 @@ do
573 echo "Patch is empty. Was it split wrong?"
574 stop_here $this
575 }
576 + rm -f "$dotest/original-commit"
577 if test -f "$dotest/rebasing" &&
578 commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \
579 -e q "$dotest/$msgnum") &&
@@ -580,6 +581,7 @@ do
581 then
582 git cat-file commit "$commit" |
583 sed -e '1,/^$/d' >"$dotest/msg-clean"
584 + echo "$commit" > "$dotest/original-commit"
585 else
586 {
587 sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
@@ -766,6 +768,10 @@ do
768 git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
769 stop_here $this
770
771 + if test -f "$dotest/original-commit"; then
772 + echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten"
773 + fi
774 +
775 if test -x "$GIT_DIR"/hooks/post-applypatch
776 then
777 "$GIT_DIR"/hooks/post-applypatch
@@ -774,6 +780,10 @@ do
780 go_next
781 done
782
783 +if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then
784 + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
785 +fi
786 +
787 git gc --auto
788
789 rm -fr "$dotest"
git-rebase.sh
+5
@@ -79,6 +79,7 @@ continue_merge () {
79 then
80 printf "Committed: %0${prec}d " $msgnum
81 fi
82 + echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten"
83 else
84 if test -z "$GIT_QUIET"
85 then
@@ -153,6 +154,10 @@ move_to_original_branch () {
154
155 finish_rb_merge () {
156 move_to_original_branch
157 + if test -x "$GIT_DIR"/hooks/post-rewrite &&
158 + test -s "$dotest"/rewritten; then
159 + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
160 + fi
161 rm -r "$dotest"
162 say All done.
163 }
t/t5407-post-rewrite-hook.sh
+30
@@ -49,4 +49,34 @@ test_expect_success 'git commit --amend --no-post-rewrite' '
49 test ! -f post-rewrite.data
50 '
51
52 +test_expect_success 'git rebase' '
53 + git reset --hard D &&
54 + clear_hook_input &&
55 + test_must_fail git rebase --onto A B &&
56 + echo C > foo &&
57 + git add foo &&
58 + git rebase --continue &&
59 + echo rebase >expected.args &&
60 + cat >expected.data <<EOF &&
61 +$(git rev-parse C) $(git rev-parse HEAD^)
62 +$(git rev-parse D) $(git rev-parse HEAD)
63 +EOF
64 + verify_hook_input
65 +'
66 +
67 +test_expect_success 'git rebase --skip' '
68 + git reset --hard D &&
69 + clear_hook_input &&
70 + test_must_fail git rebase --onto A B &&
71 + test_must_fail git rebase --skip &&
72 + echo D > foo &&
73 + git add foo &&
74 + git rebase --continue &&
75 + echo rebase >expected.args &&
76 + cat >expected.data <<EOF &&
77 +$(git rev-parse D) $(git rev-parse HEAD)
78 +EOF
79 + verify_hook_input
80 +'
81 +
82 test_done