summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-12-23 14:21:23 -0600
committerEdward Thomson <ethomson@edwardthomson.com>2021-12-23 14:21:49 -0600
commit942cfac129b2cffc2668a7d1d7b7b613e4eef19f (patch)
treeb8d4e87ad7c8dadf16be6cd8b9be08bfa176fb5f
parentf9a98f9442c0b1c22f8212753fda85603fa948e8 (diff)
downloadlibgit2-942cfac129b2cffc2668a7d1d7b7b613e4eef19f.tar.gz
worktree: checkout options suggestions from code review
-rw-r--r--include/git2/worktree.h2
-rw-r--r--src/worktree.c12
-rw-r--r--tests/worktree/worktree.c2
3 files changed, 8 insertions, 8 deletions
diff --git a/include/git2/worktree.h b/include/git2/worktree.h
index ee6b04b0c..8691f96db 100644
--- a/include/git2/worktree.h
+++ b/include/git2/worktree.h
@@ -90,7 +90,7 @@ typedef struct git_worktree_add_options {
/**
* Options for the checkout.
*/
- git_checkout_options checkout_opts;
+ git_checkout_options checkout_options;
} git_worktree_add_options;
#define GIT_WORKTREE_ADD_OPTIONS_VERSION 1
diff --git a/src/worktree.c b/src/worktree.c
index 6bf604227..2ac2274f1 100644
--- a/src/worktree.c
+++ b/src/worktree.c
@@ -304,16 +304,13 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
git_reference *ref = NULL, *head = NULL;
git_commit *commit = NULL;
git_repository *wt = NULL;
- git_checkout_options coopts = GIT_CHECKOUT_OPTIONS_INIT;
+ git_checkout_options coopts;
git_worktree_add_options wtopts = GIT_WORKTREE_ADD_OPTIONS_INIT;
int err;
GIT_ERROR_CHECK_VERSION(
opts, GIT_WORKTREE_ADD_OPTIONS_VERSION, "git_worktree_add_options");
- if (opts)
- memcpy(&wtopts, opts, sizeof(wtopts));
-
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(name);
@@ -321,6 +318,11 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
*out = NULL;
+ if (opts)
+ memcpy(&wtopts, opts, sizeof(wtopts));
+
+ memcpy(&coopts, &wtopts.checkout_options, sizeof(coopts));
+
if (wtopts.ref) {
if (!git_reference_is_branch(wtopts.ref)) {
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,
goto out;
/* Checkout worktree's HEAD */
- if (opts != NULL)
- memcpy(&coopts, &wtopts.checkout_opts, sizeof(coopts));
if ((err = git_checkout_head(wt, &coopts)) < 0)
goto out;
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index ccb6cde25..66273d1cb 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -300,7 +300,7 @@ void test_worktree_worktree__add_no_checkout(void)
git_str path = GIT_STR_INIT;
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
- opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_NONE;
+ opts.checkout_options.checkout_strategy = GIT_CHECKOUT_NONE;
cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-no-checkout"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-no-checkout", path.ptr, &opts));