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
b282ca79
Commit
b282ca79
authored
Jan 06, 2018
by
Carson Howard
Committed by
Carson Howard
Mar 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
submodule: change can_add_submodule to is_path_occupied
parent
677d393c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
src/submodule.c
+11
-6
No files found.
src/submodule.c
View file @
b282ca79
...
@@ -153,11 +153,12 @@ static int find_by_path(const git_config_entry *entry, void *payload)
...
@@ -153,11 +153,12 @@ static int find_by_path(const git_config_entry *entry, void *payload)
* Checks to see if the submodule shares its name with a file or directory that
* Checks to see if the submodule shares its name with a file or directory that
* already exists on the index. If so, the submodule cannot be added.
* already exists on the index. If so, the submodule cannot be added.
*/
*/
static
int
can_add_submodule
(
git_repository
*
repo
,
const
char
*
path
)
static
int
is_path_occupied
(
bool
*
occupied
,
git_repository
*
repo
,
const
char
*
path
)
{
{
int
error
=
0
;
int
error
=
0
;
git_index
*
index
;
git_index
*
index
;
git_buf
dir
=
GIT_BUF_INIT
;
git_buf
dir
=
GIT_BUF_INIT
;
*
occupied
=
false
;
if
((
error
=
git_repository_index__weakptr
(
&
index
,
repo
))
<
0
)
if
((
error
=
git_repository_index__weakptr
(
&
index
,
repo
))
<
0
)
goto
out
;
goto
out
;
...
@@ -165,10 +166,9 @@ static int can_add_submodule(git_repository *repo, const char *path)
...
@@ -165,10 +166,9 @@ static int can_add_submodule(git_repository *repo, const char *path)
if
((
error
=
git_index_find
(
NULL
,
index
,
path
))
==
0
)
{
if
((
error
=
git_index_find
(
NULL
,
index
,
path
))
==
0
)
{
giterr_set
(
GITERR_SUBMODULE
,
giterr_set
(
GITERR_SUBMODULE
,
"File '%s' already exists in the index"
,
path
);
"File '%s' already exists in the index"
,
path
);
error
=
GIT_EEXISTS
;
*
occupied
=
true
;
goto
out
;
goto
out
;
}
}
error
=
0
;
if
((
error
=
git_buf_sets
(
&
dir
,
path
))
<
0
)
if
((
error
=
git_buf_sets
(
&
dir
,
path
))
<
0
)
goto
out
;
goto
out
;
...
@@ -179,8 +179,7 @@ static int can_add_submodule(git_repository *repo, const char *path)
...
@@ -179,8 +179,7 @@ static int can_add_submodule(git_repository *repo, const char *path)
if
((
error
=
git_index_find_prefix
(
NULL
,
index
,
dir
.
ptr
))
==
0
)
{
if
((
error
=
git_index_find_prefix
(
NULL
,
index
,
dir
.
ptr
))
==
0
)
{
giterr_set
(
GITERR_SUBMODULE
,
giterr_set
(
GITERR_SUBMODULE
,
"Directory '%s' already exists in the index"
,
path
);
"Directory '%s' already exists in the index"
,
path
);
error
=
GIT_EEXISTS
;
*
occupied
=
true
;
goto
out
;
}
}
error
=
0
;
error
=
0
;
...
@@ -704,6 +703,7 @@ int git_submodule_add_setup(
...
@@ -704,6 +703,7 @@ int git_submodule_add_setup(
git_submodule
*
sm
=
NULL
;
git_submodule
*
sm
=
NULL
;
git_buf
name
=
GIT_BUF_INIT
,
real_url
=
GIT_BUF_INIT
;
git_buf
name
=
GIT_BUF_INIT
,
real_url
=
GIT_BUF_INIT
;
git_repository
*
subrepo
=
NULL
;
git_repository
*
subrepo
=
NULL
;
bool
path_occupied
;
assert
(
repo
&&
url
&&
path
);
assert
(
repo
&&
url
&&
path
);
...
@@ -728,9 +728,14 @@ int git_submodule_add_setup(
...
@@ -728,9 +728,14 @@ int git_submodule_add_setup(
goto
cleanup
;
goto
cleanup
;
}
}
if
((
error
=
can_add_submodule
(
repo
,
path
))
<
0
)
if
((
error
=
is_path_occupied
(
&
path_occupied
,
repo
,
path
))
<
0
)
goto
cleanup
;
goto
cleanup
;
if
(
path_occupied
)
{
error
=
GIT_EEXISTS
;
goto
cleanup
;
}
/* update .gitmodules */
/* update .gitmodules */
if
(
!
(
mods
=
open_gitmodules
(
repo
,
GITMODULES_CREATE
)))
{
if
(
!
(
mods
=
open_gitmodules
(
repo
,
GITMODULES_CREATE
)))
{
...
...
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