Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
43b5075d
Unverified
Commit
43b5075d
authored
Jul 22, 2021
by
Edward Thomson
Committed by
GitHub
Jul 22, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5890 from lolgear/git_submodule_dup
[Submodule] Git submodule dup
parents
c87e4760
54a52452
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
0 deletions
+60
-0
include/git2/submodule.h
+9
-0
src/submodule.c
+11
-0
tests/submodule/lookup.c
+40
-0
No files found.
include/git2/submodule.h
View file @
43b5075d
...
...
@@ -224,6 +224,15 @@ GIT_EXTERN(int) git_submodule_lookup(
const
char
*
name
);
/**
* Create an in-memory copy of a submodule. The copy must be explicitly
* free'd or it will leak.
*
* @param out Pointer to store the copy of the submodule.
* @param source Original submodule to copy.
*/
GIT_EXTERN
(
int
)
git_submodule_dup
(
git_submodule
**
out
,
git_submodule
*
source
);
/**
* Release a submodule
*
* @param submodule Submodule object
...
...
src/submodule.c
View file @
43b5075d
...
...
@@ -1854,6 +1854,17 @@ static void submodule_release(git_submodule *sm)
git__free
(
sm
);
}
int
git_submodule_dup
(
git_submodule
**
out
,
git_submodule
*
source
)
{
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
source
);
GIT_REFCOUNT_INC
(
source
);
*
out
=
source
;
return
0
;
}
void
git_submodule_free
(
git_submodule
*
sm
)
{
if
(
!
sm
)
...
...
tests/submodule/lookup.c
View file @
43b5075d
...
...
@@ -42,6 +42,46 @@ void test_submodule_lookup__simple_lookup(void)
assert_submodule_exists
(
g_repo
,
"sm_added_and_uncommited/"
);
}
void
test_submodule_lookup__can_be_dupped
(
void
)
{
git_submodule
*
sm
;
git_submodule
*
sm_duplicate
;
const
char
*
oid
=
"480095882d281ed676fe5b863569520e54a7d5c0"
;
/* Check original */
cl_git_pass
(
git_submodule_lookup
(
&
sm
,
g_repo
,
"sm_unchanged"
));
cl_assert
(
git_submodule_owner
(
sm
)
==
g_repo
);
cl_assert_equal_s
(
"sm_unchanged"
,
git_submodule_name
(
sm
));
cl_assert
(
git__suffixcmp
(
git_submodule_path
(
sm
),
"sm_unchanged"
)
==
0
);
cl_assert
(
git__suffixcmp
(
git_submodule_url
(
sm
),
"/submod2_target"
)
==
0
);
cl_assert
(
git_oid_streq
(
git_submodule_index_id
(
sm
),
oid
)
==
0
);
cl_assert
(
git_oid_streq
(
git_submodule_head_id
(
sm
),
oid
)
==
0
);
cl_assert
(
git_oid_streq
(
git_submodule_wd_id
(
sm
),
oid
)
==
0
);
cl_assert
(
git_submodule_ignore
(
sm
)
==
GIT_SUBMODULE_IGNORE_NONE
);
cl_assert
(
git_submodule_update_strategy
(
sm
)
==
GIT_SUBMODULE_UPDATE_CHECKOUT
);
/* Duplicate and free original */
cl_assert
(
git_submodule_dup
(
&
sm_duplicate
,
sm
)
==
0
);
git_submodule_free
(
sm
);
/* Check duplicate */
cl_assert
(
git_submodule_owner
(
sm_duplicate
)
==
g_repo
);
cl_assert_equal_s
(
"sm_unchanged"
,
git_submodule_name
(
sm_duplicate
));
cl_assert
(
git__suffixcmp
(
git_submodule_path
(
sm_duplicate
),
"sm_unchanged"
)
==
0
);
cl_assert
(
git__suffixcmp
(
git_submodule_url
(
sm_duplicate
),
"/submod2_target"
)
==
0
);
cl_assert
(
git_oid_streq
(
git_submodule_index_id
(
sm_duplicate
),
oid
)
==
0
);
cl_assert
(
git_oid_streq
(
git_submodule_head_id
(
sm_duplicate
),
oid
)
==
0
);
cl_assert
(
git_oid_streq
(
git_submodule_wd_id
(
sm_duplicate
),
oid
)
==
0
);
cl_assert
(
git_submodule_ignore
(
sm_duplicate
)
==
GIT_SUBMODULE_IGNORE_NONE
);
cl_assert
(
git_submodule_update_strategy
(
sm_duplicate
)
==
GIT_SUBMODULE_UPDATE_CHECKOUT
);
git_submodule_free
(
sm_duplicate
);
}
void
test_submodule_lookup__accessors
(
void
)
{
git_submodule
*
sm
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment