Sync with 2.36.6
[git/debian.git] / t / t7419-submodule-set-branch.sh
blob5357093e98ffbd1508d4e98c0e7ed904c789d119
1 #!/bin/sh
3 # Copyright (c) 2019 Denton Liu
6 test_description='Test submodules set-branch subcommand
8 This test verifies that the set-branch subcommand of git-submodule is working
9 as expected.
12 TEST_NO_CREATE_REPO=1
13 . ./test-lib.sh
15 test_expect_success 'setup' '
16 git config --global protocol.file.allow always
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"
39 test_expect_success 'ensure submodule branch is unset' '
40 (cd super &&
41 ! grep branch .gitmodules
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 &&
52 EOF
53 git -C submodule show -s --pretty=%s >actual &&
54 test_cmp expect actual
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 &&
66 EOF
67 git -C submodule show -s --pretty=%s >actual &&
68 test_cmp expect actual
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 &&
80 EOF
81 git -C submodule show -s --pretty=%s >actual &&
82 test_cmp expect actual
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 &&
94 EOF
95 git -C submodule show -s --pretty=%s >actual &&
96 test_cmp expect actual
100 test_done