@@ -269,15 +269,32 @@ int git_worktree_validate(const git_worktree *wt)
269269 return err ;
270270}
271271
272- int git_worktree_add (git_worktree * * out , git_repository * repo , const char * name , const char * worktree )
272+ int git_worktree_add_init_options (git_worktree_add_options * opts ,
273+ unsigned int version )
274+ {
275+ GIT_INIT_STRUCTURE_FROM_TEMPLATE (opts , version ,
276+ git_worktree_add_options , GIT_WORKTREE_ADD_OPTIONS_INIT );
277+ return 0 ;
278+ }
279+
280+ int git_worktree_add (git_worktree * * out , git_repository * repo ,
281+ const char * name , const char * worktree ,
282+ const git_worktree_add_options * opts )
273283{
274284 git_buf gitdir = GIT_BUF_INIT , wddir = GIT_BUF_INIT , buf = GIT_BUF_INIT ;
275285 git_reference * ref = NULL , * head = NULL ;
276286 git_commit * commit = NULL ;
277287 git_repository * wt = NULL ;
278288 git_checkout_options coopts = GIT_CHECKOUT_OPTIONS_INIT ;
289+ git_worktree_add_options wtopts = GIT_WORKTREE_ADD_OPTIONS_INIT ;
279290 int err ;
280291
292+ GITERR_CHECK_VERSION (
293+ opts , GIT_WORKTREE_ADD_OPTIONS_VERSION , "git_worktree_add_options" );
294+
295+ if (opts )
296+ memcpy (& wtopts , opts , sizeof (wtopts ));
297+
281298 assert (out && repo && name && worktree );
282299
283300 * out = NULL ;
@@ -301,6 +318,21 @@ int git_worktree_add(git_worktree **out, git_repository *repo, const char *name,
301318 if ((err = git_path_prettify_dir (& wddir , worktree , NULL )) < 0 )
302319 goto out ;
303320
321+ if (wtopts .lock ) {
322+ int fd ;
323+
324+ if ((err = git_buf_joinpath (& buf , gitdir .ptr , "locked" )) < 0 )
325+ goto out ;
326+
327+ if ((fd = p_creat (buf .ptr , 0644 )) < 0 ) {
328+ err = fd ;
329+ goto out ;
330+ }
331+
332+ p_close (fd );
333+ git_buf_clear (& buf );
334+ }
335+
304336 /* Create worktree .git file */
305337 if ((err = git_buf_printf (& buf , "gitdir: %s\n" , gitdir .ptr )) < 0 )
306338 goto out ;
@@ -424,11 +456,29 @@ int git_worktree_is_locked(git_buf *reason, const git_worktree *wt)
424456 return ret ;
425457}
426458
427- int git_worktree_is_prunable (git_worktree * wt , unsigned flags )
459+ int git_worktree_prune_init_options (
460+ git_worktree_prune_options * opts ,
461+ unsigned int version )
462+ {
463+ GIT_INIT_STRUCTURE_FROM_TEMPLATE (opts , version ,
464+ git_worktree_prune_options , GIT_WORKTREE_PRUNE_OPTIONS_INIT );
465+ return 0 ;
466+ }
467+
468+ int git_worktree_is_prunable (git_worktree * wt ,
469+ git_worktree_prune_options * opts )
428470{
429471 git_buf reason = GIT_BUF_INIT ;
472+ git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT ;
473+
474+ GITERR_CHECK_VERSION (
475+ opts , GIT_WORKTREE_PRUNE_OPTIONS_VERSION ,
476+ "git_worktree_prune_options" );
477+
478+ if (opts )
479+ memcpy (& popts , opts , sizeof (popts ));
430480
431- if ((flags & GIT_WORKTREE_PRUNE_LOCKED ) == 0 &&
481+ if ((popts . flags & GIT_WORKTREE_PRUNE_LOCKED ) == 0 &&
432482 git_worktree_is_locked (& reason , wt ))
433483 {
434484 if (!reason .size )
@@ -439,7 +489,7 @@ int git_worktree_is_prunable(git_worktree *wt, unsigned flags)
439489 return 0 ;
440490 }
441491
442- if ((flags & GIT_WORKTREE_PRUNE_VALID ) == 0 &&
492+ if ((popts . flags & GIT_WORKTREE_PRUNE_VALID ) == 0 &&
443493 git_worktree_validate (wt ) == 0 )
444494 {
445495 giterr_set (GITERR_WORKTREE , "Not pruning valid working tree" );
@@ -449,13 +499,22 @@ int git_worktree_is_prunable(git_worktree *wt, unsigned flags)
449499 return 1 ;
450500}
451501
452- int git_worktree_prune (git_worktree * wt , unsigned flags )
502+ int git_worktree_prune (git_worktree * wt ,
503+ git_worktree_prune_options * opts )
453504{
505+ git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT ;
454506 git_buf path = GIT_BUF_INIT ;
455507 char * wtpath ;
456508 int err ;
457509
458- if (!git_worktree_is_prunable (wt , flags )) {
510+ GITERR_CHECK_VERSION (
511+ opts , GIT_WORKTREE_PRUNE_OPTIONS_VERSION ,
512+ "git_worktree_prune_options" );
513+
514+ if (opts )
515+ memcpy (& popts , opts , sizeof (popts ));
516+
517+ if (!git_worktree_is_prunable (wt , & popts )) {
459518 err = -1 ;
460519 goto out ;
461520 }
@@ -474,7 +533,7 @@ int git_worktree_prune(git_worktree *wt, unsigned flags)
474533
475534 /* Skip deletion of the actual working tree if it does
476535 * not exist or deletion was not requested */
477- if ((flags & GIT_WORKTREE_PRUNE_WORKING_TREE ) == 0 ||
536+ if ((popts . flags & GIT_WORKTREE_PRUNE_WORKING_TREE ) == 0 ||
478537 !git_path_exists (wt -> gitlink_path ))
479538 {
480539 goto out ;
0 commit comments