summaryrefslogtreecommitdiff
path: root/submodule-config.c
diff options
context:
space:
mode:
authorHeiko Voigt <hvoigt@hvoigt.net>2015-08-17 17:22:00 -0700
committerJunio C Hamano <gitster@pobox.com>2015-08-19 11:43:10 -0700
commit027771fcb153e0003bcb2d68e1838594a48b0161 (patch)
tree688a3f852ef82161a77db7ec8fd7c59ce601b956 /submodule-config.c
parent851e18c3859ad0f9f7e91fdb4d6cce5a8272420b (diff)
downloadgit-027771fcb153e0003bcb2d68e1838594a48b0161.tar.gz
submodule: allow erroneous values for the fetchRecurseSubmodules optionhv/submodule-config
We should not die when reading the submodule config cache since the user might not be able to get out of that situation when the configuration is part of the history. We should handle this condition later when the value is about to be used. Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule-config.c')
-rw-r--r--submodule-config.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/submodule-config.c b/submodule-config.c
index c64faf3d6f..393de5357e 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -204,6 +204,30 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,
return submodule;
}
+static int parse_fetch_recurse(const char *opt, const char *arg,
+ int die_on_error)
+{
+ switch (git_config_maybe_bool(opt, arg)) {
+ case 1:
+ return RECURSE_SUBMODULES_ON;
+ case 0:
+ return RECURSE_SUBMODULES_OFF;
+ default:
+ if (!strcmp(arg, "on-demand"))
+ return RECURSE_SUBMODULES_ON_DEMAND;
+
+ if (die_on_error)
+ die("bad %s argument: %s", opt, arg);
+ else
+ return RECURSE_SUBMODULES_ERROR;
+ }
+}
+
+int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)
+{
+ return parse_fetch_recurse(opt, arg, 1);
+}
+
static void warn_multiple_config(const unsigned char *commit_sha1,
const char *name, const char *option)
{
@@ -255,6 +279,8 @@ static int parse_config(const char *var, const char *value, void *data)
submodule->path = strbuf_detach(&path, NULL);
cache_put_path(me->cache, submodule);
} else if (!strcmp(item.buf, "fetchrecursesubmodules")) {
+ /* when parsing worktree configurations we can die early */
+ int die_on_error = is_null_sha1(me->gitmodules_sha1);
if (!me->overwrite &&
submodule->fetch_recurse != RECURSE_SUBMODULES_NONE) {
warn_multiple_config(me->commit_sha1, submodule->name,
@@ -262,7 +288,8 @@ static int parse_config(const char *var, const char *value, void *data)
goto release_return;
}
- submodule->fetch_recurse = parse_fetch_recurse_submodules_arg(var, value);
+ submodule->fetch_recurse = parse_fetch_recurse(var, value,
+ die_on_error);
} else if (!strcmp(item.buf, "ignore")) {
struct strbuf ignore = STRBUF_INIT;
if (!me->overwrite && submodule->ignore != NULL) {