summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2013-04-17 04:46:37 +0200
committerVicent Marti <tanoku@gmail.com>2013-04-17 04:46:37 +0200
commita442ed687d4c01a68de9aa7b0e50902f17a1ea84 (patch)
tree0f0aa7855addf766a8d22fcf04a4728c606f1989 /src
parentf124ebd457bfbf43de3516629aaba5a279636e04 (diff)
downloadlibgit2-vmg/bare-open.tar.gz
repository: Add `git_repository_open_bare`vmg/bare-open
Diffstat (limited to 'src')
-rw-r--r--src/repository.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/repository.c b/src/repository.c
index 0ad7449ba..64ab2f4db 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -368,6 +368,37 @@ static int find_repo(
return error;
}
+int git_repository_open_bare(
+ git_repository **repo_ptr,
+ const char *bare_path)
+{
+ int error;
+ git_buf path = GIT_BUF_INIT;
+ git_repository *repo = NULL;
+
+ if ((error = git_path_prettify_dir(&path, bare_path, NULL)) < 0)
+ return error;
+
+ if (!valid_repository_path(&path)) {
+ git_buf_free(&path);
+ giterr_set(GITERR_REPOSITORY, "Path is not a repository: %s", bare_path);
+ return GIT_ENOTFOUND;
+ }
+
+ repo = repository_alloc();
+ GITERR_CHECK_ALLOC(repo);
+
+ repo->path_repository = git_buf_detach(&path);
+ GITERR_CHECK_ALLOC(repo->path_repository);
+
+ /* of course we're bare! */
+ repo->is_bare = 1;
+ repo->workdir = NULL;
+
+ *repo_ptr = repo;
+ return 0;
+}
+
int git_repository_open_ext(
git_repository **repo_ptr,
const char *start_path,