Read the submodule branch option from Git 1.8.2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index a150759..36bc7f8 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -284,6 +284,14 @@ GIT_EXTERN(const char *) git_submodule_path(git_submodule *submodule);
GIT_EXTERN(const char *) git_submodule_url(git_submodule *submodule);
/**
+* Get the branch for the submodule.
+*
+* @param submodule Pointer to submodule object
+* @return Pointer to the submodule branch
+*/
+GIT_EXTERN(const char *) git_submodule_branch(git_submodule *submodule);
+
+/**
* Set the URL for the submodule.
*
* This sets the URL in memory for the submodule. This will be used for
diff --git a/src/submodule.c b/src/submodule.c
index 5548e45..365fea3 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -472,6 +472,10 @@ int git_submodule_save(git_submodule *submodule)
(error = git_config_file_set_string(mods, key.ptr, submodule->url)) < 0)
goto cleanup;
+ if ((error = submodule_config_key_trunc_puts(&key, "branch")) < 0 ||
+ (error = git_config_file_set_string(mods, key.ptr, submodule->branch)) < 0)
+ goto cleanup;
+
if (!(error = submodule_config_key_trunc_puts(&key, "update")) &&
(val = git_submodule_update_to_str(submodule->update)) != NULL)
error = git_config_file_set_string(mods, key.ptr, val);
@@ -528,6 +532,12 @@ const char *git_submodule_url(git_submodule *submodule)
return submodule->url;
}
+const char *git_submodule_branch(git_submodule *submodule)
+{
+ assert(submodule);
+ return submodule->branch;
+}
+
int git_submodule_set_url(git_submodule *submodule, const char *url)
{
assert(submodule && url);
@@ -992,6 +1002,7 @@ static git_submodule *submodule_alloc(git_repository *repo, const char *name)
sm->update = sm->update_default = GIT_SUBMODULE_UPDATE_CHECKOUT;
sm->fetch_recurse = sm->update_default = GIT_SUBMODULE_RECURSE_YES;
sm->repo = repo;
+ sm->branch = NULL;
return sm;
}
@@ -1190,6 +1201,15 @@ static int submodule_load_from_config(
goto done;
}
}
+ else if (strcasecmp(property, "branch") == 0) {
+ git__free(sm->branch);
+ sm->branch = NULL;
+
+ if (value != NULL && (sm->branch = git__strdup(value)) == NULL) {
+ error = -1;
+ goto done;
+ }
+ }
else if (strcasecmp(property, "update") == 0) {
if ((error = git_submodule_parse_update(&sm->update, value)) < 0)
goto done;
diff --git a/src/submodule.h b/src/submodule.h
index 2a610e1..94748ac 100644
--- a/src/submodule.h
+++ b/src/submodule.h
@@ -81,6 +81,7 @@ struct git_submodule {
char *name;
char *path; /* important: may just point to "name" string */
char *url;
+ char *branch;
git_submodule_update_t update;
git_submodule_update_t update_default;
git_submodule_ignore_t ignore;