Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
f041a94e
Commit
f041a94e
authored
May 16, 2023
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'worktree_prunable' (PR #5712)
parents
9d41a3fd
12b54ae0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
11 deletions
+41
-11
include/git2/worktree.h
+3
-1
src/libgit2/worktree.c
+25
-10
tests/libgit2/worktree/worktree.c
+13
-0
No files found.
include/git2/worktree.h
View file @
f041a94e
...
...
@@ -237,7 +237,9 @@ GIT_EXTERN(int) git_worktree_prune_options_init(
*
* If the worktree is not valid and not locked or if the above
* flags have been passed in, this function will return a
* positive value.
* positive value. If the worktree is not prunable, an error
* message will be set (visible in `giterr_last`) with details about
* why.
*
* @param wt Worktree to check.
* @param opts The prunable options.
...
...
src/libgit2/worktree.c
View file @
f041a94e
...
...
@@ -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
,
...
...
tests/libgit2/worktree/worktree.c
View file @
f041a94e
...
...
@@ -645,3 +645,16 @@ void test_worktree_worktree__validate_invalid_worktreedir(void)
git_worktree_free
(
wt
);
}
void
test_worktree_worktree__is_prunable_missing_repo
(
void
)
{
git_worktree
*
wt
;
cl_git_pass
(
git_worktree_lookup
(
&
wt
,
fixture
.
repo
,
"testrepo-worktree"
));
p_rename
(
"testrepo"
,
"testrepo-tmp"
);
/* Should not be prunable since the repository moved */
cl_assert
(
!
git_worktree_is_prunable
(
wt
,
NULL
));
p_rename
(
"testrepo-tmp"
,
"testrepo"
);
git_worktree_free
(
wt
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment