]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7419-submodule-set-branch.sh
Sync with 2.36.3
[thirdparty/git.git] / t / t7419-submodule-set-branch.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Denton Liu
4 #
5
6 test_description='Test submodules set-branch subcommand
7
8 This test verifies that the set-branch subcommand of git-submodule is working
9 as expected.
10 '
11
12 TEST_NO_CREATE_REPO=1
13 . ./test-lib.sh
14
15 test_expect_success 'setup' '
16 git config --global protocol.file.allow always
17 '
18
19 test_expect_success 'submodule config cache setup' '
20 mkdir submodule &&
21 (cd submodule &&
22 git init &&
23 echo a >a &&
24 git add . &&
25 git commit -ma &&
26 git checkout -b topic &&
27 echo b >a &&
28 git add . &&
29 git commit -mb
30 ) &&
31 mkdir super &&
32 (cd super &&
33 git init &&
34 git submodule add ../submodule &&
35 git commit -m "add submodule"
36 )
37 '
38
39 test_expect_success 'ensure submodule branch is unset' '
40 (cd super &&
41 ! grep branch .gitmodules
42 )
43 '
44
45 test_expect_success 'test submodule set-branch --branch' '
46 (cd super &&
47 git submodule set-branch --branch topic submodule &&
48 grep "branch = topic" .gitmodules &&
49 git submodule update --remote &&
50 cat <<-\EOF >expect &&
51 b
52 EOF
53 git -C submodule show -s --pretty=%s >actual &&
54 test_cmp expect actual
55 )
56 '
57
58 test_expect_success 'test submodule set-branch --default' '
59 test_commit -C submodule c &&
60 (cd super &&
61 git submodule set-branch --default submodule &&
62 ! grep branch .gitmodules &&
63 git submodule update --remote &&
64 cat <<-\EOF >expect &&
65 c
66 EOF
67 git -C submodule show -s --pretty=%s >actual &&
68 test_cmp expect actual
69 )
70 '
71
72 test_expect_success 'test submodule set-branch -b' '
73 test_commit -C submodule b &&
74 (cd super &&
75 git submodule set-branch -b topic submodule &&
76 grep "branch = topic" .gitmodules &&
77 git submodule update --remote &&
78 cat <<-\EOF >expect &&
79 b
80 EOF
81 git -C submodule show -s --pretty=%s >actual &&
82 test_cmp expect actual
83 )
84 '
85
86 test_expect_success 'test submodule set-branch -d' '
87 test_commit -C submodule d &&
88 (cd super &&
89 git submodule set-branch -d submodule &&
90 ! grep branch .gitmodules &&
91 git submodule update --remote &&
92 cat <<-\EOF >expect &&
93 d
94 EOF
95 git -C submodule show -s --pretty=%s >actual &&
96 test_cmp expect actual
97 )
98 '
99
100 test_done