d7d90885e0
When running a command with the 'exec' instruction during an interactive rebase session, or for a range of commits using 'git rebase -x', the output can be a bit garbled when the name of the command is short enough: $ git rebase -x true HEAD~5 Executing: true Executing: true Executing: true Executing: true Executing: true) Successfully rebased and updated refs/heads/master. Note the ')' at the end of the last line. It gets more garbled as the range of commits increases: $ git rebase -x true HEAD~50 Executing: true) [ repeated 3 more times ] Executing: true0) [ repeated 44 more times ] Executing: true00) Successfully rebased and updated refs/heads/master. Those extra numbers and ')' are remnants of the previously displayed "Rebasing (N/M)" progress lines that are usually completely overwritten by the "Executing: <cmd>" lines, unless 'cmd' is short and the "N/M" part is long. Make sure that the previously displayed "Rebasing (N/M)" line is cleared by using the term_clear_line() helper function added in the previous patch. Do so only when not being '--verbose', because in that case these "Rebasing (N/M)" lines are not printed as progress (i.e. as lines with '\r' at the end), but as "regular" output (with '\n' at the end). A couple of other rebase commands print similar messages, e.g. "Stopped at <abbrev-oid>... <subject>" for the 'edit' or 'break' commands, or the "Successfully rebased and updated <full-ref>." at the very end. These are so long that they practically always overwrite that "Rebasing (N/M)" progress line, but let's be prudent, and clear the last line before printing these, too. In 't3420-rebase-autostash.sh' two helper functions prepare the expected output of four tests that check the full output of 'git rebase' and thus are affected by this change, so adjust their expectations to account for the new line clearing. Note that this patch doesn't completely eliminate the possibility of similar garbled outputs, e.g. some error messages from rebase or the "Auto-merging <file>" message from within the depths of the merge machinery might not be long enough to completely cover the last "Rebasing (N/M)" line. This patch doesn't do anything about them, because dealing with them individually would result in way too much churn, while having a catch-all term_clear_line() call in the common code path of pick_commits() would hide the "Rebasing (N/M)" line way too soon, and it would either flicker or be invisible. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
307 lines
9.2 KiB
Bash
Executable File
307 lines
9.2 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2013 Ramkumar Ramachandra
|
|
#
|
|
|
|
test_description='git rebase --autostash tests'
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success setup '
|
|
echo hello-world >file0 &&
|
|
git add . &&
|
|
test_tick &&
|
|
git commit -m "initial commit" &&
|
|
git checkout -b feature-branch &&
|
|
echo another-hello >file1 &&
|
|
echo goodbye >file2 &&
|
|
git add . &&
|
|
test_tick &&
|
|
git commit -m "second commit" &&
|
|
echo final-goodbye >file3 &&
|
|
git add . &&
|
|
test_tick &&
|
|
git commit -m "third commit" &&
|
|
git checkout -b unrelated-onto-branch master &&
|
|
echo unrelated >file4 &&
|
|
git add . &&
|
|
test_tick &&
|
|
git commit -m "unrelated commit" &&
|
|
git checkout -b related-onto-branch master &&
|
|
echo conflicting-change >file2 &&
|
|
git add . &&
|
|
test_tick &&
|
|
git commit -m "related commit"
|
|
'
|
|
|
|
create_expected_success_am () {
|
|
cat >expected <<-EOF
|
|
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
|
|
HEAD is now at $(git rev-parse --short feature-branch) third commit
|
|
First, rewinding head to replay your work on top of it...
|
|
Applying: second commit
|
|
Applying: third commit
|
|
Applied autostash.
|
|
EOF
|
|
}
|
|
|
|
create_expected_success_interactive () {
|
|
q_to_cr >expected <<-EOF
|
|
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
|
|
HEAD is now at $(git rev-parse --short feature-branch) third commit
|
|
Rebasing (1/2)QRebasing (2/2)QApplied autostash.
|
|
Q QSuccessfully rebased and updated refs/heads/rebased-feature-branch.
|
|
EOF
|
|
}
|
|
|
|
create_expected_failure_am () {
|
|
cat >expected <<-EOF
|
|
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
|
|
HEAD is now at $(git rev-parse --short feature-branch) third commit
|
|
First, rewinding head to replay your work on top of it...
|
|
Applying: second commit
|
|
Applying: third commit
|
|
Applying autostash resulted in conflicts.
|
|
Your changes are safe in the stash.
|
|
You can run "git stash pop" or "git stash drop" at any time.
|
|
EOF
|
|
}
|
|
|
|
create_expected_failure_interactive () {
|
|
q_to_cr >expected <<-EOF
|
|
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
|
|
HEAD is now at $(git rev-parse --short feature-branch) third commit
|
|
Rebasing (1/2)QRebasing (2/2)QApplying autostash resulted in conflicts.
|
|
Your changes are safe in the stash.
|
|
You can run "git stash pop" or "git stash drop" at any time.
|
|
Q QSuccessfully rebased and updated refs/heads/rebased-feature-branch.
|
|
EOF
|
|
}
|
|
|
|
testrebase () {
|
|
type=$1
|
|
dotest=$2
|
|
|
|
test_expect_success "rebase$type: dirty worktree, --no-autostash" '
|
|
test_config rebase.autostash true &&
|
|
git reset --hard &&
|
|
git checkout -b rebased-feature-branch feature-branch &&
|
|
test_when_finished git branch -D rebased-feature-branch &&
|
|
test_when_finished git checkout feature-branch &&
|
|
echo dirty >>file3 &&
|
|
test_must_fail git rebase$type --no-autostash unrelated-onto-branch
|
|
'
|
|
|
|
test_expect_success "rebase$type: dirty worktree, non-conflicting rebase" '
|
|
test_config rebase.autostash true &&
|
|
git reset --hard &&
|
|
git checkout -b rebased-feature-branch feature-branch &&
|
|
echo dirty >>file3 &&
|
|
git rebase$type unrelated-onto-branch >actual 2>&1 &&
|
|
grep unrelated file4 &&
|
|
grep dirty file3 &&
|
|
git checkout feature-branch
|
|
'
|
|
|
|
test_expect_success "rebase$type --autostash: check output" '
|
|
test_when_finished git branch -D rebased-feature-branch &&
|
|
suffix=${type#\ --} && suffix=${suffix:-am} &&
|
|
if test ${suffix} = "merge"; then
|
|
suffix=interactive
|
|
fi &&
|
|
create_expected_success_$suffix &&
|
|
test_i18ncmp expected actual
|
|
'
|
|
|
|
test_expect_success "rebase$type: dirty index, non-conflicting rebase" '
|
|
test_config rebase.autostash true &&
|
|
git reset --hard &&
|
|
git checkout -b rebased-feature-branch feature-branch &&
|
|
test_when_finished git branch -D rebased-feature-branch &&
|
|
echo dirty >>file3 &&
|
|
git add file3 &&
|
|
git rebase$type unrelated-onto-branch &&
|
|
grep unrelated file4 &&
|
|
grep dirty file3 &&
|
|
git checkout feature-branch
|
|
'
|
|
|
|
test_expect_success "rebase$type: conflicting rebase" '
|
|
test_config rebase.autostash true &&
|
|
git reset --hard &&
|
|
git checkout -b rebased-feature-branch feature-branch &&
|
|
test_when_finished git branch -D rebased-feature-branch &&
|
|
echo dirty >>file3 &&
|
|
test_must_fail git rebase$type related-onto-branch &&
|
|
test_path_is_file $dotest/autostash &&
|
|
test_path_is_missing file3 &&
|
|
rm -rf $dotest &&
|
|
git reset --hard &&
|
|
git checkout feature-branch
|
|
'
|
|
|
|
test_expect_success "rebase$type: --continue" '
|
|
test_config rebase.autostash true &&
|
|
git reset --hard &&
|
|
git checkout -b rebased-feature-branch feature-branch &&
|
|
test_when_finished git branch -D rebased-feature-branch &&
|
|
echo dirty >>file3 &&
|
|
test_must_fail git rebase$type related-onto-branch &&
|
|
test_path_is_file $dotest/autostash &&
|
|
test_path_is_missing file3 &&
|
|
echo "conflicting-plus-goodbye" >file2 &&
|
|
git add file2 &&
|
|
git rebase --continue &&
|
|
test_path_is_missing $dotest/autostash &&
|
|
grep dirty file3 &&
|
|
git checkout feature-branch
|
|
'
|
|
|
|
test_expect_success "rebase$type: --skip" '
|
|
test_config rebase.autostash true &&
|
|
git reset --hard &&
|
|
git checkout -b rebased-feature-branch feature-branch &&
|
|
test_when_finished git branch -D rebased-feature-branch &&
|
|
echo dirty >>file3 &&
|
|
test_must_fail git rebase$type related-onto-branch &&
|
|
test_path_is_file $dotest/autostash &&
|
|
test_path_is_missing file3 &&
|
|
git rebase --skip &&
|
|
test_path_is_missing $dotest/autostash &&
|
|
grep dirty file3 &&
|
|
git checkout feature-branch
|
|
'
|
|
|
|
test_expect_success "rebase$type: --abort" '
|
|
test_config rebase.autostash true &&
|
|
git reset --hard &&
|
|
git checkout -b rebased-feature-branch feature-branch &&
|
|
test_when_finished git branch -D rebased-feature-branch &&
|
|
echo dirty >>file3 &&
|
|
test_must_fail git rebase$type related-onto-branch &&
|
|
test_path_is_file $dotest/autostash &&
|
|
test_path_is_missing file3 &&
|
|
git rebase --abort &&
|
|
test_path_is_missing $dotest/autostash &&
|
|
grep dirty file3 &&
|
|
git checkout feature-branch
|
|
'
|
|
|
|
test_expect_success "rebase$type: non-conflicting rebase, conflicting stash" '
|
|
test_config rebase.autostash true &&
|
|
git reset --hard &&
|
|
git checkout -b rebased-feature-branch feature-branch &&
|
|
echo dirty >file4 &&
|
|
git add file4 &&
|
|
git rebase$type unrelated-onto-branch >actual 2>&1 &&
|
|
test_path_is_missing $dotest &&
|
|
git reset --hard &&
|
|
grep unrelated file4 &&
|
|
! grep dirty file4 &&
|
|
git checkout feature-branch &&
|
|
git stash pop &&
|
|
grep dirty file4
|
|
'
|
|
|
|
test_expect_success "rebase$type: check output with conflicting stash" '
|
|
test_when_finished git branch -D rebased-feature-branch &&
|
|
suffix=${type#\ --} && suffix=${suffix:-am} &&
|
|
if test ${suffix} = "merge"; then
|
|
suffix=interactive
|
|
fi &&
|
|
create_expected_failure_$suffix &&
|
|
test_i18ncmp expected actual
|
|
'
|
|
}
|
|
|
|
test_expect_success "rebase: fast-forward rebase" '
|
|
test_config rebase.autostash true &&
|
|
git reset --hard &&
|
|
git checkout -b behind-feature-branch feature-branch~1 &&
|
|
test_when_finished git branch -D behind-feature-branch &&
|
|
echo dirty >>file1 &&
|
|
git rebase feature-branch &&
|
|
grep dirty file1 &&
|
|
git checkout feature-branch
|
|
'
|
|
|
|
test_expect_success "rebase: noop rebase" '
|
|
test_config rebase.autostash true &&
|
|
git reset --hard &&
|
|
git checkout -b same-feature-branch feature-branch &&
|
|
test_when_finished git branch -D same-feature-branch &&
|
|
echo dirty >>file1 &&
|
|
git rebase feature-branch &&
|
|
grep dirty file1 &&
|
|
git checkout feature-branch
|
|
'
|
|
|
|
testrebase "" .git/rebase-apply
|
|
testrebase " --merge" .git/rebase-merge
|
|
testrebase " --interactive" .git/rebase-merge
|
|
|
|
test_expect_success 'abort rebase -i with --autostash' '
|
|
test_when_finished "git reset --hard" &&
|
|
echo uncommitted-content >file0 &&
|
|
(
|
|
write_script abort-editor.sh <<-\EOF &&
|
|
echo >"$1"
|
|
EOF
|
|
test_set_editor "$(pwd)/abort-editor.sh" &&
|
|
test_must_fail git rebase -i --autostash HEAD^ &&
|
|
rm -f abort-editor.sh
|
|
) &&
|
|
echo uncommitted-content >expected &&
|
|
test_cmp expected file0
|
|
'
|
|
|
|
test_expect_success 'restore autostash on editor failure' '
|
|
test_when_finished "git reset --hard" &&
|
|
echo uncommitted-content >file0 &&
|
|
(
|
|
test_set_editor "false" &&
|
|
test_must_fail git rebase -i --autostash HEAD^
|
|
) &&
|
|
echo uncommitted-content >expected &&
|
|
test_cmp expected file0
|
|
'
|
|
|
|
test_expect_success 'autostash is saved on editor failure with conflict' '
|
|
test_when_finished "git reset --hard" &&
|
|
echo uncommitted-content >file0 &&
|
|
(
|
|
write_script abort-editor.sh <<-\EOF &&
|
|
echo conflicting-content >file0
|
|
exit 1
|
|
EOF
|
|
test_set_editor "$(pwd)/abort-editor.sh" &&
|
|
test_must_fail git rebase -i --autostash HEAD^ &&
|
|
rm -f abort-editor.sh
|
|
) &&
|
|
echo conflicting-content >expected &&
|
|
test_cmp expected file0 &&
|
|
git checkout file0 &&
|
|
git stash pop &&
|
|
echo uncommitted-content >expected &&
|
|
test_cmp expected file0
|
|
'
|
|
|
|
test_expect_success 'autostash with dirty submodules' '
|
|
test_when_finished "git reset --hard && git checkout master" &&
|
|
git checkout -b with-submodule &&
|
|
git submodule add ./ sub &&
|
|
test_tick &&
|
|
git commit -m add-submodule &&
|
|
echo changed >sub/file0 &&
|
|
git rebase -i --autostash HEAD
|
|
'
|
|
|
|
test_expect_success 'branch is left alone when possible' '
|
|
git checkout -b unchanged-branch &&
|
|
echo changed >file0 &&
|
|
git rebase --autostash unchanged-branch &&
|
|
test changed = "$(cat file0)" &&
|
|
test unchanged-branch = "$(git rev-parse --abbrev-ref HEAD)"
|
|
'
|
|
|
|
test_done
|