mirror of
https://github.com/git/git.git
synced 2024-11-27 12:03:55 +08:00
b9cbd2958f
Commit d48e5e21da
("rebase (interactive-backend): make --keep-empty the
default", 2020-02-15) turned --keep-empty (for keeping commits which
start empty) into the default. The logic underpinning that commit was:
1) 'git commit' errors out on the creation of empty commits without an
override flag
2) Once someone determines that the override is worthwhile, it's
annoying and/or harmful to required them to take extra steps in
order to keep such commits around (and to repeat such steps with
every rebase).
While the logic on which the decision was made is sound, the result was
a bit of an overcorrection. Instead of jumping to having --keep-empty
being the default, it jumped to making --keep-empty the only available
behavior. There was a simple workaround, though, which was thought to
be good enough at the time. People could still drop commits which
started empty the same way the could drop any commits: by firing up an
interactive rebase and picking out the commits they didn't want from the
list. However, there are cases where external tools might create enough
empty commits that picking all of them out is painful. As such, having
a flag to automatically remove start-empty commits may be beneficial.
Provide users a way to drop commits which start empty using a flag that
existed for years: --no-keep-empty. Interpret --keep-empty as
countermanding any previous --no-keep-empty, but otherwise leaving
--keep-empty as the default.
This might lead to some slight weirdness since commands like
git rebase --empty=drop --keep-empty
git rebase --empty=keep --no-keep-empty
look really weird despite making perfect sense (the first will drop
commits which become empty, but keep commits that started empty; the
second will keep commits which become empty, but drop commits which
started empty). However, --no-keep-empty was named years ago and we are
predominantly keeping it for backward compatibility; also we suspect it
will only be used rarely since folks already have a simple way to drop
commits they don't want with an interactive rebase.
Reported-by: Bryan Turner <bturner@atlassian.com>
Reported-by: Sami Boukortt <sami@boukortt.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
171 lines
4.4 KiB
Bash
Executable File
171 lines
4.4 KiB
Bash
Executable File
#!/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 (apply-backend)' '
|
|
test_when_finished "git rebase --abort" &&
|
|
git checkout -B testing localmods &&
|
|
# rebase (--apply) should not drop commits that start empty
|
|
git rebase --apply upstream &&
|
|
|
|
test_write_lines D C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --merge --empty=drop' '
|
|
git checkout -B testing localmods &&
|
|
git rebase --merge --empty=drop upstream &&
|
|
|
|
test_write_lines D C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --merge uses default of --empty=drop' '
|
|
git checkout -B testing localmods &&
|
|
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 --merge --empty=keep' '
|
|
git checkout -B testing localmods &&
|
|
git rebase --merge --empty=keep upstream &&
|
|
|
|
test_write_lines D C2 C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --merge --empty=ask' '
|
|
git checkout -B testing localmods &&
|
|
test_must_fail git rebase --merge --empty=ask upstream &&
|
|
|
|
git rebase --skip &&
|
|
|
|
test_write_lines D C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --interactive --empty=drop' '
|
|
git checkout -B testing localmods &&
|
|
git rebase --interactive --empty=drop upstream &&
|
|
|
|
test_write_lines D C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --interactive --empty=keep' '
|
|
git checkout -B testing localmods &&
|
|
git rebase --interactive --empty=keep upstream &&
|
|
|
|
test_write_lines D C2 C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --interactive --empty=ask' '
|
|
git checkout -B testing localmods &&
|
|
test_must_fail git rebase --interactive --empty=ask upstream &&
|
|
|
|
git rebase --skip &&
|
|
|
|
test_write_lines D C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --interactive uses default of --empty=ask' '
|
|
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_expect_success 'rebase --merge --empty=drop --keep-empty' '
|
|
git checkout -B testing localmods &&
|
|
git rebase --merge --empty=drop --keep-empty upstream &&
|
|
|
|
test_write_lines D C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --merge --empty=drop --no-keep-empty' '
|
|
git checkout -B testing localmods &&
|
|
git rebase --merge --empty=drop --no-keep-empty upstream &&
|
|
|
|
test_write_lines C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --merge --empty=keep --keep-empty' '
|
|
git checkout -B testing localmods &&
|
|
git rebase --merge --empty=keep --keep-empty upstream &&
|
|
|
|
test_write_lines D C2 C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --merge --empty=keep --no-keep-empty' '
|
|
git checkout -B testing localmods &&
|
|
git rebase --merge --empty=keep --no-keep-empty upstream &&
|
|
|
|
test_write_lines C2 C B A >expect &&
|
|
git log --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rebase --merge does not leave state laying around' '
|
|
git checkout -B testing localmods~2 &&
|
|
git rebase --merge upstream &&
|
|
|
|
test_path_is_missing .git/CHERRY_PICK_HEAD &&
|
|
test_path_is_missing .git/MERGE_MSG
|
|
'
|
|
|
|
test_done
|