]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7419-submodule-set-branch.sh
Merge branch 'rs/bisect-start-leakfix' into maint-2.38
[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
DL
13TEST_NO_CREATE_REPO=1
14. ./test-lib.sh
15
0d3beb71
TB
16test_expect_success 'setup' '
17 git config --global protocol.file.allow always
18'
19
b57e8119
DL
20test_expect_success 'submodule config cache setup' '
21 mkdir submodule &&
22 (cd submodule &&
23 git init &&
24 echo a >a &&
25 git add . &&
26 git commit -ma &&
27 git checkout -b topic &&
28 echo b >a &&
29 git add . &&
30 git commit -mb
31 ) &&
32 mkdir super &&
33 (cd super &&
34 git init &&
35 git submodule add ../submodule &&
36 git commit -m "add submodule"
37 )
38'
39
40test_expect_success 'ensure submodule branch is unset' '
41 (cd super &&
a8e2c0ea 42 ! grep branch .gitmodules
b57e8119
DL
43 )
44'
45
46test_expect_success 'test submodule set-branch --branch' '
47 (cd super &&
48 git submodule set-branch --branch topic submodule &&
49 grep "branch = topic" .gitmodules &&
50 git submodule update --remote &&
51 cat <<-\EOF >expect &&
52 b
53 EOF
54 git -C submodule show -s --pretty=%s >actual &&
55 test_cmp expect actual
56 )
57'
58
59test_expect_success 'test submodule set-branch --default' '
f0a96e8d 60 test_commit -C submodule c &&
b57e8119
DL
61 (cd super &&
62 git submodule set-branch --default submodule &&
a8e2c0ea 63 ! grep branch .gitmodules &&
b57e8119
DL
64 git submodule update --remote &&
65 cat <<-\EOF >expect &&
f0a96e8d 66 c
b57e8119
DL
67 EOF
68 git -C submodule show -s --pretty=%s >actual &&
69 test_cmp expect actual
70 )
71'
72
73test_expect_success 'test submodule set-branch -b' '
f0a96e8d 74 test_commit -C submodule b &&
b57e8119
DL
75 (cd super &&
76 git submodule set-branch -b topic submodule &&
77 grep "branch = topic" .gitmodules &&
78 git submodule update --remote &&
79 cat <<-\EOF >expect &&
80 b
81 EOF
82 git -C submodule show -s --pretty=%s >actual &&
83 test_cmp expect actual
84 )
85'
86
87test_expect_success 'test submodule set-branch -d' '
f0a96e8d 88 test_commit -C submodule d &&
b57e8119
DL
89 (cd super &&
90 git submodule set-branch -d submodule &&
a8e2c0ea 91 ! grep branch .gitmodules &&
b57e8119
DL
92 git submodule update --remote &&
93 cat <<-\EOF >expect &&
f0a96e8d 94 d
b57e8119
DL
95 EOF
96 git -C submodule show -s --pretty=%s >actual &&
97 test_cmp expect actual
98 )
99'
100
101test_done