| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2008 Johannes Schindelin |
| 4 | # |
| 5 | |
| 6 | test_description='Test rebasing, stashing, etc. with submodules' |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success setup ' |
| 11 | |
| 12 | echo file > file && |
| 13 | git add file && |
| 14 | test_tick && |
| 15 | git commit -m initial && |
| 16 | git clone . submodule && |
| 17 | git add submodule && |
| 18 | test_tick && |
| 19 | git commit -m submodule && |
| 20 | echo second line >> file && |
| 21 | (cd submodule && git pull) && |
| 22 | test_tick && |
| 23 | git commit -m file-and-submodule -a && |
| 24 | git branch added-submodule |
| 25 | |
| 26 | ' |
| 27 | |
| 28 | test_expect_success 'rebase with a dirty submodule' ' |
| 29 | |
| 30 | (cd submodule && |
| 31 | echo 3rd line >> file && |
| 32 | test_tick && |
| 33 | git commit -m fork -a) && |
| 34 | echo unrelated >> file2 && |
| 35 | git add file2 && |
| 36 | test_tick && |
| 37 | git commit -m unrelated file2 && |
| 38 | echo other line >> file && |
| 39 | test_tick && |
| 40 | git commit -m update file && |
| 41 | CURRENT=$(cd submodule && git rev-parse HEAD) && |
| 42 | EXPECTED=$(git rev-parse HEAD~2:submodule) && |
| 43 | GIT_TRACE=1 git rebase --onto HEAD~2 HEAD^ && |
| 44 | STORED=$(git rev-parse HEAD:submodule) && |
| 45 | test $EXPECTED = $STORED && |
| 46 | test $CURRENT = $(cd submodule && git rev-parse HEAD) |
| 47 | |
| 48 | ' |
| 49 | |
| 50 | cat > fake-editor.sh << \EOF |
| 51 | #!/bin/sh |
| 52 | echo $EDITOR_TEXT |
| 53 | EOF |
| 54 | chmod a+x fake-editor.sh |
| 55 | |
| 56 | test_expect_success 'interactive rebase with a dirty submodule' ' |
| 57 | |
| 58 | echo submodule >expect && |
| 59 | git diff --name-only >actual && |
| 60 | test_cmp expect actual && |
| 61 | HEAD=$(git rev-parse HEAD) && |
| 62 | GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \ |
| 63 | git rebase -i HEAD^ && |
| 64 | echo submodule >expect && |
| 65 | git diff --name-only >actual && |
| 66 | test_cmp expect actual |
| 67 | ' |
| 68 | |
| 69 | test_expect_success 'rebase with dirty file and submodule fails' ' |
| 70 | |
| 71 | echo yet another line >> file && |
| 72 | test_tick && |
| 73 | git commit -m next file && |
| 74 | echo rewrite > file && |
| 75 | test_tick && |
| 76 | git commit -m rewrite file && |
| 77 | echo dirty > file && |
| 78 | test_must_fail git rebase --onto HEAD~2 HEAD^ |
| 79 | |
| 80 | ' |
| 81 | |
| 82 | test_expect_success 'stash with a dirty submodule' ' |
| 83 | |
| 84 | echo new > file && |
| 85 | CURRENT=$(cd submodule && git rev-parse HEAD) && |
| 86 | git stash && |
| 87 | test new != $(cat file) && |
| 88 | echo submodule >expect && |
| 89 | git diff --name-only >actual && |
| 90 | test_cmp expect actual && |
| 91 | |
| 92 | echo "$CURRENT" >expect && |
| 93 | git -C submodule rev-parse HEAD >actual && |
| 94 | test_cmp expect actual && |
| 95 | |
| 96 | git stash apply && |
| 97 | test new = $(cat file) && |
| 98 | echo "$CURRENT" >expect && |
| 99 | git -C submodule rev-parse HEAD >actual && |
| 100 | test_cmp expect actual |
| 101 | |
| 102 | ' |
| 103 | |
| 104 | test_expect_success 'rebasing submodule that should conflict' ' |
| 105 | git reset --hard && |
| 106 | git checkout added-submodule && |
| 107 | git add submodule && |
| 108 | test_tick && |
| 109 | git commit -m third && |
| 110 | ( |
| 111 | cd submodule && |
| 112 | git commit --allow-empty -m extra |
| 113 | ) && |
| 114 | git add submodule && |
| 115 | test_tick && |
| 116 | git commit -m fourth && |
| 117 | |
| 118 | test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 2>actual_output && |
| 119 | git ls-files -s submodule >actual && |
| 120 | ( |
| 121 | cd submodule && |
| 122 | echo "160000 $(git rev-parse HEAD^) 1 submodule" && |
| 123 | echo "160000 $(git rev-parse HEAD^^) 2 submodule" && |
| 124 | echo "160000 $(git rev-parse HEAD) 3 submodule" |
| 125 | ) >expect && |
| 126 | test_cmp expect actual && |
| 127 | sub_expect="go to submodule (submodule), and either merge commit $(git -C submodule rev-parse --short HEAD^0)" && |
| 128 | grep "$sub_expect" actual_output |
| 129 | ' |
| 130 | |
| 131 | test_done |