diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2023-05-16 12:41:41 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2023-05-16 12:41:41 +0100 |
commit | f041a94e2c358e84adb5a0fe108288fcb3802970 (patch) | |
tree | b01428dbfdd3e41123aa8cbee3da857affd839e5 /src/libgit2 | |
parent | 9d41a3fd694d983ade53fb602a58f6df25ce0656 (diff) | |
parent | 12b54ae00948a7a8422af53a8e98a5aa4d51f1f7 (diff) | |
download | libgit2-main.tar.gz |
Diffstat (limited to 'src/libgit2')
-rw-r--r-- | src/libgit2/worktree.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/libgit2/worktree.c b/src/libgit2/worktree.c index 82e1d2d7e..a878634ca 100644 --- a/src/libgit2/worktree.c +++ b/src/libgit2/worktree.c @@ -565,6 +565,8 @@ int git_worktree_is_prunable(git_worktree *wt, git_worktree_prune_options *opts) { git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT; + git_str path = GIT_STR_INIT; + int ret = 0; GIT_ERROR_CHECK_VERSION( opts, GIT_WORKTREE_PRUNE_OPTIONS_VERSION, @@ -575,27 +577,40 @@ int git_worktree_is_prunable(git_worktree *wt, if ((popts.flags & GIT_WORKTREE_PRUNE_LOCKED) == 0) { git_str reason = GIT_STR_INIT; - int error; - if ((error = git_worktree__is_locked(&reason, wt)) < 0) - return error; + if ((ret = git_worktree__is_locked(&reason, wt)) < 0) + goto out; + + if (ret) { + git_error_set(GIT_ERROR_WORKTREE, + "not pruning locked working tree: '%s'", + reason.size ? reason.ptr : "is locked"); - if (error) { - if (!reason.size) - git_str_attach_notowned(&reason, "no reason given", 15); - git_error_set(GIT_ERROR_WORKTREE, "not pruning locked working tree: '%s'", reason.ptr); git_str_dispose(&reason); - return 0; + ret = 0; + goto out; } } if ((popts.flags & GIT_WORKTREE_PRUNE_VALID) == 0 && git_worktree_validate(wt) == 0) { git_error_set(GIT_ERROR_WORKTREE, "not pruning valid working tree"); - return 0; + goto out; } - return 1; + if ((ret = git_str_printf(&path, "%s/worktrees/%s", wt->commondir_path, wt->name) < 0)) + goto out; + + if (!git_fs_path_exists(path.ptr)) { + git_error_set(GIT_ERROR_WORKTREE, "worktree gitdir ('%s') does not exist", path.ptr); + goto out; + } + + ret = 1; + +out: + git_str_dispose(&path); + return ret; } int git_worktree_prune(git_worktree *wt, |