Skip to content

Commit 64bbd47

Browse files
committed
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 parent 5a9fc6c commit 64bbd47

File tree

6 files changed

+44
-24
lines changed

6 files changed

+44
-24
lines changed

include/git2/submodule.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,16 +626,17 @@ GIT_EXTERN(int) git_submodule_reload_all(git_repository *repo, int force);
626626
* This looks at a submodule and tries to determine the status. It
627627
* will return a combination of the `GIT_SUBMODULE_STATUS` values above.
628628
* How deeply it examines the working directory to do this will depend
629-
* on the `git_submodule_ignore_t` value for the submodule - which can be
630-
* set either temporarily or permanently with `git_submodule_set_ignore()`.
629+
* on the `git_submodule_ignore_t` value for the submodule.
631630
*
632631
* @param status Combination of `GIT_SUBMODULE_STATUS` flags
633-
* @param submodule Submodule for which to get status
632+
* @param repo the repository in which to look
633+
* @param name name of the submodule
634634
* @return 0 on success, <0 on error
635635
*/
636636
GIT_EXTERN(int) git_submodule_status(
637637
unsigned int *status,
638-
git_submodule *submodule);
638+
git_repository *repo,
639+
const char *name);
639640

640641
/**
641642
* Get the locations of submodule information.

src/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static bool checkout_is_workdir_modified(
180180
return true;
181181
}
182182

183-
if (git_submodule_status(&sm_status, sm) < 0 ||
183+
if (git_submodule_status(&sm_status, data->repo, wditem->path) < 0 ||
184184
GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status))
185185
rval = true;
186186
else if ((sm_oid = git_submodule_wd_id(sm)) == NULL)

src/diff_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static int diff_file_content_commit_to_str(
186186
return error;
187187
}
188188

189-
if ((error = git_submodule_status(&sm_status, sm)) < 0) {
189+
if ((error = git_submodule_status(&sm_status, fc->repo, fc->file->path)) < 0) {
190190
git_submodule_free(sm);
191191
return error;
192192
}

src/submodule.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
10671067
memcpy(&clone_options.fetch_opts, &update_options.fetch_opts, sizeof(git_fetch_options));
10681068

10691069
/* Get the status of the submodule to determine if it is already initialized */
1070-
if ((error = git_submodule_status(&submodule_status, sm)) < 0)
1070+
if ((error = git_submodule_status(&submodule_status, sm->repo, sm->name)) < 0)
10711071
goto done;
10721072

10731073
/*
@@ -1511,11 +1511,20 @@ int git_submodule__status(
15111511
return 0;
15121512
}
15131513

1514-
int git_submodule_status(unsigned int *status, git_submodule *sm)
1514+
int git_submodule_status(unsigned int *status, git_repository *repo, const char *name)
15151515
{
1516-
assert(status && sm);
1516+
git_submodule *sm;
1517+
int error;
1518+
1519+
assert(status && repo && name);
1520+
1521+
if ((error = git_submodule_lookup(&sm, repo, name)) < 0)
1522+
return error;
1523+
1524+
error = git_submodule__status(status, NULL, NULL, NULL, sm, 0);
1525+
git_submodule_free(sm);
15171526

1518-
return git_submodule__status(status, NULL, NULL, NULL, sm, 0);
1527+
return error;
15191528
}
15201529

15211530
int git_submodule_location(unsigned int *location, git_submodule *sm)

tests/submodule/submodule_helpers.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,11 @@ void refute__submodule_exists(
164164

165165
unsigned int get_submodule_status(git_repository *repo, const char *name)
166166
{
167-
git_submodule *sm = NULL;
168167
unsigned int status = 0;
169168

170-
cl_git_pass(git_submodule_lookup(&sm, repo, name));
171-
cl_assert(sm);
172-
cl_git_pass(git_submodule_status(&status, sm));
173-
git_submodule_free(sm);
169+
assert(repo && name);
170+
171+
cl_git_pass(git_submodule_status(&status, repo, name));
174172

175173
return status;
176174
}

tests/submodule/update.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void test_submodule_update__update_submodule(void)
103103
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
104104

105105
/* verify the initial state of the submodule */
106-
cl_git_pass(git_submodule_status(&submodule_status, sm));
106+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
107107
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
108108
GIT_SUBMODULE_STATUS_IN_INDEX |
109109
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -114,7 +114,7 @@ void test_submodule_update__update_submodule(void)
114114
cl_git_pass(git_submodule_update(sm, 0, &update_options));
115115

116116
/* verify state */
117-
cl_git_pass(git_submodule_status(&submodule_status, sm));
117+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
118118
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
119119
GIT_SUBMODULE_STATUS_IN_INDEX |
120120
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -142,7 +142,7 @@ void test_submodule_update__update_and_init_submodule(void)
142142
/* get the submodule */
143143
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
144144

145-
cl_git_pass(git_submodule_status(&submodule_status, sm));
145+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
146146
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
147147
GIT_SUBMODULE_STATUS_IN_INDEX |
148148
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -177,7 +177,7 @@ void test_submodule_update__update_already_checked_out_submodule(void)
177177
/* Initialize and update the sub repository */
178178
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
179179

180-
cl_git_pass(git_submodule_status(&submodule_status, sm));
180+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
181181
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
182182
GIT_SUBMODULE_STATUS_IN_INDEX |
183183
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -203,7 +203,11 @@ void test_submodule_update__update_already_checked_out_submodule(void)
203203
* HEAD commit and index should be updated, but not the workdir.
204204
*/
205205

206-
cl_git_pass(git_submodule_status(&submodule_status, sm));
206+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
207+
208+
git_submodule_free(sm);
209+
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
210+
207211
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
208212
GIT_SUBMODULE_STATUS_IN_INDEX |
209213
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -251,7 +255,7 @@ void test_submodule_update__update_blocks_on_dirty_wd(void)
251255
/* Initialize and update the sub repository */
252256
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
253257

254-
cl_git_pass(git_submodule_status(&submodule_status, sm));
258+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
255259
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
256260
GIT_SUBMODULE_STATUS_IN_INDEX |
257261
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -277,7 +281,11 @@ void test_submodule_update__update_blocks_on_dirty_wd(void)
277281
* HEAD commit and index should be updated, but not the workdir.
278282
*/
279283

280-
cl_git_pass(git_submodule_status(&submodule_status, sm));
284+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
285+
286+
git_submodule_free(sm);
287+
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
288+
281289
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
282290
GIT_SUBMODULE_STATUS_IN_INDEX |
283291
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -324,7 +332,7 @@ void test_submodule_update__can_force_update(void)
324332
/* Initialize and update the sub repository */
325333
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
326334

327-
cl_git_pass(git_submodule_status(&submodule_status, sm));
335+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
328336
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
329337
GIT_SUBMODULE_STATUS_IN_INDEX |
330338
GIT_SUBMODULE_STATUS_IN_CONFIG |
@@ -349,7 +357,11 @@ void test_submodule_update__can_force_update(void)
349357
* Verify state after checkout of parent repository. The submodule ID in the
350358
* HEAD commit and index should be updated, but not the workdir.
351359
*/
352-
cl_git_pass(git_submodule_status(&submodule_status, sm));
360+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo"));
361+
362+
git_submodule_free(sm);
363+
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
364+
353365
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
354366
GIT_SUBMODULE_STATUS_IN_INDEX |
355367
GIT_SUBMODULE_STATUS_IN_CONFIG |

0 commit comments

Comments
 (0)