summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xt/t2028-worktree-move.sh8
-rw-r--r--worktree.c6
2 files changed, 13 insertions, 1 deletions
diff --git a/t/t2028-worktree-move.sh b/t/t2028-worktree-move.sh
index 5f7d45b7b7..60aba7c41a 100755
--- a/t/t2028-worktree-move.sh
+++ b/t/t2028-worktree-move.sh
@@ -141,4 +141,12 @@ test_expect_success 'NOT remove missing-but-locked worktree' '
test_path_is_dir .git/worktrees/gone-but-locked
'
+test_expect_success 'proper error when worktree not found' '
+ for i in noodle noodle/bork
+ do
+ test_must_fail git worktree lock $i 2>err &&
+ test_i18ngrep "not a working tree" err || return 1
+ done
+'
+
test_done
diff --git a/worktree.c b/worktree.c
index 97cda5f97b..b0d0b5426d 100644
--- a/worktree.c
+++ b/worktree.c
@@ -217,7 +217,11 @@ struct worktree *find_worktree(struct worktree **list,
if (prefix)
arg = to_free = prefix_filename(prefix, arg);
- path = real_pathdup(arg, 1);
+ path = real_pathdup(arg, 0);
+ if (!path) {
+ free(to_free);
+ return NULL;
+ }
for (; *list; list++)
if (!fspathcmp(path, real_path((*list)->path)))
break;