Add missing accessor for fetchRecurseSubmodules When `git_submodule` became an opaque structure, I forgot to add accessor functions for the fetchRecurseSubmodules config setting. This fixes that.
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index fe7f26c..28057d2 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -396,6 +396,35 @@ GIT_EXTERN(git_submodule_update_t) git_submodule_set_update(
git_submodule_update_t update);
/**
+ * Read the fetchRecurseSubmodules rule for a submodule.
+ *
+ * This accesses the submodule.<name>.fetchRecurseSubmodules value for
+ * the submodule that controls fetching behavior for the submodule.
+ *
+ * Note that at this time, libgit2 does not honor this setting and the
+ * fetch functionality current ignores submodules.
+ *
+ * @return 0 if fetchRecurseSubmodules is false, 1 if true
+ */
+GIT_EXTERN(int) git_submodule_fetch_recurse_submodules(
+ git_submodule *submodule);
+
+/**
+ * Set the fetchRecurseSubmodules rule for a submodule.
+ *
+ * This sets the submodule.<name>.fetchRecurseSubmodules value for
+ * the submodule. You should call `git_submodule_save()` if you want
+ * to persist the new value.
+ *
+ * @param submodule The submodule to modify
+ * @param fetch_recurse_submodules Boolean value
+ * @return old value for fetchRecurseSubmodules
+ */
+GIT_EXTERN(int) git_submodule_set_fetch_recurse_submodules(
+ git_submodule *submodule,
+ int fetch_recurse_submodules);
+
+/**
* Copy submodule info into ".git/config" file.
*
* Just like "git submodule init", this copies information about the
diff --git a/src/submodule.c b/src/submodule.c
index 66f1f84..5ae38bc 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -595,6 +595,26 @@ git_submodule_update_t git_submodule_set_update(
return old;
}
+int git_submodule_fetch_recurse_submodules(
+ git_submodule *submodule)
+{
+ assert(submodule);
+ return submodule->fetch_recurse;
+}
+
+int git_submodule_set_fetch_recurse_submodules(
+ git_submodule *submodule,
+ int fetch_recurse_submodules)
+{
+ int old;
+
+ assert(submodule);
+
+ old = submodule->fetch_recurse;
+ submodule->fetch_recurse = (fetch_recurse_submodules != 0);
+ return old;
+}
+
int git_submodule_init(git_submodule *submodule, int overwrite)
{
int error;
diff --git a/tests-clar/submodule/modify.c b/tests-clar/submodule/modify.c
index ffbbe89..0fd732c 100644
--- a/tests-clar/submodule/modify.c
+++ b/tests-clar/submodule/modify.c
@@ -183,6 +183,7 @@ void test_submodule_modify__edit_and_save(void)
git_submodule_ignore_t old_ignore;
git_submodule_update_t old_update;
git_repository *r2;
+ int old_fetchrecurse;
cl_git_pass(git_submodule_lookup(&sm1, g_repo, "sm_changed_head"));
@@ -192,12 +193,14 @@ void test_submodule_modify__edit_and_save(void)
cl_git_pass(git_submodule_set_url(sm1, SM_LIBGIT2_URL));
old_ignore = git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_UNTRACKED);
old_update = git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_REBASE);
+ old_fetchrecurse = git_submodule_set_fetch_recurse_submodules(sm1, 1);
cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm1));
cl_assert_equal_i(
(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
cl_assert_equal_i(
(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
+ cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm1));
/* revert without saving (and confirm setters return old value) */
cl_git_pass(git_submodule_set_url(sm1, old_url));
@@ -207,16 +210,21 @@ void test_submodule_modify__edit_and_save(void)
cl_assert_equal_i(
(int)GIT_SUBMODULE_UPDATE_REBASE,
(int)git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_DEFAULT));
+ cl_assert_equal_i(
+ 1, git_submodule_set_fetch_recurse_submodules(sm1, old_fetchrecurse));
/* check that revert was successful */
cl_assert_equal_s(old_url, git_submodule_url(sm1));
cl_assert_equal_i((int)old_ignore, (int)git_submodule_ignore(sm1));
cl_assert_equal_i((int)old_update, (int)git_submodule_update(sm1));
+ cl_assert_equal_i(
+ old_fetchrecurse, git_submodule_fetch_recurse_submodules(sm1));
/* modify properties of submodule (again) */
cl_git_pass(git_submodule_set_url(sm1, SM_LIBGIT2_URL));
git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_UNTRACKED);
git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_REBASE);
+ git_submodule_set_fetch_recurse_submodules(sm1, 1);
/* call save */
cl_git_pass(git_submodule_save(sm1));
@@ -232,6 +240,7 @@ void test_submodule_modify__edit_and_save(void)
(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
cl_assert_equal_i(
(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
+ cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm1));
/* call reload and check that the new values are loaded */
cl_git_pass(git_submodule_reload(sm1));
@@ -241,6 +250,7 @@ void test_submodule_modify__edit_and_save(void)
(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
cl_assert_equal_i(
(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
+ cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm1));
/* open a second copy of the repo and compare submodule */
cl_git_pass(git_repository_open(&r2, "submod2"));
@@ -251,6 +261,7 @@ void test_submodule_modify__edit_and_save(void)
(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm2));
cl_assert_equal_i(
(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm2));
+ cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm2));
git_repository_free(r2);
git__free(old_url);