Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2020-02-16 00:36:24 +0300
committerJunio C Hamano <gitster@pobox.com>2020-02-17 02:40:42 +0300
commitd48e5e21da980c6d439655a1292d0332b341c7d1 (patch)
treed3bc7c9e24f36fce1f3a0e1b36f38708fe2993e3 /t/t3424-rebase-empty.sh
parenta9ae8fde2eb0c00723d850ba23ea8401864fab83 (diff)
rebase (interactive-backend): make --keep-empty the default
Different rebase backends have different treatment for commits which start empty (i.e. have no changes relative to their parent), and the --keep-empty option was added at some point to allow adjusting behavior. The handling of commits which start empty is actually quite similar to commit b00bf1c9a8dd (git-rebase: make --allow-empty-message the default, 2018-06-27), which pointed out that the behavior for various backends is often more happenstance than design. The specific change made in that commit is actually quite relevant as well and much of the logic there directly applies here. It makes a lot of sense in 'git commit' to error out on the creation of empty commits, unless an override flag is provided. However, once someone determines that there is a rare case that merits using the manual override to create such a commit, it is somewhere between annoying and harmful to have to take extra steps to keep such intentional commits around. Granted, empty commits are quite rare, which is why handling of them doesn't get considered much and folks tend to defer to existing (accidental) behavior and assume there was a reason for it, leading them to just add flags (--keep-empty in this case) that allow them to override the bad defaults. Fix the interactive backend so that --keep-empty is the default, much like we did with --allow-empty-message. The am backend should also be fixed to have --keep-empty semantics for commits that start empty, but that is not included in this patch other than a testcase documenting the failure. Note that there was one test in t3421 which appears to have been written expecting --keep-empty to not be the default as correct behavior. This test was introduced in commit 00b8be5a4d38 ("add tests for rebasing of empty commits", 2013-06-06), which was part of a series focusing on rebase topology and which had an interesting original cover letter at https://lore.kernel.org/git/1347949878-12578-1-git-send-email-martinvonz@gmail.com/ which noted Your input especially appreciated on whether you agree with the intent of the test cases. and then went into a long example about how one of the many tests added had several questions about whether it was correct. As such, I believe most the tests in that series were about testing rebase topology with as many different flags as possible and were not trying to state in general how those flags should behave otherwise. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t3424-rebase-empty.sh')
-rwxr-xr-xt/t3424-rebase-empty.sh70
1 files changed, 70 insertions, 0 deletions
diff --git a/t/t3424-rebase-empty.sh b/t/t3424-rebase-empty.sh
new file mode 100755
index 0000000000..3b716e980e
--- /dev/null
+++ b/t/t3424-rebase-empty.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+test_description='git rebase of commits that start or become empty'
+
+. ./test-lib.sh
+
+test_expect_success 'setup test repository' '
+ test_write_lines 1 2 3 4 5 6 7 8 9 10 >numbers &&
+ test_write_lines A B C D E F G H I J >letters &&
+ git add numbers letters &&
+ git commit -m A &&
+
+ git branch upstream &&
+ git branch localmods &&
+
+ git checkout upstream &&
+ test_write_lines A B C D E >letters &&
+ git add letters &&
+ git commit -m B &&
+
+ test_write_lines 1 2 3 4 five 6 7 8 9 ten >numbers &&
+ git add numbers &&
+ git commit -m C &&
+
+ git checkout localmods &&
+ test_write_lines 1 2 3 4 five 6 7 8 9 10 >numbers &&
+ git add numbers &&
+ git commit -m C2 &&
+
+ git commit --allow-empty -m D &&
+
+ test_write_lines A B C D E >letters &&
+ git add letters &&
+ git commit -m "Five letters ought to be enough for anybody"
+'
+
+test_expect_failure 'rebase (am-backend) with a variety of empty commits' '
+ test_when_finished "git rebase --abort" &&
+ git checkout -B testing localmods &&
+ # rebase (--am) should not drop commits that start empty
+ git rebase upstream &&
+
+ test_write_lines D C B A >expect &&
+ git log --format=%s >actual &&
+ test_cmp expect actual
+'
+
+test_expect_failure 'rebase --merge with a variety of empty commits' '
+ test_when_finished "git rebase --abort" &&
+ git checkout -B testing localmods &&
+ # rebase --merge should not halt on the commit that becomes empty
+ git rebase --merge upstream &&
+
+ test_write_lines D C B A >expect &&
+ git log --format=%s >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'rebase --interactive with a variety of empty commits' '
+ git checkout -B testing localmods &&
+ test_must_fail git rebase --interactive upstream &&
+
+ git rebase --skip &&
+
+ test_write_lines D C B A >expect &&
+ git log --format=%s >actual &&
+ test_cmp expect actual
+'
+
+test_done