submodule-config: keep configured branch around

The branch field will be used in a later patch by `submodule update`. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Jul 28, 2016 at 17:44 UTC b5944f3476dbaee15649b0fa02b2b35aaa149dc3
2 files changed +11 -1
submodule-config.c
+10 -1
@@ -59,6 +59,7 @@ static void free_one_config(struct submodule_entry *entry)
59 {
60 free((void *) entry->config->path);
61 free((void *) entry->config->name);
62 + free((void *) entry->config->branch);
63 free((void *) entry->config->update_strategy.command);
64 free(entry->config);
65 }
@@ -199,6 +200,7 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,
200 submodule->update_strategy.command = NULL;
201 submodule->fetch_recurse = RECURSE_SUBMODULES_NONE;
202 submodule->ignore = NULL;
203 + submodule->branch = NULL;
204 submodule->recommend_shallow = -1;
205
206 hashcpy(submodule->gitmodules_sha1, gitmodules_sha1);
@@ -358,9 +360,16 @@ static int parse_config(const char *var, const char *value, void *data)
360 if (!me->overwrite && submodule->recommend_shallow != -1)
361 warn_multiple_config(me->commit_sha1, submodule->name,
362 "shallow");
361 - else {
363 + else
364 submodule->recommend_shallow =
365 git_config_bool(var, value);
366 + } else if (!strcmp(item.buf, "branch")) {
367 + if (!me->overwrite && submodule->branch)
368 + warn_multiple_config(me->commit_sha1, submodule->name,
369 + "branch");
370 + else {
371 + free((void *)submodule->branch);
372 + submodule->branch = xstrdup(value);
373 }
374 }
375
submodule-config.h
+1
@@ -15,6 +15,7 @@ struct submodule {
15 const char *url;
16 int fetch_recurse;
17 const char *ignore;
18 + const char *branch;
19 struct submodule_update_strategy update_strategy;
20 /* the sha1 blob id of the responsible .gitmodules file */
21 unsigned char gitmodules_sha1[20];