verify path prefix when checking out into existing 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
diff --git a/got/got.c b/got/got.c
index 238a09f..00586f4 100644
--- a/got/got.c
+++ b/got/got.c
@@ -283,6 +283,11 @@ cmd_checkout(int argc, char *argv[])
if (error != NULL)
goto done;
+ if (strcmp(path_prefix, got_worktree_get_path_prefix(worktree)) != 0) {
+ error = got_error(GOT_ERR_PATH_PREFIX);
+ goto done;
+ }
+
error = got_worktree_checkout_files(worktree, repo,
checkout_progress, worktree_path, checkout_cancel, NULL);
if (error != NULL)
diff --git a/include/got_error.h b/include/got_error.h
index e7d37e6..7720ed2 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -67,6 +67,7 @@
#define GOT_ERR_FILEIDX_SIG 51
#define GOT_ERR_FILEIDX_VER 52
#define GOT_ERR_FILEIDX_CSUM 53
+#define GOT_ERR_PATH_PREFIX 54
static const struct got_error {
int code;
@@ -122,6 +123,8 @@ static const struct got_error {
{ GOT_ERR_FILEIDX_SIG, "bad file index signature" },
{ GOT_ERR_FILEIDX_VER, "unknown file index format version" },
{ GOT_ERR_FILEIDX_CSUM, "bad file index checksum" },
+ { GOT_ERR_PATH_PREFIX, "worktree already contains items from a "
+ "different path prefix" },
};
/*
diff --git a/include/got_worktree.h b/include/got_worktree.h
index aa7c545..80de9bd 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -47,6 +47,12 @@ void got_worktree_close(struct got_worktree *);
char *got_worktree_get_repo_path(struct got_worktree *);
/*
+ * Get the path prefix associated with a worktree.
+ * The caller must dispose of it with free(3).
+ */
+const char *got_worktree_get_path_prefix(struct got_worktree *);
+
+/*
* Get the name of a work tree's HEAD reference.
* The caller must dispose of it with free(3).
*/
diff --git a/lib/worktree.c b/lib/worktree.c
index 1a57978..c55f3e7 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -376,6 +376,12 @@ got_worktree_get_repo_path(struct got_worktree *worktree)
return strdup(worktree->repo_path);
}
+const char *
+got_worktree_get_path_prefix(struct got_worktree *worktree)
+{
+ return worktree->repo_path;
+}
+
char *
got_worktree_get_head_ref_name(struct got_worktree *worktree)
{