Sync with 2.39.4
[git.git] / t / t7402-submodule-rebase.sh
blobb19792b326901bbb8c00c20f07dbb38b322a9e74
1 #!/bin/sh
3 # Copyright (c) 2008 Johannes Schindelin
6 test_description='Test rebasing, stashing, etc. with submodules'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success setup '
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
29 test_expect_success 'rebase with a dirty submodule' '
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)
51 cat > fake-editor.sh << \EOF
52 #!/bin/sh
53 echo $EDITOR_TEXT
54 EOF
55 chmod a+x fake-editor.sh
57 test_expect_success 'interactive rebase with a dirty submodule' '
59 test submodule = $(git diff --name-only) &&
60 HEAD=$(git rev-parse HEAD) &&
61 GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \
62 git rebase -i HEAD^ &&
63 test submodule = $(git diff --name-only)
67 test_expect_success 'rebase with dirty file and submodule fails' '
69 echo yet another line >> file &&
70 test_tick &&
71 git commit -m next file &&
72 echo rewrite > file &&
73 test_tick &&
74 git commit -m rewrite file &&
75 echo dirty > file &&
76 test_must_fail git rebase --onto HEAD~2 HEAD^
80 test_expect_success 'stash with a dirty submodule' '
82 echo new > file &&
83 CURRENT=$(cd submodule && git rev-parse HEAD) &&
84 git stash &&
85 test new != $(cat file) &&
86 test submodule = $(git diff --name-only) &&
87 test $CURRENT = $(cd submodule && git rev-parse HEAD) &&
88 git stash apply &&
89 test new = $(cat file) &&
90 test $CURRENT = $(cd submodule && git rev-parse HEAD)
94 test_expect_success 'rebasing submodule that should conflict' '
95 git reset --hard &&
96 git checkout added-submodule &&
97 git add submodule &&
98 test_tick &&
99 git commit -m third &&
101 cd submodule &&
102 git commit --allow-empty -m extra
103 ) &&
104 git add submodule &&
105 test_tick &&
106 git commit -m fourth &&
108 test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 >actual_output &&
109 git ls-files -s submodule >actual &&
111 cd submodule &&
112 echo "160000 $(git rev-parse HEAD^) 1 submodule" &&
113 echo "160000 $(git rev-parse HEAD^^) 2 submodule" &&
114 echo "160000 $(git rev-parse HEAD) 3 submodule"
115 ) >expect &&
116 test_cmp expect actual &&
117 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
118 then
119 sub_expect="go to submodule (submodule), and either merge commit $(git -C submodule rev-parse --short HEAD^0)" &&
120 grep "$sub_expect" actual_output
124 test_done