mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-05 17:12:51 +00:00
Fix repository initialization
We cannot assume that non-bare repositories have an index file, because 'git index' doesn't create it by default. Signed-off-by: Vicent Marti <tanoku@gmail.com>
This commit is contained in:
parent
d7c7cab8a4
commit
50dd6ca54c
@ -68,8 +68,8 @@ int git__objtable_haskey(void *object, const void *key)
|
|||||||
|
|
||||||
static int parse_repository_folders(git_repository *repo, const char *repository_path)
|
static int parse_repository_folders(git_repository *repo, const char *repository_path)
|
||||||
{
|
{
|
||||||
char path_aux[GIT_PATH_MAX];
|
char path_aux[GIT_PATH_MAX], *last_folder;
|
||||||
int path_len, i;
|
int path_len;
|
||||||
|
|
||||||
if (gitfo_isdir(repository_path) < 0)
|
if (gitfo_isdir(repository_path) < 0)
|
||||||
return GIT_ENOTAREPO;
|
return GIT_ENOTAREPO;
|
||||||
@ -97,22 +97,24 @@ static int parse_repository_folders(git_repository *repo, const char *repository
|
|||||||
if (gitfo_exists(path_aux) < 0)
|
if (gitfo_exists(path_aux) < 0)
|
||||||
return GIT_ENOTAREPO;
|
return GIT_ENOTAREPO;
|
||||||
|
|
||||||
i = path_len - 2;
|
path_aux[path_len] = 0;
|
||||||
while (path_aux[i] != '/')
|
|
||||||
i--;
|
|
||||||
|
|
||||||
if (strcmp(path_aux, "/.git/") == 0) {
|
last_folder = (path_aux + path_len - 2);
|
||||||
|
|
||||||
|
while (*last_folder != '/')
|
||||||
|
last_folder--;
|
||||||
|
|
||||||
|
if (strcmp(last_folder, "/.git/") == 0) {
|
||||||
repo->is_bare = 0;
|
repo->is_bare = 0;
|
||||||
|
|
||||||
path_aux[i + 1] = 0;
|
|
||||||
repo->path_workdir = git__strdup(path_aux);
|
|
||||||
|
|
||||||
/* index file */
|
/* index file */
|
||||||
strcpy(path_aux + path_len, "index");
|
strcpy(path_aux + path_len, "index");
|
||||||
if (gitfo_exists(path_aux) < 0)
|
|
||||||
return GIT_ENOTAREPO;
|
|
||||||
repo->path_index = git__strdup(path_aux);
|
repo->path_index = git__strdup(path_aux);
|
||||||
|
|
||||||
|
/* working dir */
|
||||||
|
*(last_folder + 1) = 0;
|
||||||
|
repo->path_workdir = git__strdup(path_aux);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
repo->is_bare = 1;
|
repo->is_bare = 1;
|
||||||
repo->path_workdir = NULL;
|
repo->path_workdir = NULL;
|
||||||
@ -199,7 +201,7 @@ git_index *git_repository_index(git_repository *repo)
|
|||||||
if (git_index_open_inrepo(&repo->index, repo) < 0)
|
if (git_index_open_inrepo(&repo->index, repo) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
assert(repo->index && repo->index->on_disk);
|
assert(repo->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
return repo->index;
|
return repo->index;
|
||||||
|
Loading…
Reference in New Issue
Block a user