Skip to content

Commit ffead01

Browse files
punkymaniacethomson
authored andcommitted
Allow user checkout options on git_worktree_add
Extend the `git_worktree_add_options` to include `git_checkout_options`. github issue libgit2#5949
1 parent a50bbba commit ffead01

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

include/git2/worktree.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ typedef struct git_worktree_add_options {
8686

8787
int lock; /**< lock newly created worktree */
8888
git_reference *ref; /**< reference to use for the new worktree HEAD */
89+
90+
/**
91+
* Options for the checkout.
92+
*/
93+
git_checkout_options checkout_opts;
8994
} git_worktree_add_options;
9095

9196
#define GIT_WORKTREE_ADD_OPTIONS_VERSION 1
92-
#define GIT_WORKTREE_ADD_OPTIONS_INIT {GIT_WORKTREE_ADD_OPTIONS_VERSION,0,NULL}
97+
#define GIT_WORKTREE_ADD_OPTIONS_INIT {GIT_WORKTREE_ADD_OPTIONS_VERSION,0,NULL,GIT_CHECKOUT_OPTIONS_INIT}
9398

9499
/**
95100
* Initialize git_worktree_add_options structure

src/worktree.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,10 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
405405
goto out;
406406

407407
/* Checkout worktree's HEAD */
408-
coopts.checkout_strategy = GIT_CHECKOUT_FORCE;
408+
if (opts != NULL)
409+
memcpy(&coopts, &wtopts.checkout_opts, sizeof(coopts));
410+
else
411+
coopts.checkout_strategy = GIT_CHECKOUT_FORCE;
409412
if ((err = git_checkout_head(wt, &coopts)) < 0)
410413
goto out;
411414

0 commit comments

Comments
 (0)