Commit Diff


commit - 49aa539ae942aff06b21e3252bed3977e80398e3
commit + d0710d08dc4faf1066d94a92bf8ee0578a6d9073
blob - e82cc82d336ec34bdac10e31a51a1a32f0487a02
blob + 7a096570fcf9fc2d50fbd56c6a4a29ad6b170e54
--- lib/worktree.c
+++ lib/worktree.c
@@ -2276,14 +2276,23 @@ got_worktree_resolve_path(char **wt_path, struct got_w
     const char *arg)
 {
 	const struct got_error *err = NULL;
-	char *resolved, *path = NULL;
+	char *resolved, *cwd = NULL, *path = NULL;
 	size_t len;
 
 	*wt_path = NULL;
 
 	resolved = realpath(arg, NULL);
-	if (resolved == NULL)
-		return got_error_from_errno2("realpath", arg);
+	if (resolved == NULL) {
+		if (errno != ENOENT)
+			return got_error_from_errno2("realpath", arg);
+		cwd = getcwd(NULL, 0);
+		if (cwd == NULL)
+			return got_error_from_errno("getcwd");
+		if (asprintf(&resolved, "%s/%s", cwd, arg) == -1) {
+			err = got_error_from_errno("asprintf");
+			goto done;
+		}
+	}
 
 	if (strncmp(got_worktree_get_root_path(worktree), resolved,
 	    strlen(got_worktree_get_root_path(worktree)))) {
@@ -2312,6 +2321,7 @@ got_worktree_resolve_path(char **wt_path, struct got_w
 	}
 done:
 	free(resolved);
+	free(cwd);
 	if (err == NULL)
 		*wt_path = path;
 	else