submodule: don't let status change an existing instance As submodules are becomes more like values, we should not let a status check to update its properties. Instead of taking a submodule, have status take a repo and submodule name.
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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index e41dc49..7375708 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -626,16 +626,17 @@ GIT_EXTERN(int) git_submodule_reload_all(git_repository *repo, int force);
* This looks at a submodule and tries to determine the status. It
* will return a combination of the `GIT_SUBMODULE_STATUS` values above.
* How deeply it examines the working directory to do this will depend
- * on the `git_submodule_ignore_t` value for the submodule - which can be
- * set either temporarily or permanently with `git_submodule_set_ignore()`.
+ * on the `git_submodule_ignore_t` value for the submodule.
*
* @param status Combination of `GIT_SUBMODULE_STATUS` flags
- * @param submodule Submodule for which to get status
+ * @param repo the repository in which to look
+ * @param name name of the submodule
* @return 0 on success, <0 on error
*/
GIT_EXTERN(int) git_submodule_status(
unsigned int *status,
- git_submodule *submodule);
+ git_repository *repo,
+ const char *name);
/**
* Get the locations of submodule information.
diff --git a/src/checkout.c b/src/checkout.c
index dab83c6..d95244a 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -180,7 +180,7 @@ static bool checkout_is_workdir_modified(
return true;
}
- if (git_submodule_status(&sm_status, sm) < 0 ||
+ if (git_submodule_status(&sm_status, data->repo, wditem->path) < 0 ||
GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status))
rval = true;
else if ((sm_oid = git_submodule_wd_id(sm)) == NULL)
diff --git a/src/diff_file.c b/src/diff_file.c
index cef4bc1..4d9ecc8 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -186,7 +186,7 @@ static int diff_file_content_commit_to_str(
return error;
}
- if ((error = git_submodule_status(&sm_status, sm)) < 0) {
+ if ((error = git_submodule_status(&sm_status, fc->repo, fc->file->path)) < 0) {
git_submodule_free(sm);
return error;
}
diff --git a/src/submodule.c b/src/submodule.c
index 78bf519..2faaa73 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -1067,7 +1067,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
memcpy(&clone_options.fetch_opts, &update_options.fetch_opts, sizeof(git_fetch_options));
/* Get the status of the submodule to determine if it is already initialized */
- if ((error = git_submodule_status(&submodule_status, sm)) < 0)
+ if ((error = git_submodule_status(&submodule_status, sm->repo, sm->name)) < 0)
goto done;
/*
@@ -1511,11 +1511,20 @@ int git_submodule__status(
return 0;
}
-int git_submodule_status(unsigned int *status, git_submodule *sm)
+int git_submodule_status(unsigned int *status, git_repository *repo, const char *name)
{
- assert(status && sm);
+ git_submodule *sm;
+ int error;
+
+ assert(status && repo && name);
+
+ if ((error = git_submodule_lookup(&sm, repo, name)) < 0)
+ return error;
+
+ error = git_submodule__status(status, NULL, NULL, NULL, sm, 0);
+ git_submodule_free(sm);
- return git_submodule__status(status, NULL, NULL, NULL, sm, 0);
+ return error;
}
int git_submodule_location(unsigned int *location, git_submodule *sm)
diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c
index 19bb04f..3683822 100644
--- a/tests/submodule/submodule_helpers.c
+++ b/tests/submodule/submodule_helpers.c
@@ -164,13 +164,11 @@ void refute__submodule_exists(
unsigned int get_submodule_status(git_repository *repo, const char *name)
{
- git_submodule *sm = NULL;
unsigned int status = 0;
- cl_git_pass(git_submodule_lookup(&sm, repo, name));
- cl_assert(sm);
- cl_git_pass(git_submodule_status(&status, sm));
- git_submodule_free(sm);
+ assert(repo && name);
+
+ cl_git_pass(git_submodule_status(&status, repo, name));
return status;
}
diff --git a/tests/submodule/update.c b/tests/submodule/update.c
index e7f1b76..8587043 100644
--- a/tests/submodule/update.c
+++ b/tests/submodule/update.c
@@ -103,7 +103,7 @@ void test_submodule_update__update_submodule(void)
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
/* verify the initial state of the submodule */
- cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -114,7 +114,7 @@ void test_submodule_update__update_submodule(void)
cl_git_pass(git_submodule_update(sm, 0, &update_options));
/* verify state */
- cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -142,7 +142,7 @@ void test_submodule_update__update_and_init_submodule(void)
/* get the submodule */
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
- cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -177,7 +177,7 @@ void test_submodule_update__update_already_checked_out_submodule(void)
/* Initialize and update the sub repository */
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
- cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -203,7 +203,11 @@ void test_submodule_update__update_already_checked_out_submodule(void)
* HEAD commit and index should be updated, but not the workdir.
*/
- cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
+
+ git_submodule_free(sm);
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -251,7 +255,7 @@ void test_submodule_update__update_blocks_on_dirty_wd(void)
/* Initialize and update the sub repository */
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
- cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -277,7 +281,11 @@ void test_submodule_update__update_blocks_on_dirty_wd(void)
* HEAD commit and index should be updated, but not the workdir.
*/
- cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
+
+ git_submodule_free(sm);
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -324,7 +332,7 @@ void test_submodule_update__can_force_update(void)
/* Initialize and update the sub repository */
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
- cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -349,7 +357,11 @@ void test_submodule_update__can_force_update(void)
* Verify state after checkout of parent repository. The submodule ID in the
* HEAD commit and index should be updated, but not the workdir.
*/
- cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
+
+ git_submodule_free(sm);
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |