summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReginald McLean <rbmclean00@gmail.com>2020-11-24 18:45:55 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2023-05-16 12:31:46 +0100
commit86db1ad5dc9d878f463ac6c9d5ee412b62b74340 (patch)
tree13aff1d2fa70fdaa7ca5f344e4e8967b4b4275eb
parent0fd80681f90ae23d5a74b469fefd3409d924ddae (diff)
downloadlibgit2-86db1ad5dc9d878f463ac6c9d5ee412b62b74340.tar.gz
Added check if gitdir exists in is_prunable()
Fixes #5598
-rw-r--r--src/libgit2/worktree.c9
1 files changed, 9 insertions, 0 deletions
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;
}