Make submodule fetchRecurse match other options This removes the fetchRecurse compiler warnings and makes the behavior match the other submodule options (i.e. the in-memory setting can be reset to the on-disk value).
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index af08ba6..d724326 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -106,19 +106,6 @@ typedef enum {
GIT_SUBMODULE_STATUS_WD_UNTRACKED)) != 0)
/**
- * Options for submodule recurse.
- *
- * * GIT_SUBMODULE_RECURSE_NO - do no recurse into submodules
- * * GIT_SUBMODULE_RECURSE_YES - recurse into submodules
- * * GIT_SUBMODULE_RECURSE_ONDEMAND - recurse into submodules only when commit not already in local clone
- */
-typedef enum {
- GIT_SUBMODULE_RECURSE_NO = 0,
- GIT_SUBMODULE_RECURSE_YES = 1,
- GIT_SUBMODULE_RECURSE_ONDEMAND = 2,
-} git_submodule_recurse_t;
-
-/**
* Lookup submodule information by name or path.
*
* Given either the submodule name or path (they are usually the same), this
diff --git a/include/git2/types.h b/include/git2/types.h
index d88815d..2229f6b 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -323,6 +323,25 @@ typedef enum {
GIT_SUBMODULE_IGNORE_DEFAULT = 0
} git_submodule_ignore_t;
+/**
+ * Options for submodule recurse.
+ *
+ * Represent the value of `submodule.$name.fetchRecurseSubmodules`
+ *
+ * * GIT_SUBMODULE_RECURSE_RESET - reset to the on-disk value
+ * * GIT_SUBMODULE_RECURSE_NO - do no recurse into submodules
+ * * GIT_SUBMODULE_RECURSE_YES - recurse into submodules
+ * * GIT_SUBMODULE_RECURSE_ONDEMAND - recurse into submodules only when
+ * commit not already in local clone
+ */
+typedef enum {
+ GIT_SUBMODULE_RECURSE_RESET = -1,
+
+ GIT_SUBMODULE_RECURSE_NO = 0,
+ GIT_SUBMODULE_RECURSE_YES = 1,
+ GIT_SUBMODULE_RECURSE_ONDEMAND = 2,
+} git_submodule_recurse_t;
+
/** @} */
GIT_END_DECL
diff --git a/src/submodule.c b/src/submodule.c
index 720681d..2388bd1 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -498,6 +498,7 @@ int git_submodule_save(git_submodule *submodule)
submodule->ignore_default = submodule->ignore;
submodule->update_default = submodule->update;
+ submodule->fetch_recurse_default = submodule->fetch_recurse;
submodule->flags |= GIT_SUBMODULE_STATUS_IN_CONFIG;
cleanup:
@@ -650,6 +651,9 @@ git_submodule_recurse_t git_submodule_set_fetch_recurse_submodules(
assert(submodule);
+ if (fetch_recurse_submodules == GIT_SUBMODULE_RECURSE_RESET)
+ fetch_recurse_submodules = submodule->fetch_recurse_default;
+
old = submodule->fetch_recurse;
submodule->fetch_recurse = fetch_recurse_submodules;
return old;
@@ -1000,7 +1004,7 @@ static git_submodule *submodule_alloc(git_repository *repo, const char *name)
GIT_REFCOUNT_INC(sm);
sm->ignore = sm->ignore_default = GIT_SUBMODULE_IGNORE_NONE;
sm->update = sm->update_default = GIT_SUBMODULE_UPDATE_CHECKOUT;
- sm->fetch_recurse = GIT_SUBMODULE_RECURSE_YES;
+ sm->fetch_recurse = sm->fetch_recurse_default = GIT_SUBMODULE_RECURSE_NO;
sm->repo = repo;
sm->branch = NULL;
@@ -1218,6 +1222,7 @@ static int submodule_load_from_config(
else if (strcasecmp(property, "fetchRecurseSubmodules") == 0) {
if (git_submodule_parse_recurse(&sm->fetch_recurse, value) < 0)
return -1;
+ sm->fetch_recurse_default = sm->fetch_recurse;
}
else if (strcasecmp(property, "ignore") == 0) {
if ((error = git_submodule_parse_ignore(&sm->ignore, value)) < 0)
diff --git a/src/submodule.h b/src/submodule.h
index 94748ac..5e532e1 100644
--- a/src/submodule.h
+++ b/src/submodule.h
@@ -60,7 +60,9 @@
* - `update_default` is the update value from the config
* - `ignore` is a git_submodule_ignore_t value - see gitmodules(5) ignore.
* - `ignore_default` is the ignore value from the config
- * - `fetch_recurse` is 0 or 1 - see gitmodules(5) fetchRecurseSubmodules.
+ * - `fetch_recurse` is a git_submodule_recurse_t value - see gitmodules(5)
+ * fetchRecurseSubmodules.
+ * - `fetch_recurse_default` is the recurse value from the config
*
* - `repo` is the parent repository that contains this submodule.
* - `flags` after for internal use, tracking where this submodule has been
@@ -87,6 +89,7 @@ struct git_submodule {
git_submodule_ignore_t ignore;
git_submodule_ignore_t ignore_default;
git_submodule_recurse_t fetch_recurse;
+ git_submodule_recurse_t fetch_recurse_default;
/* internal information */
git_repository *repo;
diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c
index 8ec9fce..e3e4d8a 100644
--- a/tests/submodule/modify.c
+++ b/tests/submodule/modify.c
@@ -178,25 +178,28 @@ 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, GIT_SUBMODULE_RECURSE_YES);
+ old_fetchrecurse = git_submodule_set_fetch_recurse_submodules(
+ sm1, GIT_SUBMODULE_RECURSE_YES);
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));
+ GIT_SUBMODULE_IGNORE_UNTRACKED, git_submodule_ignore(sm1));
cl_assert_equal_i(
- (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
- cl_assert_equal_i(GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1));
+ GIT_SUBMODULE_UPDATE_REBASE, git_submodule_update(sm1));
+ cl_assert_equal_i(
+ GIT_SUBMODULE_RECURSE_YES, 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));
cl_assert_equal_i(
- (int)GIT_SUBMODULE_IGNORE_UNTRACKED,
- (int)git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_RESET));
+ GIT_SUBMODULE_IGNORE_UNTRACKED,
+ git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_RESET));
cl_assert_equal_i(
- (int)GIT_SUBMODULE_UPDATE_REBASE,
- (int)git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_RESET));
+ GIT_SUBMODULE_UPDATE_REBASE,
+ git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_RESET));
cl_assert_equal_i(
- GIT_SUBMODULE_RECURSE_YES, git_submodule_set_fetch_recurse_submodules(sm1, old_fetchrecurse));
+ GIT_SUBMODULE_RECURSE_YES, git_submodule_set_fetch_recurse_submodules(
+ sm1, GIT_SUBMODULE_RECURSE_RESET));
/* check that revert was successful */
cl_assert_equal_s(old_url, git_submodule_url(sm1));
@@ -243,19 +246,22 @@ void test_submodule_modify__edit_and_save(void)
cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm2));
cl_assert_equal_i(
- (int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm2));
+ GIT_SUBMODULE_IGNORE_UNTRACKED, git_submodule_ignore(sm2));
cl_assert_equal_i(
- (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm2));
- cl_assert_equal_i(GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm2));
+ GIT_SUBMODULE_UPDATE_REBASE, git_submodule_update(sm2));
+ cl_assert_equal_i(
+ GIT_SUBMODULE_RECURSE_NO, git_submodule_fetch_recurse_submodules(sm2));
/* set fetchRecurseSubmodules on-demand */
cl_git_pass(git_submodule_reload(sm1));
git_submodule_set_fetch_recurse_submodules(sm1, GIT_SUBMODULE_RECURSE_ONDEMAND);
- cl_assert_equal_i(GIT_SUBMODULE_RECURSE_ONDEMAND, git_submodule_fetch_recurse_submodules(sm1));
+ cl_assert_equal_i(
+ GIT_SUBMODULE_RECURSE_ONDEMAND, git_submodule_fetch_recurse_submodules(sm1));
/* call save */
cl_git_pass(git_submodule_save(sm1));
cl_git_pass(git_submodule_reload(sm1));
- cl_assert_equal_i(GIT_SUBMODULE_RECURSE_ONDEMAND, git_submodule_fetch_recurse_submodules(sm1));
+ cl_assert_equal_i(
+ GIT_SUBMODULE_RECURSE_ONDEMAND, git_submodule_fetch_recurse_submodules(sm1));
git_repository_free(r2);
git__free(old_url);