Commit 874c3b6f by Vicent Marti

Fix repository initialization

Fixed several issues with path joining and bare repos.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent cb77ad0d
...@@ -581,7 +581,7 @@ static int repo_init_structure(repo_init *results) ...@@ -581,7 +581,7 @@ static int repo_init_structure(repo_init *results)
strcpy(temp_path, git_dir); strcpy(temp_path, git_dir);
/* Does HEAD file already exist ? */ /* Does HEAD file already exist ? */
strcpy(temp_path + path_len, GIT_HEAD_FILE); git__joinpath(temp_path, git_dir, GIT_HEAD_FILE);
if (gitfo_exists(temp_path) == GIT_SUCCESS) if (gitfo_exists(temp_path) == GIT_SUCCESS)
return repo_init_reinit(results); return repo_init_reinit(results);
...@@ -590,22 +590,22 @@ static int repo_init_structure(repo_init *results) ...@@ -590,22 +590,22 @@ static int repo_init_structure(repo_init *results)
return GIT_ERROR; return GIT_ERROR;
/* Creates the '/objects/info/' directory */ /* Creates the '/objects/info/' directory */
strcpy(temp_path + path_len, GIT_OBJECTS_INFO_DIR); git__joinpath(temp_path, git_dir, GIT_OBJECTS_INFO_DIR);
if (gitfo_mkdir_recurs(temp_path, mode)) if (gitfo_mkdir_recurs(temp_path, mode) < GIT_SUCCESS)
return GIT_ERROR; return GIT_ERROR;
/* Creates the '/objects/pack/' directory */ /* Creates the '/objects/pack/' directory */
strcpy(temp_path + path_len, GIT_OBJECTS_PACK_DIR); git__joinpath(temp_path, git_dir, GIT_OBJECTS_PACK_DIR);
if (gitfo_mkdir(temp_path, mode)) if (gitfo_mkdir(temp_path, mode))
return GIT_ERROR; return GIT_ERROR;
/* Creates the '/refs/heads/' directory */ /* Creates the '/refs/heads/' directory */
strcpy(temp_path + path_len, GIT_REFS_HEADS_DIR); git__joinpath(temp_path, git_dir, GIT_REFS_HEADS_DIR);
if (gitfo_mkdir_recurs(temp_path, mode)) if (gitfo_mkdir_recurs(temp_path, mode))
return GIT_ERROR; return GIT_ERROR;
/* Creates the '/refs/tags/' directory */ /* Creates the '/refs/tags/' directory */
strcpy(temp_path + path_len, GIT_REFS_TAGS_DIR); git__joinpath(temp_path, git_dir, GIT_REFS_TAGS_DIR);
if (gitfo_mkdir(temp_path, mode)) if (gitfo_mkdir(temp_path, mode))
return GIT_ERROR; return GIT_ERROR;
...@@ -617,23 +617,21 @@ static int repo_init_structure(repo_init *results) ...@@ -617,23 +617,21 @@ static int repo_init_structure(repo_init *results)
static int repo_init_find_dir(repo_init *results, const char* path) static int repo_init_find_dir(repo_init *results, const char* path)
{ {
char temp_path[GIT_PATH_MAX]; char temp_path[GIT_PATH_MAX];
int path_len;
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
error = gitfo_prettify_dir_path(temp_path, path); error = gitfo_prettify_dir_path(temp_path, path);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return error; return error;
path_len = strlen(temp_path); /*
if (gitfo_isdir(temp_path) < GIT_SUCCESS)
return GIT_ENOTAREPO;
*/
if (!results->is_bare) { if (!results->is_bare) {
strcpy(temp_path + path_len - 1, GIT_DIR); git__joinpath(temp_path, temp_path, GIT_DIR);
path_len = path_len + strlen(GIT_DIR) - 1; /* Skip the leading slash from the constant */
} }
if (path_len >= GIT_PATH_MAX - MAX_GITDIR_TREE_STRUCTURE_PATH_LENGTH)
return GIT_ENOTAREPO;
results->path_repository = git__strdup(temp_path); results->path_repository = git__strdup(temp_path);
if (results->path_repository == NULL) if (results->path_repository == NULL)
return GIT_ENOMEM; return GIT_ENOMEM;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment