diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2015-01-14 18:47:00 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@microsoft.com> | 2015-01-20 17:13:31 -0600 |
| commit | e74340b0001247681bf0fe43f73622e87b52ccae (patch) | |
| tree | 1e00d71efa79ac71a43851314475e27ac33c737b /tests/checkout | |
| parent | c2dee0fcb0d247ecb3a48709ae1c57d1b935d2ae (diff) | |
| download | libgit2-e74340b0001247681bf0fe43f73622e87b52ccae.tar.gz | |
checkout: remove files before writing new ones
On case insensitive filesystems, we may have files in the working
directory that case fold to a name we want to write. Remove those
files (by default) so that we will not end up with a filename that
has the unexpected case.
Diffstat (limited to 'tests/checkout')
| -rw-r--r-- | tests/checkout/icase.c | 97 | ||||
| -rw-r--r-- | tests/checkout/index.c | 4 |
2 files changed, 99 insertions, 2 deletions
diff --git a/tests/checkout/icase.c b/tests/checkout/icase.c new file mode 100644 index 000000000..625f19627 --- /dev/null +++ b/tests/checkout/icase.c @@ -0,0 +1,97 @@ +#include "clar_libgit2.h" + +#include "git2/checkout.h" +#include "path.h" + +static git_repository *repo; +static git_object *obj; +static git_checkout_options checkout_opts; + +void test_checkout_icase__initialize(void) +{ + git_oid id; + + repo = cl_git_sandbox_init("testrepo"); + + cl_git_pass(git_reference_name_to_id(&id, repo, "refs/heads/dir")); + cl_git_pass(git_object_lookup(&obj, repo, &id, GIT_OBJ_ANY)); + + git_checkout_init_options(&checkout_opts, GIT_CHECKOUT_OPTIONS_VERSION); + checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE; +} + +void test_checkout_icase__cleanup(void) +{ + git_object_free(obj); + cl_git_sandbox_cleanup(); +} + +static void assert_name_is(const char *expected) +{ + char *actual; + size_t actual_len, expected_len, start; + + cl_assert(actual = realpath(expected, NULL)); + + expected_len = strlen(expected); + actual_len = strlen(actual); + cl_assert(actual_len >= expected_len); + + start = actual_len - expected_len; + cl_assert_equal_s(expected, actual + start); + + if (start) + cl_assert_equal_strn("/", actual + (start - 1), 1); + + free(actual); +} + +void test_checkout_icase__overwrites_files_for_files(void) +{ + cl_git_write2file("testrepo/NEW.txt", "neue file\n", 10, \ + O_WRONLY | O_CREAT | O_TRUNC, 0644); + + cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts)); + assert_name_is("testrepo/new.txt"); +} + +void test_checkout_icase__overwrites_links_for_files(void) +{ + cl_must_pass(p_symlink("../tmp", "testrepo/NEW.txt")); + + cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts)); + + cl_assert(!git_path_exists("tmp")); + assert_name_is("testrepo/new.txt"); +} + +void test_checkout_icase__overwites_folders_for_files(void) +{ + cl_must_pass(p_mkdir("testrepo/NEW.txt", 0777)); + + cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts)); + + assert_name_is("testrepo/new.txt"); + cl_assert(!git_path_isdir("testrepo/new.txt")); +} + +void test_checkout_icase__overwrites_files_for_folders(void) +{ + cl_git_write2file("testrepo/A", "neue file\n", 10, \ + O_WRONLY | O_CREAT | O_TRUNC, 0644); + + cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts)); + assert_name_is("testrepo/a"); + cl_assert(git_path_isdir("testrepo/a")); +} + +void test_checkout_icase__overwrites_links_for_folders(void) +{ + cl_must_pass(p_symlink("..", "testrepo/A")); + + cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts)); + + cl_assert(!git_path_exists("b.txt")); + assert_name_is("testrepo/a"); +} + diff --git a/tests/checkout/index.c b/tests/checkout/index.c index f94556214..112324a04 100644 --- a/tests/checkout/index.c +++ b/tests/checkout/index.c @@ -279,10 +279,10 @@ void test_checkout_index__options_open_flags(void) cl_git_mkfile("./testrepo/new.txt", "hi\n"); - opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; + opts.checkout_strategy = + GIT_CHECKOUT_FORCE | GIT_CHECKOUT_DONT_REMOVE_EXISTING; opts.file_open_flags = O_CREAT | O_RDWR | O_APPEND; - opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); check_file_contents("./testrepo/new.txt", "hi\nmy new file\n"); |
