Fourth batch
[gitweb.git] / t / t3420-rebase-autostash.sh
index 827ea7f8b4e28e7c7ae886c45883d21f26455226..5f7e73cf83a267cd3dc74917c963352fe9a1856d 100755 (executable)
@@ -30,13 +30,13 @@ test_expect_success setup '
        echo conflicting-change >file2 &&
        git add . &&
        test_tick &&
-       git commit -m "related commit"
+       git commit -m "related commit" &&
+       remove_progress_re="$(printf "s/.*\\r//")"
 '
 
 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
@@ -47,44 +47,30 @@ create_expected_success_am () {
 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.
+       Applied autostash.
        Successfully rebased and updated refs/heads/rebased-feature-branch.
        EOF
 }
 
-create_expected_success_merge () {
+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...
-       Merging unrelated-onto-branch with HEAD~1
-       Merging:
-       $(git rev-parse --short unrelated-onto-branch) unrelated commit
-       $(git rev-parse --short feature-branch^) second commit
-       found 1 common ancestor:
-       $(git rev-parse --short feature-branch~2) initial commit
-       [detached HEAD $(git rev-parse --short rebased-feature-branch~1)] second commit
-        Author: A U Thor <author@example.com>
-        Date: Thu Apr 7 15:14:13 2005 -0700
-        2 files changed, 2 insertions(+)
-        create mode 100644 file1
-        create mode 100644 file2
-       Committed: 0001 second commit
-       Merging unrelated-onto-branch with HEAD~0
-       Merging:
-       $(git rev-parse --short rebased-feature-branch~1) second commit
-       $(git rev-parse --short feature-branch) third commit
-       found 1 common ancestor:
-       $(git rev-parse --short feature-branch~1) second commit
-       [detached HEAD $(git rev-parse --short rebased-feature-branch)] third commit
-        Author: A U Thor <author@example.com>
-        Date: Thu Apr 7 15:15:13 2005 -0700
-        1 file changed, 1 insertion(+)
-        create mode 100644 file3
-       Committed: 0002 third commit
-       All done.
-       Applied autostash.
+       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 () {
+       cat >expected <<-EOF
+       $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
+       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.
+       Successfully rebased and updated refs/heads/rebased-feature-branch.
        EOF
 }
 
@@ -116,8 +102,12 @@ testrebase () {
        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_cmp expected actual
+               sed "$remove_progress_re" <actual >actual2 &&
+               test_i18ncmp expected actual2
        '
 
        test_expect_success "rebase$type: dirty index, non-conflicting rebase" '
@@ -141,7 +131,7 @@ testrebase () {
                echo dirty >>file3 &&
                test_must_fail git rebase$type related-onto-branch &&
                test_path_is_file $dotest/autostash &&
-               ! grep dirty file3 &&
+               test_path_is_missing file3 &&
                rm -rf $dotest &&
                git reset --hard &&
                git checkout feature-branch
@@ -155,7 +145,7 @@ testrebase () {
                echo dirty >>file3 &&
                test_must_fail git rebase$type related-onto-branch &&
                test_path_is_file $dotest/autostash &&
-               ! grep dirty file3 &&
+               test_path_is_missing file3 &&
                echo "conflicting-plus-goodbye" >file2 &&
                git add file2 &&
                git rebase --continue &&
@@ -172,7 +162,7 @@ testrebase () {
                echo dirty >>file3 &&
                test_must_fail git rebase$type related-onto-branch &&
                test_path_is_file $dotest/autostash &&
-               ! grep dirty file3 &&
+               test_path_is_missing file3 &&
                git rebase --skip &&
                test_path_is_missing $dotest/autostash &&
                grep dirty file3 &&
@@ -187,7 +177,7 @@ testrebase () {
                echo dirty >>file3 &&
                test_must_fail git rebase$type related-onto-branch &&
                test_path_is_file $dotest/autostash &&
-               ! grep dirty file3 &&
+               test_path_is_missing file3 &&
                git rebase --abort &&
                test_path_is_missing $dotest/autostash &&
                grep dirty file3 &&
@@ -198,10 +188,9 @@ testrebase () {
                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 >file4 &&
                git add file4 &&
-               git rebase$type unrelated-onto-branch &&
+               git rebase$type unrelated-onto-branch >actual 2>&1 &&
                test_path_is_missing $dotest &&
                git reset --hard &&
                grep unrelated file4 &&
@@ -210,6 +199,17 @@ testrebase () {
                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 &&
+               sed "$remove_progress_re" <actual >actual2 &&
+               test_i18ncmp expected actual2
+       '
 }
 
 test_expect_success "rebase: fast-forward rebase" '
@@ -284,4 +284,30 @@ test_expect_success 'autostash is saved on editor failure with conflict' '
        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_expect_success 'never change active branch' '
+       git checkout -b not-the-feature-branch unrelated-onto-branch &&
+       test_when_finished "git reset --hard && git checkout master" &&
+       echo changed >file0 &&
+       git rebase --autostash not-the-feature-branch feature-branch &&
+       test_cmp_rev not-the-feature-branch unrelated-onto-branch
+'
+
 test_done