Skip to content

Commit 942cfac

Browse files
committed
worktree: checkout options suggestions from code review
1 parent f9a98f9 commit 942cfac

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

include/git2/worktree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ typedef struct git_worktree_add_options {
9090
/**
9191
* Options for the checkout.
9292
*/
93-
git_checkout_options checkout_opts;
93+
git_checkout_options checkout_options;
9494
} git_worktree_add_options;
9595

9696
#define GIT_WORKTREE_ADD_OPTIONS_VERSION 1

src/worktree.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,25 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
304304
git_reference *ref = NULL, *head = NULL;
305305
git_commit *commit = NULL;
306306
git_repository *wt = NULL;
307-
git_checkout_options coopts = GIT_CHECKOUT_OPTIONS_INIT;
307+
git_checkout_options coopts;
308308
git_worktree_add_options wtopts = GIT_WORKTREE_ADD_OPTIONS_INIT;
309309
int err;
310310

311311
GIT_ERROR_CHECK_VERSION(
312312
opts, GIT_WORKTREE_ADD_OPTIONS_VERSION, "git_worktree_add_options");
313313

314-
if (opts)
315-
memcpy(&wtopts, opts, sizeof(wtopts));
316-
317314
GIT_ASSERT_ARG(out);
318315
GIT_ASSERT_ARG(repo);
319316
GIT_ASSERT_ARG(name);
320317
GIT_ASSERT_ARG(worktree);
321318

322319
*out = NULL;
323320

321+
if (opts)
322+
memcpy(&wtopts, opts, sizeof(wtopts));
323+
324+
memcpy(&coopts, &wtopts.checkout_options, sizeof(coopts));
325+
324326
if (wtopts.ref) {
325327
if (!git_reference_is_branch(wtopts.ref)) {
326328
git_error_set(GIT_ERROR_WORKTREE, "reference is not a branch");
@@ -405,8 +407,6 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
405407
goto out;
406408

407409
/* Checkout worktree's HEAD */
408-
if (opts != NULL)
409-
memcpy(&coopts, &wtopts.checkout_opts, sizeof(coopts));
410410
if ((err = git_checkout_head(wt, &coopts)) < 0)
411411
goto out;
412412

tests/worktree/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void test_worktree_worktree__add_no_checkout(void)
300300
git_str path = GIT_STR_INIT;
301301
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
302302

303-
opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_NONE;
303+
opts.checkout_options.checkout_strategy = GIT_CHECKOUT_NONE;
304304

305305
cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-no-checkout"));
306306
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-no-checkout", path.ptr, &opts));

0 commit comments

Comments
 (0)