diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2015-02-14 18:33:06 +0300 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2015-02-27 21:50:32 +0300 |
commit | e6da3e4496188b36dbc83950f5e771a373c8ebcc (patch) | |
tree | c966272518558cb2fd101e01b00f264e554997ec /tests/checkout | |
parent | 5cbe950fb8b18e930f79c81bdab0aebf21443596 (diff) |
checkout: upgrade to `SAFE_CREATE` when no index file
When the repository does not contain an index, emulate git's behavior
and upgrade to `SAFE_CREATE`. This allows us to check out repositories
created with `git clone --no-checkout`.
Diffstat (limited to 'tests/checkout')
-rw-r--r-- | tests/checkout/tree.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c index 0fabadc8d..1b4a33273 100644 --- a/tests/checkout/tree.c +++ b/tests/checkout/tree.c @@ -1264,3 +1264,39 @@ void test_checkout_tree__can_update_but_not_write_index(void) git_object_free(head); git_index_free(index); } + +/* Emulate checking out in a repo created by clone --no-checkout, + * which would not have written an index. */ +void test_checkout_tree__safe_proceeds_if_no_index(void) +{ + git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; + git_oid oid; + git_object *obj = NULL; + + assert_on_branch(g_repo, "master"); + cl_must_pass(p_unlink("testrepo/.git/index")); + + /* do second checkout safe because we should be clean after first */ + opts.checkout_strategy = GIT_CHECKOUT_SAFE; + + cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/subtrees")); + cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); + + cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); + cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees", NULL, NULL)); + + cl_assert(git_path_isfile("testrepo/README")); + cl_assert(git_path_isfile("testrepo/branch_file.txt")); + cl_assert(git_path_isfile("testrepo/new.txt")); + cl_assert(git_path_isfile("testrepo/ab/4.txt")); + cl_assert(git_path_isfile("testrepo/ab/c/3.txt")); + cl_assert(git_path_isfile("testrepo/ab/de/2.txt")); + cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt")); + + cl_assert(!git_path_isdir("testrepo/a")); + + assert_on_branch(g_repo, "subtrees"); + + git_object_free(obj); +} + |