]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7419-submodule-set-branch.sh
Git 2.45
[thirdparty/git.git] / t / t7419-submodule-set-branch.sh
CommitLineData
b57e8119
DL
1#!/bin/sh
2#
3# Copyright (c) 2019 Denton Liu
4#
5
6test_description='Test submodules set-branch subcommand
7
8This test verifies that the set-branch subcommand of git-submodule is working
9as expected.
10'
11
d40c42e0 12TEST_PASSES_SANITIZE_LEAK=true
b57e8119 13TEST_NO_CREATE_REPO=1
b027fb07
JAS
14
15GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
16export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
17
b57e8119
DL
18. ./test-lib.sh
19
0d3beb71
TB
20test_expect_success 'setup' '
21 git config --global protocol.file.allow always
22'
23
b57e8119
DL
24test_expect_success 'submodule config cache setup' '
25 mkdir submodule &&
26 (cd submodule &&
27 git init &&
28 echo a >a &&
29 git add . &&
30 git commit -ma &&
31 git checkout -b topic &&
32 echo b >a &&
33 git add . &&
b027fb07
JAS
34 git commit -mb &&
35 git checkout main
b57e8119
DL
36 ) &&
37 mkdir super &&
38 (cd super &&
39 git init &&
40 git submodule add ../submodule &&
32bff367
JAS
41 git submodule add --name thename ../submodule thepath &&
42 git commit -m "add submodules"
b57e8119
DL
43 )
44'
45
46test_expect_success 'ensure submodule branch is unset' '
47 (cd super &&
5fc88063 48 test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch
b57e8119
DL
49 )
50'
51
52test_expect_success 'test submodule set-branch --branch' '
53 (cd super &&
54 git submodule set-branch --branch topic submodule &&
5fc88063 55 test_cmp_config topic -f .gitmodules submodule.submodule.branch &&
b57e8119
DL
56 git submodule update --remote &&
57 cat <<-\EOF >expect &&
58 b
59 EOF
60 git -C submodule show -s --pretty=%s >actual &&
61 test_cmp expect actual
62 )
63'
64
65test_expect_success 'test submodule set-branch --default' '
66 (cd super &&
67 git submodule set-branch --default submodule &&
5fc88063 68 test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch &&
b57e8119
DL
69 git submodule update --remote &&
70 cat <<-\EOF >expect &&
b027fb07 71 a
b57e8119
DL
72 EOF
73 git -C submodule show -s --pretty=%s >actual &&
74 test_cmp expect actual
75 )
76'
77
78test_expect_success 'test submodule set-branch -b' '
79 (cd super &&
80 git submodule set-branch -b topic submodule &&
5fc88063 81 test_cmp_config topic -f .gitmodules submodule.submodule.branch &&
b57e8119
DL
82 git submodule update --remote &&
83 cat <<-\EOF >expect &&
84 b
85 EOF
86 git -C submodule show -s --pretty=%s >actual &&
87 test_cmp expect actual
88 )
89'
90
91test_expect_success 'test submodule set-branch -d' '
92 (cd super &&
93 git submodule set-branch -d submodule &&
5fc88063 94 test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch &&
b57e8119
DL
95 git submodule update --remote &&
96 cat <<-\EOF >expect &&
b027fb07 97 a
b57e8119
DL
98 EOF
99 git -C submodule show -s --pretty=%s >actual &&
100 test_cmp expect actual
101 )
102'
103
32bff367
JAS
104test_expect_success 'test submodule set-branch --branch with named submodule' '
105 (cd super &&
106 git submodule set-branch --branch topic thepath &&
107 test_cmp_config topic -f .gitmodules submodule.thename.branch &&
108 test_cmp_config "" -f .gitmodules --default "" submodule.thepath.branch &&
109 git submodule update --remote &&
110 cat <<-\EOF >expect &&
111 b
112 EOF
113 git -C thepath show -s --pretty=%s >actual &&
114 test_cmp expect actual
115 )
116'
117
118test_expect_success 'test submodule set-branch --default with named submodule' '
119 (cd super &&
120 git submodule set-branch --default thepath &&
121 test_cmp_config "" -f .gitmodules --default "" submodule.thename.branch &&
122 git submodule update --remote &&
123 cat <<-\EOF >expect &&
124 a
125 EOF
126 git -C thepath show -s --pretty=%s >actual &&
127 test_cmp expect actual
128 )
129'
130
b57e8119 131test_done