Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6194889

Browse files
committed
Merge pull request libgit2#3500 from ethomson/submodules_with_path
Handle submodules with paths in `git_submodule_update`
2 parents 5aa28a8 + f4b0267 commit 6194889

16 files changed

+95
-24
lines changed

src/submodule.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,6 @@ static int submodule_update_head(git_submodule *submodule)
14231423
return 0;
14241424
}
14251425

1426-
14271426
int git_submodule_reload(git_submodule *sm, int force)
14281427
{
14291428
int error = 0;
@@ -1433,35 +1432,30 @@ int git_submodule_reload(git_submodule *sm, int force)
14331432

14341433
assert(sm);
14351434

1436-
/* refresh index data */
1437-
if ((error = submodule_update_index(sm)) < 0)
1438-
return error;
1439-
1440-
/* refresh HEAD tree data */
1441-
if ((error = submodule_update_head(sm)) < 0)
1442-
return error;
1435+
if (!git_repository_is_bare(sm->repo)) {
1436+
/* refresh config data */
1437+
mods = gitmodules_snapshot(sm->repo);
1438+
if (mods != NULL) {
1439+
error = submodule_read_config(sm, mods);
1440+
git_config_free(mods);
14431441

1444-
/* done if bare */
1445-
if (git_repository_is_bare(sm->repo))
1446-
return error;
1442+
if (error < 0)
1443+
return error;
1444+
}
14471445

1448-
/* refresh config data */
1449-
mods = gitmodules_snapshot(sm->repo);
1450-
if (mods != NULL) {
1451-
error = submodule_read_config(sm, mods);
1452-
git_config_free(mods);
1446+
/* refresh wd data */
1447+
sm->flags &=
1448+
~(GIT_SUBMODULE_STATUS_IN_WD |
1449+
GIT_SUBMODULE_STATUS__WD_OID_VALID |
1450+
GIT_SUBMODULE_STATUS__WD_FLAGS);
14531451

1454-
if (error < 0) {
1455-
return error;
1456-
}
1452+
error = submodule_load_from_wd_lite(sm);
14571453
}
14581454

1459-
/* refresh wd data */
1460-
sm->flags &=
1461-
~(GIT_SUBMODULE_STATUS_IN_WD | GIT_SUBMODULE_STATUS__WD_OID_VALID |
1462-
GIT_SUBMODULE_STATUS__WD_FLAGS);
1455+
if (error == 0 && (error = submodule_update_index(sm)) == 0)
1456+
error = submodule_update_head(sm);
14631457

1464-
return submodule_load_from_wd_lite(sm);
1458+
return error;
14651459
}
14661460

14671461
static void submodule_copy_oid_maybe(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "testrepo"]
2+
path = lib/testrepo
3+
url = ../testrepo.git
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = false
4+
bare = false
5+
logallrefupdates = true
6+
symlinks = false
7+
ignorecase = true
8+
hideDotFiles = dotGitOnly
253 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
89ca686bb21bfb75dda99a02313831a0c418f921

tests/submodule/submodule_helpers.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ git_repository *setup_fixture_submodule_simple(void)
156156
return repo;
157157
}
158158

159+
git_repository *setup_fixture_submodule_with_path(void)
160+
{
161+
git_repository *repo = cl_git_sandbox_init("submodule_with_path");
162+
163+
cl_fixture_sandbox("testrepo.git");
164+
p_mkdir("submodule_with_path/lib", 0777);
165+
p_mkdir("submodule_with_path/lib/testrepo", 0777);
166+
167+
cl_set_cleanup(cleanup_fixture_submodules, "testrepo.git");
168+
169+
cl_git_pass(git_repository_reinit_filesystem(repo, 1));
170+
171+
return repo;
172+
}
173+
159174
void assert__submodule_exists(
160175
git_repository *repo, const char *name,
161176
const char *msg, const char *file, int line)

tests/submodule/submodule_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extern git_repository *setup_fixture_submodules(void);
55
extern git_repository *setup_fixture_submod2(void);
66
extern git_repository *setup_fixture_submodule_simple(void);
77
extern git_repository *setup_fixture_super(void);
8+
extern git_repository *setup_fixture_submodule_with_path(void);
89

910
extern unsigned int get_submodule_status(git_repository *, const char *);
1011

tests/submodule/update.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,53 @@ void test_submodule_update__update_submodule(void)
131131
git_submodule_free(sm);
132132
}
133133

134+
void test_submodule_update__update_submodule_with_path(void)
135+
{
136+
git_submodule *sm;
137+
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
138+
unsigned int submodule_status = 0;
139+
struct update_submodule_cb_payload update_payload = { 0 };
140+
141+
g_repo = setup_fixture_submodule_with_path();
142+
143+
update_options.checkout_opts.progress_cb = checkout_progress_cb;
144+
update_options.checkout_opts.progress_payload = &update_payload;
145+
146+
update_options.fetch_opts.callbacks.update_tips = update_tips;
147+
update_options.fetch_opts.callbacks.payload = &update_payload;
148+
149+
/* get the submodule */
150+
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
151+
152+
/* verify the initial state of the submodule */
153+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_UNSPECIFIED));
154+
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
155+
GIT_SUBMODULE_STATUS_IN_INDEX |
156+
GIT_SUBMODULE_STATUS_IN_CONFIG |
157+
GIT_SUBMODULE_STATUS_WD_UNINITIALIZED);
158+
159+
/* initialize and update the submodule */
160+
cl_git_pass(git_submodule_init(sm, 0));
161+
cl_git_pass(git_submodule_update(sm, 0, &update_options));
162+
163+
/* verify state */
164+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_UNSPECIFIED));
165+
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
166+
GIT_SUBMODULE_STATUS_IN_INDEX |
167+
GIT_SUBMODULE_STATUS_IN_CONFIG |
168+
GIT_SUBMODULE_STATUS_IN_WD);
169+
170+
cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
171+
cl_assert(git_oid_streq(git_submodule_wd_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
172+
cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
173+
174+
/* verify that the expected callbacks have been called. */
175+
cl_assert_equal_i(1, update_payload.checkout_progress_called);
176+
cl_assert_equal_i(1, update_payload.update_tips_called);
177+
178+
git_submodule_free(sm);
179+
}
180+
134181
void test_submodule_update__update_and_init_submodule(void)
135182
{
136183
git_submodule *sm;
@@ -390,3 +437,4 @@ void test_submodule_update__can_force_update(void)
390437
git_object_free(branch_commit);
391438
git_reference_free(branch_reference);
392439
}
440+

0 commit comments

Comments
 (0)