From 86db1ad5dc9d878f463ac6c9d5ee412b62b74340 Mon Sep 17 00:00:00 2001 From: Reginald McLean Date: Tue, 24 Nov 2020 18:45:55 -0500 Subject: Added check if gitdir exists in is_prunable() Fixes #5598 --- src/libgit2/worktree.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libgit2/worktree.c b/src/libgit2/worktree.c index 82e1d2d7e..a8460380f 100644 --- a/src/libgit2/worktree.c +++ b/src/libgit2/worktree.c @@ -565,6 +565,7 @@ int git_worktree_is_prunable(git_worktree *wt, git_worktree_prune_options *opts) { git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT; + git_buf path = GIT_BUF_INIT; GIT_ERROR_CHECK_VERSION( opts, GIT_WORKTREE_PRUNE_OPTIONS_VERSION, @@ -595,6 +596,14 @@ int git_worktree_is_prunable(git_worktree *wt, return 0; } + if (git_buf_printf(&path, "%s/worktrees/%s", wt->commondir_path, wt->name) < 0) + return 0; + if (!git_path_exists(path.ptr)) + { + git_error_set(GIT_ERROR_WORKTREE, "worktree gitdir '%s' does not exist", path.ptr); + return 0; + } + return 1; } -- cgit v1.2.1