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
d6073b30
Commit
d6073b30
authored
May 05, 2015
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
submodule: make `_set_url()` affect the configuration
With this one, we can get rid of the edit_and_save test.
parent
486ba4cd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
61 deletions
+17
-61
include/git2/submodule.h
+5
-7
src/submodule.c
+3
-12
tests/submodule/init.c
+3
-3
tests/submodule/modify.c
+6
-39
No files found.
include/git2/submodule.h
View file @
d6073b30
...
@@ -386,20 +386,18 @@ GIT_EXTERN(const char *) git_submodule_branch(git_submodule *submodule);
...
@@ -386,20 +386,18 @@ GIT_EXTERN(const char *) git_submodule_branch(git_submodule *submodule);
GIT_EXTERN
(
int
)
git_submodule_set_branch
(
git_repository
*
repo
,
const
char
*
name
,
const
char
*
branch
);
GIT_EXTERN
(
int
)
git_submodule_set_branch
(
git_repository
*
repo
,
const
char
*
name
,
const
char
*
branch
);
/**
/**
* Set the URL for the submodule
.
* Set the URL for the submodule
in the configuration
*
*
* This sets the URL in memory for the submodule. This will be used for
* any following submodule actions while this submodule data is in memory.
*
*
* After calling this, you may wish to call `git_submodule_save()` to write
* After calling this, you may wish to call `git_submodule_sync()` to
* the changes back to the ".gitmodules" file and `git_submodule_sync()` to
* write the changes to the checked out submodule repository.
* write the changes to the checked out submodule repository.
*
*
* @param submodule Pointer to the submodule object
* @param repo the repository to affect
* @param name the name of the submodule to configure
* @param url URL that should be used for the submodule
* @param url URL that should be used for the submodule
* @return 0 on success, <0 on failure
* @return 0 on success, <0 on failure
*/
*/
GIT_EXTERN
(
int
)
git_submodule_set_url
(
git_
submodule
*
submodul
e
,
const
char
*
url
);
GIT_EXTERN
(
int
)
git_submodule_set_url
(
git_
repository
*
repo
,
const
char
*
nam
e
,
const
char
*
url
);
/**
/**
* Get the OID for the submodule in the index.
* Get the OID for the submodule in the index.
...
...
src/submodule.c
View file @
d6073b30
...
@@ -788,10 +788,6 @@ int git_submodule_save(git_submodule *submodule)
...
@@ -788,10 +788,6 @@ int git_submodule_save(git_submodule *submodule)
(
error
=
git_config_file_set_string
(
mods
,
key
.
ptr
,
submodule
->
path
))
<
0
)
(
error
=
git_config_file_set_string
(
mods
,
key
.
ptr
,
submodule
->
path
))
<
0
)
goto
cleanup
;
goto
cleanup
;
if
((
error
=
submodule_config_key_trunc_puts
(
&
key
,
"url"
))
<
0
||
(
error
=
git_config_file_set_string
(
mods
,
key
.
ptr
,
submodule
->
url
))
<
0
)
goto
cleanup
;
/* update internal defaults */
/* update internal defaults */
submodule
->
ignore_default
=
submodule
->
ignore
;
submodule
->
ignore_default
=
submodule
->
ignore
;
...
@@ -890,16 +886,11 @@ int git_submodule_set_branch(git_repository *repo, const char *name, const char
...
@@ -890,16 +886,11 @@ int git_submodule_set_branch(git_repository *repo, const char *name, const char
return
write_var
(
repo
,
name
,
"branch"
,
branch
);
return
write_var
(
repo
,
name
,
"branch"
,
branch
);
}
}
int
git_submodule_set_url
(
git_
submodule
*
submodul
e
,
const
char
*
url
)
int
git_submodule_set_url
(
git_
repository
*
repo
,
const
char
*
nam
e
,
const
char
*
url
)
{
{
assert
(
submodule
&&
url
);
assert
(
repo
&&
name
&&
url
);
git__free
(
submodule
->
url
);
submodule
->
url
=
git__strdup
(
url
);
return
write_var
(
repo
,
name
,
"url"
,
url
);
GITERR_CHECK_ALLOC
(
submodule
->
url
);
return
0
;
}
}
const
git_oid
*
git_submodule_index_id
(
git_submodule
*
submodule
)
const
git_oid
*
git_submodule_index_id
(
git_submodule
*
submodule
)
...
...
tests/submodule/init.c
View file @
d6073b30
...
@@ -23,10 +23,10 @@ void test_submodule_init__absolute_url(void)
...
@@ -23,10 +23,10 @@ void test_submodule_init__absolute_url(void)
cl_assert
(
git_path_dirname_r
(
&
absolute_url
,
git_repository_workdir
(
g_repo
))
>
0
);
cl_assert
(
git_path_dirname_r
(
&
absolute_url
,
git_repository_workdir
(
g_repo
))
>
0
);
cl_git_pass
(
git_buf_joinpath
(
&
absolute_url
,
absolute_url
.
ptr
,
"testrepo.git"
));
cl_git_pass
(
git_buf_joinpath
(
&
absolute_url
,
absolute_url
.
ptr
,
"testrepo.git"
));
cl_git_pass
(
git_submodule_lookup
(
&
sm
,
g_repo
,
"testrepo"
));
/* write the absolute url to the .gitmodules file*/
/* write the absolute url to the .gitmodules file*/
cl_git_pass
(
git_submodule_set_url
(
sm
,
absolute_url
.
ptr
));
cl_git_pass
(
git_submodule_set_url
(
g_repo
,
"testrepo"
,
absolute_url
.
ptr
));
cl_git_pass
(
git_submodule_lookup
(
&
sm
,
g_repo
,
"testrepo"
));
/* verify that the .gitmodules is set with an absolute path*/
/* verify that the .gitmodules is set with an absolute path*/
cl_assert_equal_s
(
absolute_url
.
ptr
,
git_submodule_url
(
sm
));
cl_assert_equal_s
(
absolute_url
.
ptr
,
git_submodule_url
(
sm
));
...
...
tests/submodule/modify.c
View file @
d6073b30
...
@@ -185,47 +185,14 @@ void test_submodule_modify__set_branch(void)
...
@@ -185,47 +185,14 @@ void test_submodule_modify__set_branch(void)
git_submodule_free
(
sm
);
git_submodule_free
(
sm
);
}
}
void
test_submodule_modify__
edit_and_save
(
void
)
void
test_submodule_modify__
set_url
(
void
)
{
{
git_submodule
*
sm1
,
*
sm2
;
git_submodule
*
sm
;
char
*
old_url
;
git_repository
*
r2
;
cl_git_pass
(
git_submodule_lookup
(
&
sm1
,
g_repo
,
"sm_changed_head"
));
old_url
=
git__strdup
(
git_submodule_url
(
sm1
));
/* modify properties of submodule */
cl_git_pass
(
git_submodule_set_url
(
sm1
,
SM_LIBGIT2_URL
));
cl_assert_equal_s
(
SM_LIBGIT2_URL
,
git_submodule_url
(
sm1
));
/* revert without saving (and confirm setters return old value) */
cl_git_pass
(
git_submodule_set_url
(
sm1
,
old_url
));
/* check that revert was successful */
cl_assert_equal_s
(
old_url
,
git_submodule_url
(
sm1
));
/* modify properties of submodule (again) */
cl_git_pass
(
git_submodule_set_url
(
sm1
,
SM_LIBGIT2_URL
));
/* call save */
cl_git_pass
(
git_submodule_save
(
sm1
));
/* call reload and check that the new values are loaded */
cl_git_pass
(
git_submodule_reload
(
sm1
,
0
));
cl_assert_equal_s
(
SM_LIBGIT2_URL
,
git_submodule_url
(
sm1
));
/* open a second copy of the repo and compare submodule */
cl_git_pass
(
git_repository_open
(
&
r2
,
"submod2"
));
cl_git_pass
(
git_submodule_lookup
(
&
sm2
,
r2
,
"sm_changed_head"
));
cl_assert_equal_s
(
SM_LIBGIT2_URL
,
git_submodule_url
(
sm2
));
git_submodule_free
(
sm1
);
cl_git_pass
(
git_submodule_set_url
(
g_repo
,
"sm_changed_head"
,
SM_LIBGIT2_URL
)
);
git_submodule_free
(
sm2
);
cl_git_pass
(
git_submodule_lookup
(
&
sm
,
g_repo
,
"sm_changed_head"
)
);
git_repository_free
(
r2
);
cl_assert_equal_s
(
SM_LIBGIT2_URL
,
git_submodule_url
(
sm
)
);
git_
_free
(
old_url
);
git_
submodule_free
(
sm
);
}
}
void
test_submodule_modify__save_last
(
void
)
void
test_submodule_modify__save_last
(
void
)
...
...
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