diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-02-03 13:52:23 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-02-13 11:13:08 +0100 |
commit | 1ba242c9ab0eb323abed1b3bbc770aeb3367d855 (patch) | |
tree | 0ecaec9fe31f15bb81c9ffce27c5f80621b82745 /src/worktree.c | |
parent | 3f3a4ce7bcd9862ef1eb87dfc5871e4012159244 (diff) | |
download | libgit2-1ba242c9ab0eb323abed1b3bbc770aeb3367d855.tar.gz |
worktree: extract git_worktree_is_prunable
Diffstat (limited to 'src/worktree.c')
-rw-r--r-- | src/worktree.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/worktree.c b/src/worktree.c index a3fe07a23..5abc98945 100644 --- a/src/worktree.c +++ b/src/worktree.c @@ -357,11 +357,9 @@ out: return ret; } -int git_worktree_prune(git_worktree *wt, unsigned flags) +int git_worktree_is_prunable(git_worktree *wt, unsigned flags) { - git_buf reason = GIT_BUF_INIT, path = GIT_BUF_INIT; - char *wtpath; - int err; + git_buf reason = GIT_BUF_INIT; if ((flags & GIT_WORKTREE_PRUNE_LOCKED) == 0 && git_worktree_is_locked(&reason, wt)) @@ -369,15 +367,28 @@ int git_worktree_prune(git_worktree *wt, unsigned flags) if (!reason.size) git_buf_attach_notowned(&reason, "no reason given", 15); giterr_set(GITERR_WORKTREE, "Not pruning locked working tree: '%s'", reason.ptr); + git_buf_free(&reason); - err = -1; - goto out; + return 0; } if ((flags & GIT_WORKTREE_PRUNE_VALID) == 0 && git_worktree_validate(wt) == 0) { giterr_set(GITERR_WORKTREE, "Not pruning valid working tree"); + return 0; + } + + return 1; +} + +int git_worktree_prune(git_worktree *wt, unsigned flags) +{ + git_buf path = GIT_BUF_INIT; + char *wtpath; + int err; + + if (!git_worktree_is_prunable(wt, flags)) { err = -1; goto out; } @@ -415,7 +426,6 @@ int git_worktree_prune(git_worktree *wt, unsigned flags) goto out; out: - git_buf_free(&reason); git_buf_free(&path); return err; |