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
db628072
Commit
db628072
authored
May 11, 2012
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed leaks and added tests
parent
dc34da6e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
13 deletions
+34
-13
src/repository.c
+10
-13
tests-clar/repo/init.c
+24
-0
No files found.
src/repository.c
View file @
db628072
...
...
@@ -713,31 +713,28 @@ static int repo_write_template(
const
char
*
git_dir
,
const
char
*
file
,
mode_t
mode
,
const
char
*
content
)
{
git_buf
path
=
GIT_BUF_INIT
;
int
fd
;
int
fd
,
error
=
0
;
if
(
git_buf_joinpath
(
&
path
,
git_dir
,
file
)
<
0
)
return
-
1
;
fd
=
p_open
(
git_buf_cstr
(
&
path
),
O_WRONLY
|
O_CREAT
|
O_EXCL
,
mode
);
if
(
fd
<
0
)
{
git_buf_free
(
&
path
);
if
(
errno
==
EEXIST
)
return
0
;
goto
fail
;
}
if
(
p_write
(
fd
,
content
,
strlen
(
content
))
<
0
)
goto
fail
;
if
(
fd
>=
0
)
{
error
=
p_write
(
fd
,
content
,
strlen
(
content
))
;
p_close
(
fd
);
}
else
if
(
errno
!=
EEXIST
)
error
=
fd
;
return
0
;
fail:
git_buf_free
(
&
path
);
if
(
error
)
giterr_set
(
GITERR_OS
,
"Failed to initialize repository with template '%s'"
,
file
);
return
-
1
;
return
error
;
}
static
int
repo_init_structure
(
const
char
*
git_dir
,
int
is_bare
)
...
...
tests-clar/repo/init.c
View file @
db628072
...
...
@@ -141,3 +141,27 @@ void test_repo_init__reinit_too_recent_bare_repo(void)
cl_fixture_cleanup
(
"reinit.git"
);
}
void
test_repo_init__additional_templates
(
void
)
{
git_buf
path
=
GIT_BUF_INIT
;
cl_set_cleanup
(
&
cleanup_repository
,
"tester"
);
ensure_repository_init
(
"tester"
,
0
,
"tester/.git/"
,
"tester/"
);
cl_git_pass
(
git_buf_joinpath
(
&
path
,
git_repository_path
(
_repo
),
"description"
));
cl_assert
(
git_path_isfile
(
git_buf_cstr
(
&
path
)));
cl_git_pass
(
git_buf_joinpath
(
&
path
,
git_repository_path
(
_repo
),
"info/exclude"
));
cl_assert
(
git_path_isfile
(
git_buf_cstr
(
&
path
)));
cl_git_pass
(
git_buf_joinpath
(
&
path
,
git_repository_path
(
_repo
),
"hooks"
));
cl_assert
(
git_path_isdir
(
git_buf_cstr
(
&
path
)));
/* won't confirm specific contents of hooks dir since it may vary */
git_buf_free
(
&
path
);
}
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