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