lockfile: replace random() by rand()
[git/debian.git] / t / t7402-submodule-rebase.sh
blob8e32f190077474274dc5046df5a64f837ee696f3
1 #!/bin/sh
3 # Copyright (c) 2008 Johannes Schindelin
6 test_description='Test rebasing, stashing, etc. with submodules'
8 . ./test-lib.sh
10 test_expect_success setup '
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
28 test_expect_success 'rebase with a dirty submodule' '
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)
50 cat > fake-editor.sh << \EOF
51 #!/bin/sh
52 echo $EDITOR_TEXT
53 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 &&
69 test_tick &&
70 git commit -m next file &&
71 echo rewrite > file &&
72 test_tick &&
73 git commit -m rewrite file &&
74 echo dirty > file &&
75 test_must_fail git rebase --onto HEAD~2 HEAD^
79 test_expect_success 'stash with a dirty submodule' '
81 echo new > file &&
82 CURRENT=$(cd submodule && git rev-parse HEAD) &&
83 git stash &&
84 test new != $(cat file) &&
85 test submodule = $(git diff --name-only) &&
86 test $CURRENT = $(cd submodule && git rev-parse HEAD) &&
87 git stash apply &&
88 test new = $(cat file) &&
89 test $CURRENT = $(cd submodule && git rev-parse HEAD)
93 test_expect_success 'rebasing submodule that should conflict' '
94 git reset --hard &&
95 git checkout added-submodule &&
96 git add submodule &&
97 test_tick &&
98 git commit -m third &&
100 cd submodule &&
101 git commit --allow-empty -m extra
102 ) &&
103 git add submodule &&
104 test_tick &&
105 git commit -m fourth &&
107 test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 &&
108 git ls-files -s submodule >actual &&
110 cd submodule &&
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"
114 ) >expect &&
115 test_cmp expect actual
118 test_done