Commit 942cfac1 by Edward Thomson

worktree: checkout options suggestions from code review

parent f9a98f94
...@@ -90,7 +90,7 @@ typedef struct git_worktree_add_options { ...@@ -90,7 +90,7 @@ typedef struct git_worktree_add_options {
/** /**
* Options for the checkout. * Options for the checkout.
*/ */
git_checkout_options checkout_opts; git_checkout_options checkout_options;
} git_worktree_add_options; } git_worktree_add_options;
#define GIT_WORKTREE_ADD_OPTIONS_VERSION 1 #define GIT_WORKTREE_ADD_OPTIONS_VERSION 1
......
...@@ -304,16 +304,13 @@ int git_worktree_add(git_worktree **out, git_repository *repo, ...@@ -304,16 +304,13 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
git_reference *ref = NULL, *head = NULL; git_reference *ref = NULL, *head = NULL;
git_commit *commit = NULL; git_commit *commit = NULL;
git_repository *wt = 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; git_worktree_add_options wtopts = GIT_WORKTREE_ADD_OPTIONS_INIT;
int err; int err;
GIT_ERROR_CHECK_VERSION( GIT_ERROR_CHECK_VERSION(
opts, GIT_WORKTREE_ADD_OPTIONS_VERSION, "git_worktree_add_options"); opts, GIT_WORKTREE_ADD_OPTIONS_VERSION, "git_worktree_add_options");
if (opts)
memcpy(&wtopts, opts, sizeof(wtopts));
GIT_ASSERT_ARG(out); GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(repo); GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(name); GIT_ASSERT_ARG(name);
...@@ -321,6 +318,11 @@ int git_worktree_add(git_worktree **out, git_repository *repo, ...@@ -321,6 +318,11 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
*out = NULL; *out = NULL;
if (opts)
memcpy(&wtopts, opts, sizeof(wtopts));
memcpy(&coopts, &wtopts.checkout_options, sizeof(coopts));
if (wtopts.ref) { if (wtopts.ref) {
if (!git_reference_is_branch(wtopts.ref)) { if (!git_reference_is_branch(wtopts.ref)) {
git_error_set(GIT_ERROR_WORKTREE, "reference is not a branch"); 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, ...@@ -405,8 +407,6 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
goto out; goto out;
/* Checkout worktree's HEAD */ /* Checkout worktree's HEAD */
if (opts != NULL)
memcpy(&coopts, &wtopts.checkout_opts, sizeof(coopts));
if ((err = git_checkout_head(wt, &coopts)) < 0) if ((err = git_checkout_head(wt, &coopts)) < 0)
goto out; goto out;
......
...@@ -300,7 +300,7 @@ void test_worktree_worktree__add_no_checkout(void) ...@@ -300,7 +300,7 @@ void test_worktree_worktree__add_no_checkout(void)
git_str path = GIT_STR_INIT; git_str path = GIT_STR_INIT;
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_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_str_joinpath(&path, fixture.repo->workdir, "../worktree-no-checkout"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-no-checkout", path.ptr, &opts)); cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-no-checkout", path.ptr, &opts));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment