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