t / t7413-submodule-is-active.shon commit t4000: make hash size independent (8cc5ff8)
   1#!/bin/sh
   2
   3test_description='Test submodule--helper is-active
   4
   5This test verifies that `git submodue--helper is-active` correctly identifies
   6submodules which are "active" and interesting to the user.
   7'
   8
   9. ./test-lib.sh
  10
  11test_expect_success 'setup' '
  12        git init sub &&
  13        test_commit -C sub initial &&
  14        git init super &&
  15        test_commit -C super initial &&
  16        git -C super submodule add ../sub sub1 &&
  17        git -C super submodule add ../sub sub2 &&
  18
  19        # Remove submodule.<name>.active entries in order to test in an
  20        # environment where only URLs are present in the conifg
  21        git -C super config --unset submodule.sub1.active &&
  22        git -C super config --unset submodule.sub2.active &&
  23
  24        git -C super commit -a -m "add 2 submodules at sub{1,2}"
  25'
  26
  27test_expect_success 'is-active works with urls' '
  28        git -C super submodule--helper is-active sub1 &&
  29        git -C super submodule--helper is-active sub2 &&
  30
  31        git -C super config --unset submodule.sub1.URL &&
  32        test_must_fail git -C super submodule--helper is-active sub1 &&
  33        git -C super config submodule.sub1.URL ../sub &&
  34        git -C super submodule--helper is-active sub1
  35'
  36
  37test_expect_success 'is-active works with submodule.<name>.active config' '
  38        test_when_finished "git -C super config --unset submodule.sub1.active" &&
  39        test_when_finished "git -C super config submodule.sub1.URL ../sub" &&
  40
  41        git -C super config --bool submodule.sub1.active "false" &&
  42        test_must_fail git -C super submodule--helper is-active sub1 &&
  43
  44        git -C super config --bool submodule.sub1.active "true" &&
  45        git -C super config --unset submodule.sub1.URL &&
  46        git -C super submodule--helper is-active sub1
  47'
  48
  49test_expect_success 'is-active works with basic submodule.active config' '
  50        test_when_finished "git -C super config submodule.sub1.URL ../sub" &&
  51        test_when_finished "git -C super config --unset-all submodule.active" &&
  52
  53        git -C super config --add submodule.active "." &&
  54        git -C super config --unset submodule.sub1.URL &&
  55
  56        git -C super submodule--helper is-active sub1 &&
  57        git -C super submodule--helper is-active sub2
  58'
  59
  60test_expect_success 'is-active correctly works with paths that are not submodules' '
  61        test_when_finished "git -C super config --unset-all submodule.active" &&
  62
  63        test_must_fail git -C super submodule--helper is-active not-a-submodule &&
  64
  65        git -C super config --add submodule.active "." &&
  66        test_must_fail git -C super submodule--helper is-active not-a-submodule
  67'
  68
  69test_expect_success 'is-active works with exclusions in submodule.active config' '
  70        test_when_finished "git -C super config --unset-all submodule.active" &&
  71
  72        git -C super config --add submodule.active "." &&
  73        git -C super config --add submodule.active ":(exclude)sub1" &&
  74
  75        test_must_fail git -C super submodule--helper is-active sub1 &&
  76        git -C super submodule--helper is-active sub2
  77'
  78
  79test_expect_success 'is-active with submodule.active and submodule.<name>.active' '
  80        test_when_finished "git -C super config --unset-all submodule.active" &&
  81        test_when_finished "git -C super config --unset submodule.sub1.active" &&
  82        test_when_finished "git -C super config --unset submodule.sub2.active" &&
  83
  84        git -C super config --add submodule.active "sub1" &&
  85        git -C super config --bool submodule.sub1.active "false" &&
  86        git -C super config --bool submodule.sub2.active "true" &&
  87
  88        test_must_fail git -C super submodule--helper is-active sub1 &&
  89        git -C super submodule--helper is-active sub2
  90'
  91
  92test_expect_success 'is-active, submodule.active and submodule add' '
  93        test_when_finished "rm -rf super2" &&
  94        git init super2 &&
  95        test_commit -C super2 initial &&
  96        git -C super2 config --add submodule.active "sub*" &&
  97
  98        # submodule add should only add submodule.<name>.active
  99        # to the config if not matched by the pathspec
 100        git -C super2 submodule add ../sub sub1 &&
 101        test_must_fail git -C super2 config --get submodule.sub1.active &&
 102
 103        git -C super2 submodule add ../sub mod &&
 104        git -C super2 config --get submodule.mod.active
 105'
 106
 107test_done