b00bf1c9a8
rebase backends currently behave differently with empty commit messages, largely as a side-effect of the different underlying commands on which they are based. am-based rebases apply commits with an empty commit message without stopping or requiring the user to specify an extra flag. (It is interesting to note that am-based rebases are the default rebase type, and no one has ever requested a --no-allow-empty-message flag to change this behavior.) merge-based and interactive-based rebases (which are ultimately based on git-commit), will currently halt on any such commits and require the user to manually specify what to do with the commit and continue. One possible rationale for the difference in behavior is that the purpose of an "am" based rebase is solely to transplant an existing history, while an "interactive" rebase is one whose purpose is to polish a series before making it publishable. Thus, stopping and asking for confirmation for a possible problem is more appropriate in the latter case. However, there are two problems with this rationale: 1) merge-based rebases are also non-interactive and there are multiple types of rebases that use the interactive machinery but are not explicitly interactive (e.g. when either --rebase-merges or --keep-empty are specified without --interactive). These rebases are also used solely to transplant an existing history, and thus also should default to --allow-empty-message. 2) this rationale only says that the user is more accepting of stopping in the case of an explicitly interactive rebase, not that stopping for this particular reason actually makes sense. Exploring whether it makes sense, requires backing up and analyzing the underlying commands... If git-commit did not error out on empty commits by default, accidental creation of commits with empty messages would be a very common occurrence (this check has caught me many times). Further, nearly all such empty commit messages would be considered an accidental error (as evidenced by a huge amount of documentation across version control systems and in various blog posts explaining how important commit messages are). A simple check for what would otherwise be a common error thus made a lot of sense, and git-commit gained an --allow-empty-message flag for special case overrides. This has made commits with empty messages very rare. There are two sources for commits with empty messages for rebase (and cherry-pick): (a) commits created in git where the user previously specified --allow-empty-message to git-commit, and (b) commits imported into git from other version control systems. In case (a), the user has already explicitly specified that there is something special about this commit that makes them not want to specify a commit message; forcing them to re-specify with every cherry-pick or rebase seems more likely to be infuriating than helpful. In case (b), the commit is highly unlikely to have been authored by the person who has imported the history and is doing the rebase or cherry-pick, and thus the user is unlikely to be the appropriate person to write a commit message for it. Stopping and expecting the user to modify the commit before proceeding thus seems counter-productive. Further, note that while empty commit messages was a common error case for git-commit to deal with, it is a rare case for rebase (or cherry-pick). The fact that it is rare raises the question of why it would be worth checking and stopping on this particular condition and not others. For example, why doesn't an interactive rebase automatically stop if the commit message's first line is 2000 columns long, or is missing a blank line after the first line, or has every line indented with five spaces, or any number of other myriad problems? Finally, note that if a user doing an interactive rebase does have the necessary knowledge to add a message for any such commit and wants to do so, it is rather simple for them to change the appropriate line from 'pick' to 'reword'. The fact that the subject is empty in the todo list that the user edits should even serve as a way to notify them. As far as I can tell, the fact that merge-based and interactive-based rebases stop on commits with empty commit messages is solely a by-product of having been based on git-commit. It went without notice for a long time precisely because such cases are rare. The rareness of this situation made it difficult to reason about, so when folks did eventually notice this behavior, they assumed it was there for a good reason and just added an --allow-empty-message flag. In my opinion, stopping on such messages not desirable in any of these cases, even the (explicitly) interactive case. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
91 lines
1.9 KiB
Bash
Executable File
91 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='rebase should handle arbitrary git message'
|
|
|
|
. ./test-lib.sh
|
|
. "$TEST_DIRECTORY"/lib-rebase.sh
|
|
|
|
cat >F <<\EOF
|
|
This is an example of a commit log message
|
|
that does not conform to git commit convention.
|
|
|
|
It has two paragraphs, but its first paragraph is not friendly
|
|
to oneline summary format.
|
|
EOF
|
|
|
|
cat >G <<\EOF
|
|
commit log message containing a diff
|
|
EOF
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
>file1 &&
|
|
>file2 &&
|
|
git add file1 file2 &&
|
|
test_tick &&
|
|
git commit -m "Initial commit" &&
|
|
git branch diff-in-message &&
|
|
git branch empty-message-merge &&
|
|
|
|
git checkout -b multi-line-subject &&
|
|
cat F >file2 &&
|
|
git add file2 &&
|
|
test_tick &&
|
|
git commit -F F &&
|
|
|
|
git cat-file commit HEAD | sed -e "1,/^\$/d" >F0 &&
|
|
|
|
git checkout diff-in-message &&
|
|
echo "commit log message containing a diff" >G &&
|
|
echo "" >>G &&
|
|
cat G >file2 &&
|
|
git add file2 &&
|
|
git diff --cached >>G &&
|
|
test_tick &&
|
|
git commit -F G &&
|
|
|
|
git cat-file commit HEAD | sed -e "1,/^\$/d" >G0 &&
|
|
|
|
git checkout empty-message-merge &&
|
|
echo file3 >file3 &&
|
|
git add file3 &&
|
|
git commit --allow-empty-message -m "" &&
|
|
|
|
git checkout master &&
|
|
|
|
echo One >file1 &&
|
|
test_tick &&
|
|
git add file1 &&
|
|
git commit -m "Second commit"
|
|
'
|
|
|
|
test_expect_success 'rebase commit with multi-line subject' '
|
|
|
|
git rebase master multi-line-subject &&
|
|
git cat-file commit HEAD | sed -e "1,/^\$/d" >F1 &&
|
|
|
|
test_cmp F0 F1 &&
|
|
test_cmp F F0
|
|
'
|
|
|
|
test_expect_success 'rebase commit with diff in message' '
|
|
git rebase master diff-in-message &&
|
|
git cat-file commit HEAD | sed -e "1,/^$/d" >G1 &&
|
|
test_cmp G0 G1 &&
|
|
test_cmp G G0
|
|
'
|
|
|
|
test_expect_success 'rebase -m commit with empty message' '
|
|
git rebase -m master empty-message-merge
|
|
'
|
|
|
|
test_expect_success 'rebase -i commit with empty message' '
|
|
git checkout diff-in-message &&
|
|
set_fake_editor &&
|
|
env FAKE_COMMIT_MESSAGE=" " FAKE_LINES="reword 1" \
|
|
git rebase -i HEAD^
|
|
'
|
|
|
|
test_done
|