From 790012ce782e2b97e90e52ae9fdaff098b56b999 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 4 Nov 2015 16:16:51 -0500 Subject: [PATCH 1/2] 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. --- .../resources/submodule_with_path/.gitmodules | Bin 0 -> 67 bytes .../submodule_with_path/.gitted/HEAD | Bin 0 -> 23 bytes .../submodule_with_path/.gitted/config | Bin 0 -> 157 bytes .../submodule_with_path/.gitted/index | Bin 0 -> 253 bytes .../18/372280a56a54340fa600aa91315065c6c4c693 | Bin 0 -> 85 bytes .../36/683131578275f6a8fd1c539e0d5da0d8adff26 | Bin 0 -> 63 bytes .../89/ca686bb21bfb75dda99a02313831a0c418f921 | Bin 0 -> 161 bytes .../b1/620ef2628d10416a84d19c783e33dc4556c9c3 | Bin 0 -> 86 bytes .../ba/34c47dc9d3d0b1bb335b45c9d26ba1f0fc90c7 | Bin 0 -> 68 bytes .../c8/4bf57ba2254dba216ab5c6eb1a19fe8bd0e0d6 | Bin 0 -> 127 bytes .../d5/45fc6b40ec9e67332b6a1d2dedcbdb1bffeb6b | Bin 0 -> 51 bytes .../.gitted/refs/heads/master | Bin 0 -> 41 bytes tests/submodule/submodule_helpers.c | 15 ++++++ tests/submodule/submodule_helpers.h | 1 + tests/submodule/update.c | 48 ++++++++++++++++++ 15 files changed, 64 insertions(+) create mode 100644 tests/resources/submodule_with_path/.gitmodules create mode 100644 tests/resources/submodule_with_path/.gitted/HEAD create mode 100644 tests/resources/submodule_with_path/.gitted/config create mode 100644 tests/resources/submodule_with_path/.gitted/index create mode 100644 tests/resources/submodule_with_path/.gitted/objects/18/372280a56a54340fa600aa91315065c6c4c693 create mode 100644 tests/resources/submodule_with_path/.gitted/objects/36/683131578275f6a8fd1c539e0d5da0d8adff26 create mode 100644 tests/resources/submodule_with_path/.gitted/objects/89/ca686bb21bfb75dda99a02313831a0c418f921 create mode 100644 tests/resources/submodule_with_path/.gitted/objects/b1/620ef2628d10416a84d19c783e33dc4556c9c3 create mode 100644 tests/resources/submodule_with_path/.gitted/objects/ba/34c47dc9d3d0b1bb335b45c9d26ba1f0fc90c7 create mode 100644 tests/resources/submodule_with_path/.gitted/objects/c8/4bf57ba2254dba216ab5c6eb1a19fe8bd0e0d6 create mode 100644 tests/resources/submodule_with_path/.gitted/objects/d5/45fc6b40ec9e67332b6a1d2dedcbdb1bffeb6b create mode 100644 tests/resources/submodule_with_path/.gitted/refs/heads/master diff --git a/tests/resources/submodule_with_path/.gitmodules b/tests/resources/submodule_with_path/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..ba34c47dc9d3d0b1bb335b45c9d26ba1f0fc90c7 GIT binary patch literal 67 zcmazpE=|hKPbtkwRZuEPEiNfaEy!1j<>D+zEXh!?RmjOq(uWCiah4Y40LAq5;6i%o HnI&8RAAA}oMPd`mF*(s_9TLV@qN9ge_KWI9)sd8MlRa2 zXaRqt8cCf_(;P!4#v%zjWnjY?9-x23vH`PVKK2BT);-swYt{-=eU0H4(pLN73O4eu U^rVDm@k>7$ViLcSFO^&T0N7wQ1ONa4 literal 0 HcmV?d00001 diff --git a/tests/resources/submodule_with_path/.gitted/index b/tests/resources/submodule_with_path/.gitted/index new file mode 100644 index 0000000000000000000000000000000000000000..a740b4b91e5595fef2e2b0983480d834da7bdf9e GIT binary patch literal 253 zcmZ?q402{*U|<5_Fsqa(Ak7eFmF@zf5ukAig3aK(%j8Jy$;%fu?lz8gJ$Wg6;fFsH zjx%uUrDvAp=BJeAq!vRJ1I-HqF@ba>l71lb0Sb3n{M*m7-alcwygN_jzOR4$laTTN z2A-VEB>j@q;*z4&f_#YbkRVrAAj_1&NWqY6V-nw|q+S8Xtd@&&D(sB!xQ3lP4AjD4 ys9?Z#)%8!d!<%{O#@bo3x^GY4mj3@b`_cPT!M_=Km$h&Qx=xo~|8AY~c_{$IhD+W6 literal 0 HcmV?d00001 diff --git a/tests/resources/submodule_with_path/.gitted/objects/18/372280a56a54340fa600aa91315065c6c4c693 b/tests/resources/submodule_with_path/.gitted/objects/18/372280a56a54340fa600aa91315065c6c4c693 new file mode 100644 index 0000000000000000000000000000000000000000..d9b4313e187ed50eb03ad8c99a11ae9bbfa14879 GIT binary patch literal 85 zcmV-b0IL6Z0V^p=O;s?nWH2-^Ff%bx&`ZxO$<0qG%}Fh0Fv~DB3~ws^w&Jf$@I2nw r1vl3IS2HmH0)?E+B!;W5f3h9k%u6@c&XU!Ad-}HY|JT_795W{55>P0GzrDa}b$P%23+E-6Ya$XANx;w(rk$xyIW$jMC7 VhY53WmKNmz#q{(LLI7Du7m_mY8dU%Q literal 0 HcmV?d00001 diff --git a/tests/resources/submodule_with_path/.gitted/objects/89/ca686bb21bfb75dda99a02313831a0c418f921 b/tests/resources/submodule_with_path/.gitted/objects/89/ca686bb21bfb75dda99a02313831a0c418f921 new file mode 100644 index 0000000000000000000000000000000000000000..7c1af6645b3678f7cddabf69568fbe93b73c26c7 GIT binary patch literal 161 zcmV;S0ABxi0i}-14Z<)GL^-<(HvsbbvvDMZxX=L&*z1jwgW1S2qJ2yaoM!Z-HyV;! zx2~;&Q*X>V16sq2MH>qk5167aFw+zrJ6FhufHad+dusgZnxfB3m~yf<_%dP`IS_J& z1oOf%7sIBYO7Ff((~t5=t?1_}^^ljo@}R$VuNyTvWa$@@deh)NB1W*F&n6h71|3H` P|1qIN_CtLE2lz_SuD?t; literal 0 HcmV?d00001 diff --git a/tests/resources/submodule_with_path/.gitted/objects/b1/620ef2628d10416a84d19c783e33dc4556c9c3 b/tests/resources/submodule_with_path/.gitted/objects/b1/620ef2628d10416a84d19c783e33dc4556c9c3 new file mode 100644 index 0000000000000000000000000000000000000000..4475582597be6c70d7350a9d6e9dd3106b6d7d31 GIT binary patch literal 86 zcmV-c0IC0Y0V^p=O;s?nWH2-^Ff%bx&`ZxO$<0qG%}Fh0*ky90_T=RY8+RK=yPmw1 sz3{`I3CB$gfIuN9Gl}7<>z{0gH}leswX5XNWE?P0GzrDa}b$P%23+E-6Ya$XANx;w(rk$xyIW$jMC7 ahY53WmKNmz#q{*xLVD?$C0qc#AQ=eHq#alQ literal 0 HcmV?d00001 diff --git a/tests/resources/submodule_with_path/.gitted/objects/c8/4bf57ba2254dba216ab5c6eb1a19fe8bd0e0d6 b/tests/resources/submodule_with_path/.gitted/objects/c8/4bf57ba2254dba216ab5c6eb1a19fe8bd0e0d6 new file mode 100644 index 0000000000000000000000000000000000000000..9f664569ce0477eeddf845279556266ded79ab69 GIT binary patch literal 127 zcmV-_0D%8^0i})04Z<)CKsjd$F933WZYm+v3mdS2up4eLK1{#Z}`(UZSY*b+*WvPS`U50JrDb%rS8)7 h(9&9V=y!`00M=Q)Z&t&)Pj75W$|x6&wBra>GJM8mHWQ_@lQg^ J0{~*65=1l57(D<0 literal 0 HcmV?d00001 diff --git a/tests/resources/submodule_with_path/.gitted/refs/heads/master b/tests/resources/submodule_with_path/.gitted/refs/heads/master new file mode 100644 index 0000000000000000000000000000000000000000..4b5a5a21d3e5931df4bfb9c19574711228bc603c GIT binary patch literal 41 vcmV~$!4Uu;2m`Rc(@;=^aVQ@9k6;qn<>91)!+YMV%n~(N7)p90CKc-g@PrD* literal 0 HcmV?d00001 diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c index cde69d92d..4ff4b4da7 100644 --- a/tests/submodule/submodule_helpers.c +++ b/tests/submodule/submodule_helpers.c @@ -156,6 +156,21 @@ git_repository *setup_fixture_submodule_simple(void) return repo; } +git_repository *setup_fixture_submodule_with_path(void) +{ + git_repository *repo = cl_git_sandbox_init("submodule_with_path"); + + cl_fixture_sandbox("testrepo.git"); + p_mkdir("submodule_with_path/lib", 0777); + p_mkdir("submodule_with_path/lib/testrepo", 0777); + + cl_set_cleanup(cleanup_fixture_submodules, "testrepo.git"); + + cl_git_pass(git_repository_reinit_filesystem(repo, 1)); + + return repo; +} + void assert__submodule_exists( git_repository *repo, const char *name, const char *msg, const char *file, int line) diff --git a/tests/submodule/submodule_helpers.h b/tests/submodule/submodule_helpers.h index 1191ab35b..42b14a7bc 100644 --- a/tests/submodule/submodule_helpers.h +++ b/tests/submodule/submodule_helpers.h @@ -5,6 +5,7 @@ extern git_repository *setup_fixture_submodules(void); extern git_repository *setup_fixture_submod2(void); extern git_repository *setup_fixture_submodule_simple(void); extern git_repository *setup_fixture_super(void); +extern git_repository *setup_fixture_submodule_with_path(void); extern unsigned int get_submodule_status(git_repository *, const char *); diff --git a/tests/submodule/update.c b/tests/submodule/update.c index 40d24d0a7..cbd519d81 100644 --- a/tests/submodule/update.c +++ b/tests/submodule/update.c @@ -131,6 +131,53 @@ void test_submodule_update__update_submodule(void) git_submodule_free(sm); } +void test_submodule_update__update_submodule_with_path(void) +{ + git_submodule *sm; + git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; + unsigned int submodule_status = 0; + struct update_submodule_cb_payload update_payload = { 0 }; + + g_repo = setup_fixture_submodule_with_path(); + + update_options.checkout_opts.progress_cb = checkout_progress_cb; + update_options.checkout_opts.progress_payload = &update_payload; + + update_options.fetch_opts.callbacks.update_tips = update_tips; + update_options.fetch_opts.callbacks.payload = &update_payload; + + /* get the submodule */ + 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, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_UNSPECIFIED)); + cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | + GIT_SUBMODULE_STATUS_IN_INDEX | + GIT_SUBMODULE_STATUS_IN_CONFIG | + GIT_SUBMODULE_STATUS_WD_UNINITIALIZED); + + /* initialize and update the submodule */ + cl_git_pass(git_submodule_init(sm, 0)); + cl_git_pass(git_submodule_update(sm, 0, &update_options)); + + /* verify state */ + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_UNSPECIFIED)); + cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | + GIT_SUBMODULE_STATUS_IN_INDEX | + GIT_SUBMODULE_STATUS_IN_CONFIG | + GIT_SUBMODULE_STATUS_IN_WD); + + cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); + cl_assert(git_oid_streq(git_submodule_wd_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); + cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); + + /* verify that the expected callbacks have been called. */ + cl_assert_equal_i(1, update_payload.checkout_progress_called); + cl_assert_equal_i(1, update_payload.update_tips_called); + + git_submodule_free(sm); +} + void test_submodule_update__update_and_init_submodule(void) { git_submodule *sm; @@ -390,3 +437,4 @@ void test_submodule_update__can_force_update(void) git_object_free(branch_commit); git_reference_free(branch_reference); } + From f4b02671220e35fd0c20b915ebe6359b89440f54 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 4 Nov 2015 16:17:51 -0500 Subject: [PATCH 2/2] submodule: reload HEAD/index after reading config Reload the HEAD and index data for a submodule after reading the configuration. The configuration may specify a `path`, so we must update HEAD and index data with that path in mind. --- src/submodule.c | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/submodule.c b/src/submodule.c index 3fd338843..1148f8790 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -1423,7 +1423,6 @@ static int submodule_update_head(git_submodule *submodule) return 0; } - int git_submodule_reload(git_submodule *sm, int force) { int error = 0; @@ -1433,35 +1432,30 @@ int git_submodule_reload(git_submodule *sm, int force) assert(sm); - /* refresh index data */ - if ((error = submodule_update_index(sm)) < 0) - return error; + if (!git_repository_is_bare(sm->repo)) { + /* refresh config data */ + mods = gitmodules_snapshot(sm->repo); + if (mods != NULL) { + error = submodule_read_config(sm, mods); + git_config_free(mods); - /* refresh HEAD tree data */ - if ((error = submodule_update_head(sm)) < 0) - return error; - - /* done if bare */ - if (git_repository_is_bare(sm->repo)) - return error; - - /* refresh config data */ - mods = gitmodules_snapshot(sm->repo); - if (mods != NULL) { - error = submodule_read_config(sm, mods); - git_config_free(mods); - - if (error < 0) { - return error; + if (error < 0) + return error; } + + /* refresh wd data */ + sm->flags &= + ~(GIT_SUBMODULE_STATUS_IN_WD | + GIT_SUBMODULE_STATUS__WD_OID_VALID | + GIT_SUBMODULE_STATUS__WD_FLAGS); + + error = submodule_load_from_wd_lite(sm); } - /* refresh wd data */ - sm->flags &= - ~(GIT_SUBMODULE_STATUS_IN_WD | GIT_SUBMODULE_STATUS__WD_OID_VALID | - GIT_SUBMODULE_STATUS__WD_FLAGS); + if (error == 0 && (error = submodule_update_index(sm)) == 0) + error = submodule_update_head(sm); - return submodule_load_from_wd_lite(sm); + return error; } static void submodule_copy_oid_maybe(