8000 Merge pull request #6727 from libgit2/ethomson/should_checkout_error · russell/libgit2@f6d1cd7 · GitHub
[go: up one dir, main page]

Skip to content

Commit f6d1cd7

Browse files
authored
Merge pull request libgit2#6727 from libgit2/ethomson/should_checkout_error
clone: don't swallow error in should_checkout
2 parents 9b2577f + ca864c5 commit f6d1cd7

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/libgit2/clone.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,25 +362,29 @@ static int create_and_configure_origin(
362362
return error;
363363
}
364364

365-
static bool should_checkout(
365+
static int should_checkout(
366+
bool *out,
366367
git_repository *repo,
367368
bool is_bare,
368369
const git_checkout_options *opts)
369370
{
370-
if (is_bare)
371-
return false;
371+
int error;
372372

373-
if (!opts)
374-
return false;
373+
if (!opts || is_bare || opts->checkout_strategy == GIT_CHECKOUT_NONE) {
374+
*out = 0;
375+
return 0;
376+
}
375377

376-
if (opts->checkout_strategy == GIT_CHECKOUT_NONE)
377-
return false;
378+
if ((error = git_repository_head_unborn(repo)) < 0)
379+
return error;
378380

379-
return !git_repository_head_unborn(repo);
381+
*out = !error;
382+
return 0;
380383
}
381384

382385
static int checkout_branch(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, const char *reflog_message)
383386
{
387+
bool checkout;
384388
int error;
385389

386390
if (branch)
@@ -389,7 +393,13 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
389393
else
390394
error = update_head_to_remote(repo, remote, reflog_message);
391395

392-
if (!error && should_checkout(repo, git_repository_is_bare(repo), co_opts))
396+
if (error < 0)
397+
return error;
398+
399+
if ((error = should_checkout(&checkout, repo, git_repository_is_bare(repo), co_opts)) < 0)
400+
return error;
401+
402+
if (checkout)
393403
error = git_checkout_head(repo, co_opts);
394404

395405
return error;

0 commit comments

Comments
 (0)
0