t / t7419-submodule-set-branch.shon commit Merge branch 'jt/avoid-ls-refs-with-http' (f67bf53)
   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 &&
  37                test_must_fail grep branch .gitmodules
  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' '
  55        (cd super &&
  56                git submodule set-branch --default submodule &&
  57                test_must_fail grep branch .gitmodules &&
  58                git submodule update --remote &&
  59                cat <<-\EOF >expect &&
  60                a
  61                EOF
  62                git -C submodule show -s --pretty=%s >actual &&
  63                test_cmp expect actual
  64        )
  65'
  66
  67test_expect_success 'test submodule set-branch -b' '
  68        (cd super &&
  69                git submodule set-branch -b topic submodule &&
  70                grep "branch = topic" .gitmodules &&
  71                git submodule update --remote &&
  72                cat <<-\EOF >expect &&
  73                b
  74                EOF
  75                git -C submodule show -s --pretty=%s >actual &&
  76                test_cmp expect actual
  77        )
  78'
  79
  80test_expect_success 'test submodule set-branch -d' '
  81        (cd super &&
  82                git submodule set-branch -d submodule &&
  83                test_must_fail grep branch .gitmodules &&
  84                git submodule update --remote &&
  85                cat <<-\EOF >expect &&
  86                a
  87                EOF
  88                git -C submodule show -s --pretty=%s >actual &&
  89                test_cmp expect actual
  90        )
  91'
  92
  93test_done