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
9371149f
Commit
9371149f
authored
Oct 20, 2017
by
Carson Howard
Committed by
Carson Howard
Mar 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
submodule: fix styling errors
parent
3e500fc8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
61 deletions
+50
-61
src/submodule.c
+36
-29
tests/submodule/add.c
+14
-32
No files found.
src/submodule.c
View file @
9371149f
...
@@ -149,6 +149,41 @@ static int find_by_path(const git_config_entry *entry, void *payload)
...
@@ -149,6 +149,41 @@ static int find_by_path(const git_config_entry *entry, void *payload)
return
0
;
return
0
;
}
}
static
int
can_add_submodule
(
git_repository
*
repo
,
const
char
*
path
)
{
int
error
;
git_index
*
index
;
git_buf
dir
=
GIT_BUF_INIT
;
if
((
error
=
git_buf_sets
(
&
dir
,
path
))
<
0
)
return
error
;
if
((
error
=
git_path_to_dir
(
&
dir
))
<
0
)
return
error
;
/* get the index for the repo */
if
((
error
=
git_repository_index__weakptr
(
&
index
,
repo
))
<
0
)
return
error
;
/* see if the submodule name exists as a file on the index */
if
((
error
=
git_index_find
(
NULL
,
index
,
path
))
==
0
)
{
giterr_set
(
GITERR_SUBMODULE
,
"'%s' already exists in the index"
,
path
);
return
GIT_EEXISTS
;
}
/* see if the submodule name exists as a directory on the index */
if
((
error
=
git_index_find_prefix
(
NULL
,
index
,
dir
.
ptr
))
==
0
)
{
giterr_set
(
GITERR_SUBMODULE
,
"'%s' already exists in the index"
,
path
);
return
GIT_EEXISTS
;
}
return
0
;
}
/**
/**
* Release the name map returned by 'load_submodule_names'.
* Release the name map returned by 'load_submodule_names'.
*/
*/
...
@@ -660,10 +695,7 @@ int git_submodule_add_setup(
...
@@ -660,10 +695,7 @@ int git_submodule_add_setup(
int
use_gitlink
)
int
use_gitlink
)
{
{
int
error
=
0
;
int
error
=
0
;
size_t
path_len
;
const
char
*
dir
;
git_config_backend
*
mods
=
NULL
;
git_config_backend
*
mods
=
NULL
;
git_index
*
index
;
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
;
...
@@ -691,34 +723,9 @@ int git_submodule_add_setup(
...
@@ -691,34 +723,9 @@ int git_submodule_add_setup(
goto
cleanup
;
goto
cleanup
;
}
}
/* get the index for the repo */
if
((
error
=
can_add_submodule
(
repo
,
path
))
<
0
)
if
((
error
=
git_repository_index__weakptr
(
&
index
,
repo
))
<
0
)
goto
cleanup
;
goto
cleanup
;
/* see if the submodule name exists as a file on the index */
if
((
error
=
git_index_find
(
NULL
,
index
,
path
))
==
0
)
{
giterr_set
(
GITERR_SUBMODULE
,
"'%s' already exists in the index"
,
path
);
return
GIT_EEXISTS
;
}
/* We need the path to end with '/' so we can check it as a directory prefix */
path_len
=
strlen
(
path
);
dir
=
git__malloc
(
path_len
+
1
);
strcpy
(
dir
,
path
);
git_path_string_to_dir
(
dir
,
path_len
+
1
);
/* see if the submodule name exists as a directory on the index */
if
((
error
=
git_index_find_prefix
(
NULL
,
index
,
dir
))
==
0
)
{
giterr_set
(
GITERR_SUBMODULE
,
"'%s' already exists in the index"
,
path
);
return
GIT_EEXISTS
;
}
/* update .gitmodules */
/* update .gitmodules */
if
(
!
(
mods
=
open_gitmodules
(
repo
,
GITMODULES_CREATE
)))
{
if
(
!
(
mods
=
open_gitmodules
(
repo
,
GITMODULES_CREATE
)))
{
...
...
tests/submodule/add.c
View file @
9371149f
...
@@ -135,31 +135,22 @@ void test_submodule_add__path_exists_in_index(void)
...
@@ -135,31 +135,22 @@ void test_submodule_add__path_exists_in_index(void)
git_submodule
*
sm
;
git_submodule
*
sm
;
git_buf
dirname
=
GIT_BUF_INIT
;
git_buf
dirname
=
GIT_BUF_INIT
;
git_buf
filename
=
GIT_BUF_INIT
;
git_buf
filename
=
GIT_BUF_INIT
;
FILE
*
fd
;
/* In this repo, HEAD (master) has no remote tracking branc h*/
/* In this repo, HEAD (master) has no remote tracking branc h*/
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
git_buf_joinpath
(
&
dirname
,
git_repository_workdir
(
g_repo
),
"TestGitRepository"
);
cl_git_pass
(
git_buf_joinpath
(
&
dirname
,
git_repository_workdir
(
g_repo
),
"TestGitRepository"
)
);
git_buf_joinpath
(
&
filename
,
dirname
.
ptr
,
"test.txt"
);
cl_git_pass
(
git_buf_joinpath
(
&
filename
,
dirname
.
ptr
,
"test.txt"
)
);
p_mkdir
(
dirname
.
ptr
,
0700
);
cl_git_pass
(
p_mkdir
(
dirname
.
ptr
,
0700
));
fd
=
fopen
(
filename
.
ptr
,
"w"
);
cl_git_mkfile
(
filename
.
ptr
,
"This is some content"
);
fclose
(
fd
);
cl_git_pass
(
cl_git_pass
(
git_repository_index__weakptr
(
&
index
,
g_repo
));
git_repository_index__weakptr
(
&
index
,
g_repo
)
cl_git_pass
(
git_index_add_bypath
(
index
,
"TestGitRepository/test.txt"
));
);
cl_git_pass
(
cl_git_fail_with
(
git_submodule_add_setup
(
&
sm
,
g_repo
,
"./"
,
"TestGitRepository"
,
1
),
GIT_EEXISTS
);
git_index_add_bypath
(
index
,
"TestGitRepository/test.txt"
)
);
cl_git_fail_with
(
git_submodule_add_setup
(
&
sm
,
g_repo
,
"./"
,
"TestGitRepository"
,
1
),
GIT_EEXISTS
);
git_submodule_free
(
sm
);
git_buf_free
(
&
dirname
);
git_buf_free
(
&
dirname
);
git_buf_free
(
&
filename
);
git_buf_free
(
&
filename
);
}
}
...
@@ -169,28 +160,19 @@ void test_submodule_add__file_exists_in_index(void)
...
@@ -169,28 +160,19 @@ void test_submodule_add__file_exists_in_index(void)
git_index
*
index
;
git_index
*
index
;
git_submodule
*
sm
;
git_submodule
*
sm
;
git_buf
name
=
GIT_BUF_INIT
;
git_buf
name
=
GIT_BUF_INIT
;
FILE
*
fd
;
/* In this repo, HEAD (master) has no remote tracking branc h*/
/* In this repo, HEAD (master) has no remote tracking branc h*/
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
git_buf_joinpath
(
&
name
,
git_repository_workdir
(
g_repo
),
"TestGitRepository"
);
cl_git_pass
(
git_buf_joinpath
(
&
name
,
git_repository_workdir
(
g_repo
),
"TestGitRepository"
)
);
fd
=
fopen
(
name
.
ptr
,
"w"
);
cl_git_mkfile
(
name
.
ptr
,
"Test content"
);
fclose
(
fd
);
cl_git_pass
(
cl_git_pass
(
git_repository_index__weakptr
(
&
index
,
g_repo
));
git_repository_index__weakptr
(
&
index
,
g_repo
)
cl_git_pass
(
git_index_add_bypath
(
index
,
"TestGitRepository"
));
);
cl_git_pass
(
cl_git_fail_with
(
git_submodule_add_setup
(
&
sm
,
g_repo
,
"./"
,
"TestGitRepository"
,
1
),
GIT_EEXISTS
);
git_index_add_bypath
(
index
,
"TestGitRepository"
)
);
cl_git_fail_with
(
git_submodule_add_setup
(
&
sm
,
g_repo
,
"./"
,
"TestGitRepository"
,
1
),
GIT_EEXISTS
);
git_submodule_free
(
sm
);
git_buf_free
(
&
name
);
git_buf_free
(
&
name
);
}
}
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