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