try to infer repository path from work tree
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
diff --git a/got/got.c b/got/got.c
index 3666d5b..c710058 100644
--- a/got/got.c
+++ b/got/got.c
@@ -449,7 +449,7 @@ cmd_log(int argc, char *argv[])
const char *errstr;
#ifndef PROFILE
- if (pledge("stdio rpath wpath cpath proc", NULL) == -1)
+ if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
err(1, "pledge");
#endif
@@ -623,7 +623,7 @@ cmd_diff(int argc, char *argv[])
int ch;
#ifndef PROFILE
- if (pledge("stdio rpath wpath cpath proc", NULL) == -1)
+ if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
err(1, "pledge");
#endif
diff --git a/lib/repository.c b/lib/repository.c
index 611e952..fa438db 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -27,6 +27,7 @@
#include "got_error.h"
#include "got_reference.h"
#include "got_repository.h"
+#include "got_worktree.h"
#include "got_lib_path.h"
#include "got_lib_delta.h"
@@ -34,6 +35,7 @@
#include "got_lib_object.h"
#include "got_lib_pack.h"
#include "got_lib_repository.h"
+#include "got_lib_worktree.h"
#ifndef nitems
#define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
@@ -184,6 +186,28 @@ got_repo_open(struct got_repository **ret, const char *path)
goto done;
}
if (!is_git_repo(repo)) {
+ struct got_worktree *worktree;
+ if (got_worktree_open(&worktree, repo->path) == NULL) {
+ free(repo->path_git_dir);
+ repo->path_git_dir =
+ strdup(worktree->repo_path);
+ if (repo->path_git_dir == NULL) {
+ err = got_error_from_errno();
+ goto done;
+ }
+ if (!is_git_repo(repo)) {
+ free(repo->path_git_dir);
+ if (asprintf(&repo->path_git_dir,
+ "%s/%s", worktree->repo_path,
+ GOT_GIT_DIR) == -1) {
+ err = got_error_from_errno();
+ goto done;
+ }
+ }
+ got_worktree_close(worktree);
+ }
+ }
+ if (!is_git_repo(repo)) {
err = got_error(GOT_ERR_NOT_GIT_REPO);
goto done;
}
diff --git a/regress/repository/Makefile b/regress/repository/Makefile
index 0058276..605897b 100644
--- a/regress/repository/Makefile
+++ b/regress/repository/Makefile
@@ -2,7 +2,8 @@
PROG = repository_test
SRCS = path.c repository.c error.c reference.c object.c sha1.c diff.c \
- diffreg.c pack.c privsep.c delta.c zbuf.c repository_test.c
+ diffreg.c pack.c privsep.c delta.c fileindex.c worktree.c \
+ zbuf.c repository_test.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
LDADD = -lutil -lz