1#!/bin/sh
   2test_description='Test submodule--helper is-active
   4This test verifies that `git submodue--helper is-active` correctly identifies
   6submodules which are "active" and interesting to the user.
   7'
   8. ./test-lib.sh
  10test_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        # 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        git -C super commit -a -m "add 2 submodules at sub{1,2}"
  25'
  26test_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        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'
  36test_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        git -C super config --bool submodule.sub1.active "false" &&
  42        test_must_fail git -C super submodule--helper is-active sub1 &&
  43        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'
  48test_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        git -C super config --add submodule.active "." &&
  54        git -C super config --unset submodule.sub1.URL &&
  55        git -C super submodule--helper is-active sub1 &&
  57        git -C super submodule--helper is-active sub2
  58'
  59test_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        test_must_fail git -C super submodule--helper is-active not-a-submodule &&
  64        git -C super config --add submodule.active "." &&
  66        test_must_fail git -C super submodule--helper is-active not-a-submodule
  67'
  68test_expect_success 'is-active works with exclusions in submodule.active config' '
  70        test_when_finished "git -C super config --unset-all submodule.active" &&
  71        git -C super config --add submodule.active "." &&
  73        git -C super config --add submodule.active ":(exclude)sub1" &&
  74        test_must_fail git -C super submodule--helper is-active sub1 &&
  76        git -C super submodule--helper is-active sub2
  77'
  78test_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        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        test_must_fail git -C super submodule--helper is-active sub1 &&
  89        git -C super submodule--helper is-active sub2
  90'
  91test_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        # 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        git -C super2 submodule add ../sub mod &&
 104        git -C super2 config --get submodule.mod.active
 105'
 106test_done