mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-20 20:23:26 +00:00
commit
4811c1500b
@ -657,6 +657,15 @@ GIT_EXTERN(int) git_repository_set_namespace(git_repository *repo, const char *n
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_repository_get_namespace(git_repository *repo);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the repository was a shallow clone
|
||||
*
|
||||
* @param repo The repository
|
||||
* @return 1 if shallow, zero if not
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_is_shallow(git_repository *repo);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
|
@ -1822,3 +1822,20 @@ int git_repository_state(git_repository *repo)
|
||||
git_buf_free(&repo_path);
|
||||
return state;
|
||||
}
|
||||
|
||||
int git_repository_is_shallow(git_repository *repo)
|
||||
{
|
||||
git_buf path = GIT_BUF_INIT;
|
||||
struct stat st;
|
||||
int error;
|
||||
|
||||
git_buf_joinpath(&path, repo->path_repository, "shallow");
|
||||
error = git_path_lstat(path.ptr, &st);
|
||||
git_buf_free(&path);
|
||||
|
||||
if (error == GIT_ENOTFOUND)
|
||||
return 0;
|
||||
if (error < 0)
|
||||
return -1;
|
||||
return st.st_size == 0 ? 0 : 1;
|
||||
}
|
||||
|
33
tests-clar/repo/shallow.c
Normal file
33
tests-clar/repo/shallow.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include "clar_libgit2.h"
|
||||
#include "fileops.h"
|
||||
|
||||
static git_repository *g_repo;
|
||||
|
||||
void test_repo_shallow__initialize(void)
|
||||
{
|
||||
}
|
||||
|
||||
void test_repo_shallow__cleanup(void)
|
||||
{
|
||||
cl_git_sandbox_cleanup();
|
||||
}
|
||||
|
||||
void test_repo_shallow__no_shallow_file(void)
|
||||
{
|
||||
g_repo = cl_git_sandbox_init("testrepo.git");
|
||||
cl_assert_equal_i(0, git_repository_is_shallow(g_repo));
|
||||
}
|
||||
|
||||
void test_repo_shallow__empty_shallow_file(void)
|
||||
{
|
||||
g_repo = cl_git_sandbox_init("testrepo.git");
|
||||
cl_git_mkfile("testrepo.git/shallow", "");
|
||||
cl_assert_equal_i(0, git_repository_is_shallow(g_repo));
|
||||
}
|
||||
|
||||
void test_repo_shallow__shallow_repo(void)
|
||||
{
|
||||
g_repo = cl_git_sandbox_init("shallow.git");
|
||||
cl_assert_equal_i(1, git_repository_is_shallow(g_repo));
|
||||
}
|
||||
|
1
tests-clar/resources/shallow.git/HEAD
Normal file
1
tests-clar/resources/shallow.git/HEAD
Normal file
@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
8
tests-clar/resources/shallow.git/config
Normal file
8
tests-clar/resources/shallow.git/config
Normal file
@ -0,0 +1,8 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = true
|
||||
ignorecase = true
|
||||
precomposeunicode = false
|
||||
[remote "origin"]
|
||||
url = file://testrepo.git
|
Binary file not shown.
Binary file not shown.
2
tests-clar/resources/shallow.git/packed-refs
Normal file
2
tests-clar/resources/shallow.git/packed-refs
Normal file
@ -0,0 +1,2 @@
|
||||
# pack-refs with: peeled
|
||||
a65fedf39aefe402d3bb6e24df4d4f5fe4547750 refs/heads/master
|
0
tests-clar/resources/shallow.git/refs/.gitkeep
Normal file
0
tests-clar/resources/shallow.git/refs/.gitkeep
Normal file
1
tests-clar/resources/shallow.git/shallow
Normal file
1
tests-clar/resources/shallow.git/shallow
Normal file
@ -0,0 +1 @@
|
||||
be3563ae3f795b2b4353bcce3a527ad0a4f7f644
|
Loading…
Reference in New Issue
Block a user