summaryrefslogtreecommitdiff
path: root/src/worktree.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/worktree.c')
-rw-r--r--src/worktree.c12
1 files changed, 6 insertions, 6 deletions
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;