From 2a3b3e0324b272c50c8d2d7767bd4d55c4d453f6 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sat, 12 Jan 2013 19:27:31 +0100 Subject: [PATCH] checkout: Teach checkout to cope with orphaned Head Fix #1236 --- src/checkout.c | 9 ++++++++- tests-clar/checkout/index.c | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/checkout.c b/src/checkout.c index b58ef9f44..d5a471d0c 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -1173,7 +1173,14 @@ static int checkout_data_init( if (!data->opts.baseline) { data->opts_free_baseline = true; - if ((error = checkout_lookup_head_tree(&data->opts.baseline, repo)) < 0) + error = checkout_lookup_head_tree(&data->opts.baseline, repo); + + if (error == GIT_EORPHANEDHEAD) { + error = 0; + giterr_clear(); + } + + if (error < 0) goto cleanup; } diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c index 2dc08715d..22c6217b9 100644 --- a/tests-clar/checkout/index.c +++ b/tests-clar/checkout/index.c @@ -498,3 +498,13 @@ void test_checkout_index__can_update_prefixed_files(void) cl_assert(!git_path_exists("testrepo/branch_file")); cl_assert(!git_path_exists("testrepo/branch_file.txt.after")); } + +void test_checkout_index__can_checkout_a_newly_initialized_repository(void) +{ + test_checkout_index__cleanup(); + + g_repo = cl_git_sandbox_init("empty_standard_repo"); + cl_git_remove_placeholders(git_repository_path(g_repo), "dummy-marker.txt"); + + cl_git_pass(git_checkout_index(g_repo, NULL, NULL)); +}