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
99a07f0f
Commit
99a07f0f
authored
Jan 25, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #541 from nulltoken/topic/repo-reinit
Repository re-initialization
parents
911ff94e
5663e61a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
56 deletions
+98
-56
src/repository.c
+43
-7
tests-clar/repo/init.c
+55
-18
tests-clar/repo/open.c
+0
-31
No files found.
src/repository.c
View file @
99a07f0f
...
...
@@ -24,6 +24,8 @@
#define GIT_BRANCH_MASTER "master"
#define GIT_CONFIG_CORE_REPOSITORYFORMATVERSION "core.repositoryformatversion"
#define GIT_REPOSITORYFORMATVERSION 0
static
void
drop_odb
(
git_repository
*
repo
)
{
...
...
@@ -628,12 +630,46 @@ cleanup:
return
error
;
}
static
int
repo_init_reinit
(
const
char
*
repository_path
,
int
is_bare
)
static
int
check_repositoryformatversion
(
git_repository
*
repo
)
{
/* TODO: reinit the repository */
return
git__throw
(
GIT_ENOTIMPLEMENTED
,
"Failed to reinitialize the %srepository at '%s'. "
"This feature is not yet implemented"
,
git_config
*
config
;
int
version
,
error
=
GIT_SUCCESS
;
if
((
error
=
git_repository_config
(
&
config
,
repo
))
<
GIT_SUCCESS
)
return
git__throw
(
error
,
"Failed to open config file."
);
error
=
git_config_get_int32
(
config
,
GIT_CONFIG_CORE_REPOSITORYFORMATVERSION
,
&
version
);
if
(
GIT_REPOSITORYFORMATVERSION
<
version
)
error
=
git__throw
(
GIT_ERROR
,
"Unsupported git repository version (Expected version <= %d, found %d)."
,
GIT_REPOSITORYFORMATVERSION
,
version
);
git_config_free
(
config
);
return
error
;
}
static
int
repo_init_reinit
(
git_repository
**
repo_out
,
const
char
*
repository_path
,
int
is_bare
)
{
int
error
;
git_repository
*
repo
=
NULL
;
if
((
error
=
git_repository_open
(
&
repo
,
repository_path
))
<
GIT_SUCCESS
)
goto
error
;
if
((
error
=
check_repositoryformatversion
(
repo
))
<
GIT_SUCCESS
)
goto
error
;
/* TODO: reinitialize the templates */
*
repo_out
=
repo
;
return
GIT_SUCCESS
;
error:
git_repository_free
(
repo
);
return
git__rethrow
(
error
,
"Failed to reinitialize the %srepository at '%s'. "
,
is_bare
?
"bare "
:
""
,
repository_path
);
}
...
...
@@ -673,7 +709,7 @@ static int repo_init_config(const char *git_dir, int is_bare)
goto
cleanup
;
SET_REPO_CONFIG
(
bool
,
"core.bare"
,
is_bare
);
SET_REPO_CONFIG
(
int32
,
"core.repositoryformatversion"
,
0
);
SET_REPO_CONFIG
(
int32
,
GIT_CONFIG_CORE_REPOSITORYFORMATVERSION
,
GIT_REPOSITORYFORMATVERSION
);
/* TODO: what other defaults? */
cleanup:
...
...
@@ -735,7 +771,7 @@ int git_repository_init(git_repository **repo_out, const char *path, unsigned is
if
(
git_path_isdir
(
repository_path
.
ptr
)
==
GIT_SUCCESS
)
{
if
(
quickcheck_repository_dir
(
&
repository_path
)
==
GIT_SUCCESS
)
{
error
=
repo_init_reinit
(
repository_path
.
ptr
,
is_bare
);
error
=
repo_init_reinit
(
repo
_out
,
repo
sitory_path
.
ptr
,
is_bare
);
git_buf_free
(
&
repository_path
);
return
error
;
}
...
...
tests-clar/repo/init.c
View file @
99a07f0f
#include "clar_libgit2.h"
#include "fileops.h"
#include "repository.h"
#include "config.h"
enum
repo_mode
{
STANDARD_REPOSITORY
=
0
,
...
...
@@ -75,32 +77,67 @@ void test_repo_init__bare_repo_noslash(void)
ensure_repository_init
(
"testrepo.git"
,
1
,
"testrepo.git/"
,
NULL
);
}
#if 0
BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping out of the current working directory")
void
test_repo_init__bare_repo_escaping_current_workdir
(
void
)
{
git_buf
path_repository
=
GIT_BUF_INIT
;
char current_workdir[GIT_PATH_MAX];
const mode_t mode = 0777;
git_repository* repo;
git_buf
path_current_workdir
=
GIT_BUF_INIT
;
cl_git_pass
(
git_path_prettify_dir
(
&
path_current_workdir
,
"."
,
NULL
));
cl_git_pass
(
git_buf_joinpath
(
&
path_repository
,
git_buf_cstr
(
&
path_current_workdir
),
"a/b/c"
));
cl_git_pass
(
git_futils_mkdir_r
(
git_buf_cstr
(
&
path_repository
),
NULL
,
GIT_DIR_MODE
));
/* Change the current working directory */
cl_git_pass
(
chdir
(
git_buf_cstr
(
&
path_repository
)));
must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
/* Initialize a bare repo with a relative path escaping out of the current working directory */
cl_git_pass
(
git_repository_init
(
&
_repo
,
"../d/e.git"
,
1
));
cl_git_pass
(
git__suffixcmp
(
git_repository_path
(
_repo
),
"/a/b/d/e.git/"
));
git_repository_free
(
_repo
);
must_pass(git_buf_joinpath(&path_repository, TEMP_REPO_FOLDER, "a/b/c/"));
must_pass(git_futils_mkdir_r(path_repository.ptr, mode
));
/* Open a bare repo with a relative path escaping out of the current working directory */
cl_git_pass
(
git_repository_open
(
&
_repo
,
"../d/e.git"
));
must_pass(chdir(path_repository.ptr
));
cl_git_pass
(
chdir
(
git_buf_cstr
(
&
path_current_workdir
)
));
git_buf_free
(
&
path_current_workdir
);
git_buf_free
(
&
path_repository
);
must_pass(git_repository_init(&repo, "../d/e.git", 1));
must_pass(git__suffixcmp(git_repository_path(_repo), "/a/b/d/e.git/"));
cleanup_repository
(
"a"
);
}
void
test_repo_init__reinit_bare_repo
(
void
)
{
cl_set_cleanup
(
&
cleanup_repository
,
"reinit.git"
);
/* Initialize the repository */
cl_git_pass
(
git_repository_init
(
&
_repo
,
"reinit.git"
,
1
));
git_repository_free
(
_repo
);
git_repository_free(repo);
/* Reinitialize the repository */
cl_git_pass
(
git_repository_init
(
&
_repo
,
"reinit.git"
,
1
));
}
must_pass(git_repository_open(&repo, "../d/e.git"));
void
test_repo_init__reinit_too_recent_bare_repo
(
void
)
{
git_config
*
config
;
git_repository_free(repo);
/* Initialize the repository */
cl_git_pass
(
git_repository_init
(
&
_repo
,
"reinit.git"
,
1
));
git_repository_config
(
&
config
,
_repo
);
must_pass(chdir(current_workdir));
must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1));
END_TEST
#endif
/*
* Hack the config of the repository to make it look like it has
* been created by a recenter version of git/libgit2
*/
cl_git_pass
(
git_config_set_int32
(
config
,
"core.repositoryformatversion"
,
42
));
git_config_free
(
config
);
git_repository_free
(
_repo
);
/* Try to reinitialize the repository */
cl_git_fail
(
git_repository_init
(
&
_repo
,
"reinit.git"
,
1
));
cl_fixture_cleanup
(
"reinit.git"
);
}
tests-clar/repo/open.c
View file @
99a07f0f
...
...
@@ -22,34 +22,3 @@ void test_repo_open__standard_empty_repo(void)
git_repository_free
(
repo
);
}
/* TODO TODO */
#if 0
BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of the current working directory")
char current_workdir[GIT_PATH_MAX];
git_buf new_current_workdir = GIT_BUF_INIT;
git_buf path_repository = GIT_BUF_INIT;
const mode_t mode = 0777;
git_repository* repo;
/* Setup the repository to open */
must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
must_pass(git_buf_join_n(&path_repository, 3, current_workdir, TEMP_REPO_FOLDER, "a/d/e.git"));
must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository.ptr));
git_buf_free(&path_repository);
/* Change the current working directory */
must_pass(git_buf_joinpath(&new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/"));
must_pass(git_futils_mkdir_r(new_current_workdir.ptr, mode));
must_pass(chdir(new_current_workdir.ptr));
git_buf_free(&new_current_workdir);
must_pass(git_repository_open(&repo, "../../d/e.git"));
git_repository_free(repo);
must_pass(chdir(current_workdir));
must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1));
END_TEST
#endif
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