3 # Copyright (c) 2008 Johannes Schindelin
6 test_description
='Test rebasing, stashing, etc. with submodules'
10 test_expect_success setup
'
15 git commit -m initial &&
16 git clone . submodule &&
19 git commit -m submodule &&
20 echo second line >> file &&
21 (cd submodule && git pull) &&
23 git commit -m file-and-submodule -a &&
24 git branch added-submodule
28 test_expect_success
'rebase with a dirty submodule' '
31 echo 3rd line >> file &&
33 git commit -m fork -a) &&
34 echo unrelated >> file2 &&
37 git commit -m unrelated file2 &&
38 echo other line >> file &&
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)
50 cat > fake-editor.sh
<< \EOF
54 chmod a
+x fake-editor.sh
56 test_expect_success
'interactive rebase with a dirty submodule' '
58 test submodule = $(git diff --name-only) &&
59 HEAD=$(git rev-parse HEAD) &&
60 GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \
61 git rebase -i HEAD^ &&
62 test submodule = $(git diff --name-only)
66 test_expect_success
'rebase with dirty file and submodule fails' '
68 echo yet another line >> file &&
70 git commit -m next file &&
71 echo rewrite > file &&
73 git commit -m rewrite file &&
75 test_must_fail git rebase --onto HEAD~2 HEAD^
79 test_expect_success
'stash with a dirty submodule' '
82 CURRENT=$(cd submodule && git rev-parse HEAD) &&
84 test new != $(cat file) &&
85 test submodule = $(git diff --name-only) &&
86 test $CURRENT = $(cd submodule && git rev-parse HEAD) &&
88 test new = $(cat file) &&
89 test $CURRENT = $(cd submodule && git rev-parse HEAD)
93 test_expect_success
'rebasing submodule that should conflict' '
95 git checkout added-submodule &&
98 git commit -m third &&
101 git commit --allow-empty -m extra
105 git commit -m fourth &&
107 test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 &&
108 git ls-files -s submodule >actual &&
111 echo "160000 $(git rev-parse HEAD^) 1 submodule" &&
112 echo "160000 $(git rev-parse HEAD^^) 2 submodule" &&
113 echo "160000 $(git rev-parse HEAD) 3 submodule"
115 test_cmp expect actual