summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: afcc4f7)
raw | patch | inline | side by side (parent: afcc4f7)
author | Johannes Sixt <johannes.sixt@telecom.at> | |
Mon, 3 Dec 2007 07:24:50 +0000 (08:24 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 3 Dec 2007 08:25:26 +0000 (00:25 -0800) |
Normally, it should not be allowed to generate an empty commit. A merge
commit generated with git 'merge -s ours' does not change the tree (along
the first parent), but merges are not "empty" even if they do not change
the tree. Hence, commit 8588452ceb7 allowed to amend a merge commit that
does not change the tree, but 4fb5fd5d301 disallowed it again in an
attempt to avoid that an existing commit is amended such that it becomes
empty. With this change, a commit can be edited (create a new one or amend
an existing one) either if there are changes or if there are at least two
parents.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit generated with git 'merge -s ours' does not change the tree (along
the first parent), but merges are not "empty" even if they do not change
the tree. Hence, commit 8588452ceb7 allowed to amend a merge commit that
does not change the tree, but 4fb5fd5d301 disallowed it again in an
attempt to avoid that an existing commit is amended such that it becomes
empty. With this change, a commit can be edited (create a new one or amend
an existing one) either if there are changes or if there are at least two
parents.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-commit.sh | patch | blob | history | |
t/t7501-commit.sh | patch | blob | history |
diff --git a/git-commit.sh b/git-commit.sh
index 485339754ca3567c86b824af656700654c68e173..cef76a77754190338add5b2bb61435fca5193b61 100755 (executable)
--- a/git-commit.sh
+++ b/git-commit.sh
# we need to check if there is anything to commit
run_status >/dev/null
fi
-if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
-then
+case "$?,$PARENTS" in
+0,* | *,-p' '?*-p' '?*)
+ # a merge commit can record the same tree as its parent.
+ ;;
+*)
rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
use_status_color=t
run_status
exit 1
-fi
+esac
case "$no_edit" in
'')
diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index 31a6f63399a97902e493c453a3f3117bc44ef2f7..2e7bcb016ac94f150423446b2fbce2d61eb7bced 100755 (executable)
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
'
+test_expect_success 'same tree (single parent)' '
+
+ if git commit -m empty
+ then
+ echo oops -- should have complained
+ false
+ else
+ : happy
+ fi
+
+'
+
+test_expect_success 'same tree (merge and amend merge)' '
+
+ git checkout -b side HEAD^ &&
+ echo zero >zero &&
+ git add zero &&
+ git commit -m "add zero" &&
+ git checkout master &&
+
+ git merge -s ours side -m "empty ok" &&
+ git diff HEAD^ HEAD >actual &&
+ : >expected &&
+ diff -u expected actual &&
+
+ git commit --amend -m "empty really ok" &&
+ git diff HEAD^ HEAD >actual &&
+ : >expected &&
+ diff -u expected actual
+
+'
+
test_done