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

Skip to content

Commit 790012c

Browse files
Edward Thomsonethomson
Edward Thomson
authored andcommitted
submodule: test updating a submodule w/ a path
Test that `git_submodule_update` can handle a submodule that is freshly cloned and has a path differing from its name.
1 parent 610e553 commit 790012c

15 files changed

+77
-0
lines changed
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)