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
41233c40
Commit
41233c40
authored
Apr 08, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new method `git_repository_is_empty`
parent
cef75d74
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
0 deletions
+41
-0
include/git2/repository.h
+12
-0
src/repository.c
+15
-0
tests/t12-repo.c
+14
-0
No files found.
include/git2/repository.h
View file @
41233c40
...
@@ -182,6 +182,18 @@ GIT_EXTERN(void) git_repository_free(git_repository *repo);
...
@@ -182,6 +182,18 @@ GIT_EXTERN(void) git_repository_free(git_repository *repo);
*/
*/
GIT_EXTERN
(
int
)
git_repository_init
(
git_repository
**
repo_out
,
const
char
*
path
,
unsigned
is_bare
);
GIT_EXTERN
(
int
)
git_repository_init
(
git_repository
**
repo_out
,
const
char
*
path
,
unsigned
is_bare
);
/**
* Check if a repository is empty
*
* An empty repository has just been initialized and contains
* no commits.
*
* @param repo Repo to test
* @return 1 if the repository is empty, 0 if it isn't, error code
* if the repository is corrupted
*/
GIT_EXTERN
(
int
)
git_repository_is_empty
(
git_repository
*
repo
);
/** @} */
/** @} */
GIT_END_DECL
GIT_END_DECL
#endif
#endif
src/repository.c
View file @
41233c40
...
@@ -473,3 +473,18 @@ cleanup:
...
@@ -473,3 +473,18 @@ cleanup:
return
error
;
return
error
;
}
}
int
git_repository_is_empty
(
git_repository
*
repo
)
{
git_reference
*
head
,
*
branch
;
int
error
;
error
=
git_reference_lookup
(
&
head
,
repo
,
"HEAD"
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
if
(
git_reference_type
(
head
)
!=
GIT_REF_SYMBOLIC
)
return
GIT_EOBJCORRUPTED
;
return
git_reference_resolve
(
&
branch
,
head
)
==
GIT_SUCCESS
?
0
:
1
;
}
tests/t12-repo.c
View file @
41233c40
...
@@ -244,6 +244,19 @@ BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of t
...
@@ -244,6 +244,19 @@ BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of t
rmdir_recurs
(
TEMP_REPO_FOLDER
);
rmdir_recurs
(
TEMP_REPO_FOLDER
);
END_TEST
END_TEST
BEGIN_TEST
(
empty0
,
"test if a repository is empty or not"
)
git_repository
*
repo_empty
,
*
repo_normal
;
must_pass
(
git_repository_open
(
&
repo_normal
,
REPOSITORY_FOLDER
));
must_be_true
(
git_repository_is_empty
(
repo_normal
)
==
0
);
git_repository_free
(
repo_normal
);
must_pass
(
git_repository_open
(
&
repo_empty
,
EMPTY_BARE_REPOSITORY_FOLDER
));
must_be_true
(
git_repository_is_empty
(
repo_empty
)
==
1
);
git_repository_free
(
repo_empty
);
END_TEST
BEGIN_SUITE
(
repository
)
BEGIN_SUITE
(
repository
)
ADD_TEST
(
odb0
);
ADD_TEST
(
odb0
);
ADD_TEST
(
odb1
);
ADD_TEST
(
odb1
);
...
@@ -253,5 +266,6 @@ BEGIN_SUITE(repository)
...
@@ -253,5 +266,6 @@ BEGIN_SUITE(repository)
ADD_TEST
(
open0
);
ADD_TEST
(
open0
);
ADD_TEST
(
open1
);
ADD_TEST
(
open1
);
ADD_TEST
(
open2
);
ADD_TEST
(
open2
);
ADD_TEST
(
empty0
);
END_SUITE
END_SUITE
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