Commit Diff


commit - f609be2e6595d866c110e5c9f895db17f761e612
commit + e5dc71984941ad561bd7f953c0cbb88bc5aad0b0
blob - 00586f45a6454992ba9f574c4bd6e54132bcda79
blob + 6c95c1658ef7d66ad92828e36f72187ce1e36de9
--- got/got.c
+++ got/got.c
@@ -206,7 +206,7 @@ cmd_checkout(int argc, char *argv[])
 	char *repo_path = NULL;
 	char *worktree_path = NULL;
 	const char *path_prefix = "";
-	int ch;
+	int ch, same_path_prefix;
 
 	while ((ch = getopt(argc, argv, "p:")) != -1) {
 		switch (ch) {
@@ -283,7 +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_worktree_match_path_prefix(&same_path_prefix, worktree,
+	    path_prefix);
+	if (error != NULL)
+		goto done;
+	if (!same_path_prefix) {
 		error = got_error(GOT_ERR_PATH_PREFIX);
 		goto done;
 	}
blob - 7ffb70af030caa6fdcf0a595f91fe0486870a2c4
blob + 49f1b19f634b166145be20e9b7d2feaca633cfed
--- include/got_worktree.h
+++ include/got_worktree.h
@@ -51,6 +51,12 @@ const char *got_worktree_get_repo_path(struct got_work
 const char *got_worktree_get_path_prefix(struct got_worktree *);
 
 /*
+ * Check if a user-provided path prefix matches that of the worktree.
+ */
+const struct got_error *got_worktree_match_path_prefix(int *,
+    struct got_worktree *, const char *);
+
+/*
  * Get the name of a work tree's HEAD reference.
  * The caller must dispose of it with free(3).
  */
blob - 461f6ecb0fe1bbb0f4a8a46480962c27c01b456e
blob + 174d53dbfa4f1c9b5afae594ea6901007891a69e
--- lib/worktree.c
+++ lib/worktree.c
@@ -380,6 +380,22 @@ const char *
 got_worktree_get_path_prefix(struct got_worktree *worktree)
 {
 	return worktree->path_prefix;
+}
+
+const struct got_error *
+got_worktree_match_path_prefix(int *match, struct got_worktree *worktree,
+    const char *path_prefix)
+{
+	char *absprefix = NULL;
+
+	if (!got_path_is_absolute(path_prefix)) {
+		if (asprintf(&absprefix, "/%s", path_prefix) == -1)
+			return got_error_from_errno();
+	}
+	*match = (strcmp(absprefix ? absprefix : path_prefix,
+	    worktree->path_prefix) == 0);
+	free(absprefix);
+	return NULL;
 }
 
 char *