diff options
author | Vicent Marti <vicent@github.com> | 2013-12-13 07:29:27 -0800 |
---|---|---|
committer | Vicent Marti <vicent@github.com> | 2013-12-13 07:29:27 -0800 |
commit | a7ecd1a9e36df5d6843c1863542c02d777e9e8b5 (patch) | |
tree | 3bc5eeaa251d61fc6966d95e286dfacb1dd5b652 /tests | |
parent | 79194bcdc956406979cd27ac99198826860d3f20 (diff) | |
parent | bf4a577c6989f67fc7821eebd61a117726afc9d5 (diff) | |
download | libgit2-a7ecd1a9e36df5d6843c1863542c02d777e9e8b5.tar.gz |
Merge pull request #2000 from ethomson/overwrite_ignored
Overwrite ignored files on checkout
Diffstat (limited to 'tests')
-rw-r--r-- | tests/checkout/tree.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c index d2e92f8e8..06aa6a594 100644 --- a/tests/checkout/tree.c +++ b/tests/checkout/tree.c @@ -235,6 +235,113 @@ void test_checkout_tree__can_remove_ignored(void) cl_assert(!git_path_isfile("testrepo/ignored_file")); } +static int checkout_tree_with_blob_ignored_in_workdir(int strategy, bool isdir) +{ + git_oid oid; + git_object *obj = NULL; + git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; + int ignored = 0, error; + + assert_on_branch(g_repo, "master"); + + /* do first checkout with FORCE because we don't know if testrepo + * base data is clean for a checkout or not + */ + opts.checkout_strategy = GIT_CHECKOUT_FORCE; + + cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir")); + 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/dir")); + + 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/a/b.txt")); + + cl_assert(!git_path_isdir("testrepo/ab")); + + assert_on_branch(g_repo, "dir"); + + git_object_free(obj); + + opts.checkout_strategy = strategy; + + if (isdir) { + cl_must_pass(p_mkdir("testrepo/ab", 0777)); + cl_must_pass(p_mkdir("testrepo/ab/4.txt", 0777)); + + cl_git_mkfile("testrepo/ab/4.txt/file1.txt", "as you wish"); + cl_git_mkfile("testrepo/ab/4.txt/file2.txt", "foo bar foo"); + cl_git_mkfile("testrepo/ab/4.txt/file3.txt", "inky blinky pinky clyde"); + + cl_assert(git_path_isdir("testrepo/ab/4.txt")); + } else { + cl_must_pass(p_mkdir("testrepo/ab", 0777)); + cl_git_mkfile("testrepo/ab/4.txt", "as you wish"); + + cl_assert(git_path_isfile("testrepo/ab/4.txt")); + } + + cl_git_pass(git_ignore_add_rule(g_repo, "ab/4.txt\n")); + + cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "ab/4.txt")); + cl_assert_equal_i(1, ignored); + + 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)); + + error = git_checkout_tree(g_repo, obj, &opts); + + git_object_free(obj); + + return error; +} + +void test_checkout_tree__conflict_on_ignored_when_not_overwriting(void) +{ + int error; + + cl_git_fail(error = checkout_tree_with_blob_ignored_in_workdir( + GIT_CHECKOUT_SAFE | GIT_CHECKOUT_DONT_OVERWRITE_IGNORED, false)); + + cl_assert_equal_i(GIT_EMERGECONFLICT, error); +} + +void test_checkout_tree__can_overwrite_ignored_by_default(void) +{ + cl_git_pass(checkout_tree_with_blob_ignored_in_workdir(GIT_CHECKOUT_SAFE, false)); + + cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); + + cl_assert(git_path_isfile("testrepo/ab/4.txt")); + + assert_on_branch(g_repo, "subtrees"); +} + +void test_checkout_tree__conflict_on_ignored_folder_when_not_overwriting(void) +{ + int error; + + cl_git_fail(error = checkout_tree_with_blob_ignored_in_workdir( + GIT_CHECKOUT_SAFE | GIT_CHECKOUT_DONT_OVERWRITE_IGNORED, true)); + + cl_assert_equal_i(GIT_EMERGECONFLICT, error); +} + +void test_checkout_tree__can_overwrite_ignored_folder_by_default(void) +{ + cl_git_pass(checkout_tree_with_blob_ignored_in_workdir(GIT_CHECKOUT_SAFE, true)); + + cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); + + cl_assert(git_path_isfile("testrepo/ab/4.txt")); + + assert_on_branch(g_repo, "subtrees"); + +} + void test_checkout_tree__can_update_only(void) { git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; |