@@ -42,6 +42,46 @@ void test_submodule_lookup__simple_lookup(void)
4242 assert_submodule_exists (g_repo , "sm_added_and_uncommited/" );
4343}
4444
45+ void test_submodule_lookup__can_be_dupped (void )
46+ {
47+ git_submodule * sm ;
48+ git_submodule * sm_duplicate ;
49+ const char * oid = "480095882d281ed676fe5b863569520e54a7d5c0" ;
50+
51+ /* Check original */
52+ cl_git_pass (git_submodule_lookup (& sm , g_repo , "sm_unchanged" ));
53+ cl_assert (git_submodule_owner (sm ) == g_repo );
54+ cl_assert_equal_s ("sm_unchanged" , git_submodule_name (sm ));
55+ cl_assert (git__suffixcmp (git_submodule_path (sm ), "sm_unchanged" ) == 0 );
56+ cl_assert (git__suffixcmp (git_submodule_url (sm ), "/submod2_target" ) == 0 );
57+
58+ cl_assert (git_oid_streq (git_submodule_index_id (sm ), oid ) == 0 );
59+ cl_assert (git_oid_streq (git_submodule_head_id (sm ), oid ) == 0 );
60+ cl_assert (git_oid_streq (git_submodule_wd_id (sm ), oid ) == 0 );
61+
62+ cl_assert (git_submodule_ignore (sm ) == GIT_SUBMODULE_IGNORE_NONE );
63+ cl_assert (git_submodule_update_strategy (sm ) == GIT_SUBMODULE_UPDATE_CHECKOUT );
64+
65+ /* Duplicate and free original */
66+ cl_assert (git_submodule_dup (& sm_duplicate , sm ) == 0 );
67+ git_submodule_free (sm );
68+
69+ /* Check duplicate */
70+ cl_assert (git_submodule_owner (sm_duplicate ) == g_repo );
71+ cl_assert_equal_s ("sm_unchanged" , git_submodule_name (sm_duplicate ));
72+ cl_assert (git__suffixcmp (git_submodule_path (sm_duplicate ), "sm_unchanged" ) == 0 );
73+ cl_assert (git__suffixcmp (git_submodule_url (sm_duplicate ), "/submod2_target" ) == 0 );
74+
75+ cl_assert (git_oid_streq (git_submodule_index_id (sm_duplicate ), oid ) == 0 );
76+ cl_assert (git_oid_streq (git_submodule_head_id (sm_duplicate ), oid ) == 0 );
77+ cl_assert (git_oid_streq (git_submodule_wd_id (sm_duplicate ), oid ) == 0 );
78+
79+ cl_assert (git_submodule_ignore (sm_duplicate ) == GIT_SUBMODULE_IGNORE_NONE );
80+ cl_assert (git_submodule_update_strategy (sm_duplicate ) == GIT_SUBMODULE_UPDATE_CHECKOUT );
81+
82+ git_submodule_free (sm_duplicate );
83+ }
84+
4585void test_submodule_lookup__accessors (void )
4686{
4787 git_submodule * sm ;
0 commit comments