Commit 0c48fee25cfbd876833d857ed3810028847225b0

Stefan Sperling 2019-03-11T18:15:28

refuse to create got worktree at a git repo path

diff --git a/include/got_error.h b/include/got_error.h
index 65ff442..67326be 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -79,6 +79,7 @@
 #define GOT_ERR_UUID		63
 #define GOT_ERR_LOCKFILE_TIMEOUT 64
 #define GOT_ERR_BAD_REF_NAME	65
+#define GOT_ERR_WORKTREE_REPO	66
 
 static const struct got_error {
 	int code;
@@ -148,6 +149,7 @@ static const struct got_error {
 	{ GOT_ERR_UUID,		"uuid error" },
 	{ GOT_ERR_LOCKFILE_TIMEOUT,"lockfile timeout" },
 	{ GOT_ERR_BAD_REF_NAME,	"bad reference name" },
+	{ GOT_ERR_WORKTREE_REPO,"cannot create worktree inside a git repository" },
 };
 
 /*
diff --git a/lib/worktree.c b/lib/worktree.c
index b42d708..352980f 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -207,6 +207,11 @@ got_worktree_init(const char *path, struct got_reference *head_ref,
 	char *basestr = NULL;
 	char *uuidstr = NULL;
 
+	if (strcmp(path, got_repo_get_path(repo)) == 0) {
+		err = got_error(GOT_ERR_WORKTREE_REPO);
+		goto done;
+	}
+
 	err = got_ref_resolve(&commit_id, repo, head_ref);
 	if (err)
 		return err;