diff options
author | Russell Belfer <rb@github.com> | 2012-09-21 10:51:42 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-09-21 10:51:42 -0700 |
commit | 0cb24616eea3b92893b2a03e851a0db2c04862ef (patch) | |
tree | f62f1028b6611a78fd930319aca0045978e5fd1d /tests-clar/checkout/index.c | |
parent | 73f6da66afae81a806a1596afe55cab058e3df32 (diff) | |
parent | 9e592583fc5fcd7eec5d40d30e34870e6a029fef (diff) | |
download | libgit2-0cb24616eea3b92893b2a03e851a0db2c04862ef.tar.gz |
Merge pull request #942 from nulltoken/topic/checkout-notify-skipped
checkout: add notification callback for skipped files
Diffstat (limited to 'tests-clar/checkout/index.c')
-rw-r--r-- | tests-clar/checkout/index.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c index d1c59e38c..f017a0fe2 100644 --- a/tests-clar/checkout/index.c +++ b/tests-clar/checkout/index.c @@ -287,3 +287,76 @@ void test_checkout_index__options_open_flags(void) test_file_contents("./testrepo/new.txt", "hi\nmy new file\n"); } + +struct notify_data { + const char *file; + const char *sha; +}; + +static int notify_cb( + const char *skipped_file, + const git_oid *blob_oid, + int file_mode, + void *payload) +{ + struct notify_data *expectations = (struct notify_data *)payload; + + GIT_UNUSED(file_mode); + + cl_assert_equal_s(expectations->file, skipped_file); + cl_assert_equal_i(0, git_oid_streq(blob_oid, expectations->sha)); + + return 0; +} + +void test_checkout_index__can_notify_of_skipped_files(void) +{ + struct notify_data data; + + cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!"); + + /* + * $ git ls-tree HEAD + * 100644 blob a8233120f6ad708f843d861ce2b7228ec4e3dec6 README + * 100644 blob 3697d64be941a53d4ae8f6a271e4e3fa56b022cc branch_file.txt + * 100644 blob a71586c1dfe8a71c6cbf6c129f404c5642ff31bd new.txt + */ + data.file = "new.txt"; + data.sha = "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"; + + g_opts.checkout_strategy = GIT_CHECKOUT_CREATE_MISSING; + g_opts.skipped_notify_cb = notify_cb; + g_opts.notify_payload = &data; + + cl_git_pass(git_checkout_index(g_repo, &g_opts, NULL)); +} + +static int dont_notify_cb( + const char *skipped_file, + const git_oid *blob_oid, + int file_mode, + void *payload) +{ + GIT_UNUSED(skipped_file); + GIT_UNUSED(blob_oid); + GIT_UNUSED(file_mode); + GIT_UNUSED(payload); + + cl_assert(false); + + return 0; +} + +void test_checkout_index__wont_notify_of_expected_line_ending_changes(void) +{ + cl_git_pass(p_unlink("./testrepo/.gitattributes")); + set_core_autocrlf_to(true); + + cl_git_mkfile("./testrepo/new.txt", "my new file\r\n"); + + g_opts.checkout_strategy = GIT_CHECKOUT_CREATE_MISSING; + g_opts.skipped_notify_cb = dont_notify_cb; + g_opts.notify_payload = NULL; + + cl_git_pass(git_checkout_index(g_repo, &g_opts, NULL)); +} |