Skip to content

Commit a3a733e

Browse files
spearceJunio C Hamano
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b0fe4a commit a3a733e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

git-commit.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,12 @@ fi
635635
PARENTS="-p HEAD"
636636
if test -z "$initial_commit"
637637
then
638+
rloga='commit'
638639
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
640+
rloga='commit (merge)'
639641
PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
640642
elif test -n "$amend"; then
643+
rloga='commit (amend)'
641644
PARENTS=$(git-cat-file commit HEAD |
642645
sed -n -e '/^$/q' -e 's/^parent /-p /p')
643646
fi
@@ -649,6 +652,7 @@ else
649652
fi
650653
PARENTS=""
651654
current=
655+
rloga='commit (initial)'
652656
fi
653657

654658
if test -z "$no_edit"
@@ -724,7 +728,7 @@ then
724728
fi &&
725729
commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
726730
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 &&
728732
rm -f -- "$GIT_DIR/MERGE_HEAD" &&
729733
if test -f "$NEXT_INDEX"
730734
then

t/t1400-update-ref.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,30 @@ test_expect_success \
188188
echo OTHER >F &&
189189
GIT_AUTHOR_DATE="2005-05-26 23:41" \
190190
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)
192203
rm -f M'
193204

194205
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
196207
$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.
197210
EOF
198211
test_expect_success \
199212
'git-commit logged updates' \
200213
'diff expect .git/logs/$m'
201-
unset h_TEST h_OTHER
214+
unset h_TEST h_OTHER h_FIXED h_MERGED
202215

203216
test_expect_success \
204217
'git-cat-file blob master:F (expect OTHER)' \

0 commit comments

Comments
 (0)