submodule--helper: add is-active subcommand
The definition of which submodules are of interest by the user is tied to the configuration submodule.<name>.url; when it is set to a non-empty string, it is of interest. We'd want to be able to later change this definition, but there are many places that explicitly check this condition in the scripted Porcelain. Introduce the "is-active" subcommand to "submodule--helper", so that the exact definition of what submodule is of interest can be centrally defined (and changed in later steps). In a few patches that follow, this helper is used to replace the explicit checks of the configuration variable in scripts. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Mar 16, 2017 at 15:29 UTC
5c2bd8b77aeefa4c6484684ef3e9227a6287a93e
2 files changed
+42
builtin/submodule--helper.c
+11
@@ -1127,6 +1127,16 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
1127
return 0;
1128
}
1129
1130
+static int is_active(int argc, const char **argv, const char *prefix)
1131
+{
1132
+ if (argc != 2)
1133
+ die("submodule--helper is-active takes exactly 1 arguments");
1134
+
1135
+ gitmodules_config();
1136
+
1137
+ return !is_submodule_initialized(argv[1]);
1138
+}
1139
+
1140
#define SUPPORT_SUPER_PREFIX (1<<0)
1141
1142
struct cmd_struct {
@@ -1146,6 +1156,7 @@ static struct cmd_struct commands[] = {
1156
{"init", module_init, SUPPORT_SUPER_PREFIX},
1157
{"remote-branch", resolve_remote_submodule_branch, 0},
1158
{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
1159
+ {"is-active", is_active, 0},
1160
};
1161
1162
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
t/t7413-submodule-is-active.sh
new
+31
@@ -0,0 +1,31 @@
1
+#!/bin/sh
2
+
3
+test_description='Test submodule--helper is-active
4
+
5
+This test verifies that `git submodue--helper is-active` correclty identifies
6
+submodules which are "active" and interesting to the user.
7
+'
8
+
9
+. ./test-lib.sh
10
+
11
+test_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
+ git -C super commit -a -m "add 2 submodules at sub{1,2}"
19
+'
20
+
21
+test_expect_success 'is-active works with urls' '
22
+ git -C super submodule--helper is-active sub1 &&
23
+ git -C super submodule--helper is-active sub2 &&
24
+
25
+ git -C super config --unset submodule.sub1.URL &&
26
+ test_must_fail git -C super submodule--helper is-active sub1 &&
27
+ git -C super config submodule.sub1.URL ../sub &&
28
+ git -C super submodule--helper is-active sub1
29
+'
30
+
31
+test_done