@matheusbsbs / matheus-bagliano / commits / a3a733e63b
Fork 0

Record the type of commit operation in the reflog.

If committing a merge (.git/MERGE_HEAD exists), an initial tree (no HEAD) or using --amend to amend the prior commit then denote the subtype of commit in the reflog. This helps to distinguish amended or merge commits from normal commits. In the case of --amend the prior sha1 is probably the commit which is being thrown away in favor of the new commit. Since it is likely that the old commit doesn't have any ref pointing to it anymore it can be interesting to know why that the commit was replaced and orphaned. In the case of a merge the prior sha1 is probably the first parent of the new merge commit. Consequently having its prior sha1 in the reflog is slightly less interesting but its still informative to know the commit was the result of a merge which had to be completed by hand. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn Pearce committed Jul 10, 2006 at 22:48 UTC a3a733e63bb8dfbd6921b8f405d652db1821d4fd
2 files changed +21 -4
git-commit.sh
+5 -1
@@ -635,9 +635,12 @@ fi
635 PARENTS="-p HEAD"
636 if test -z "$initial_commit"
637 then
638 + rloga='commit'
639 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
640 + rloga='commit (merge)'
641 PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
642 elif test -n "$amend"; then
643 + rloga='commit (amend)'
644 PARENTS=$(git-cat-file commit HEAD |
645 sed -n -e '/^$/q' -e 's/^parent /-p /p')
646 fi
@@ -649,6 +652,7 @@ else
652 fi
653 PARENTS=""
654 current=
655 + rloga='commit (initial)'
656 fi
657
658 if test -z "$no_edit"
@@ -724,7 +728,7 @@ then
728 fi &&
729 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
730 rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
727 - git-update-ref -m "commit: $rlogm" HEAD $commit $current &&
731 + git-update-ref -m "$rloga: $rlogm" HEAD $commit $current &&
732 rm -f -- "$GIT_DIR/MERGE_HEAD" &&
733 if test -f "$NEXT_INDEX"
734 then
t/t1400-update-ref.sh
+16 -3
@@ -188,17 +188,30 @@ test_expect_success \
188 echo OTHER >F &&
189 GIT_AUTHOR_DATE="2005-05-26 23:41" \
190 GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a &&
191 - h_OTHER=$(git-rev-parse --verify HEAD)
191 + h_OTHER=$(git-rev-parse --verify HEAD) &&
192 + echo FIXED >F &&
193 + EDITOR=true \
194 + GIT_AUTHOR_DATE="2005-05-26 23:44" \
195 + GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend &&
196 + h_FIXED=$(git-rev-parse --verify HEAD) &&
197 + echo TEST+FIXED >F &&
198 + echo Merged initial commit and a later commit. >M &&
199 + echo $h_TEST >.git/MERGE_HEAD &&
200 + GIT_AUTHOR_DATE="2005-05-26 23:45" \
201 + GIT_COMMITTER_DATE="2005-05-26 23:45" git-commit -F M &&
202 + h_MERGED=$(git-rev-parse --verify HEAD)
203 rm -f M'
204
205 cat >expect <<EOF
195 -$Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit: add
206 +$Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
207 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
208 +$h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
209 +$h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
210 EOF
211 test_expect_success \
212 'git-commit logged updates' \
213 'diff expect .git/logs/$m'
201 -unset h_TEST h_OTHER
214 +unset h_TEST h_OTHER h_FIXED h_MERGED
215
216 test_expect_success \
217 'git-cat-file blob master:F (expect OTHER)' \