diff options
| author | Vicent Martí <vicent@github.com> | 2012-08-19 01:26:06 -0700 |
|---|---|---|
| committer | Vicent Martí <vicent@github.com> | 2012-08-19 01:26:06 -0700 |
| commit | f98c32f3fea0d5532db2d5733418aa62648b9e93 (patch) | |
| tree | 5b53901f1848d73a72765ec014e2ad5188316eb4 /tests-clar | |
| parent | 1a10fded40875f986164b80c6efd414cd1507cb8 (diff) | |
| parent | eb87800ab631d19a7655f01ece130455b1cc976a (diff) | |
| download | libgit2-f98c32f3fea0d5532db2d5733418aa62648b9e93.tar.gz | |
Merge pull request #778 from ben/clone
Clone
Diffstat (limited to 'tests-clar')
20 files changed, 333 insertions, 6 deletions
diff --git a/tests-clar/checkout/checkout.c b/tests-clar/checkout/checkout.c new file mode 100644 index 000000000..80e30bbc3 --- /dev/null +++ b/tests-clar/checkout/checkout.c @@ -0,0 +1,186 @@ +#include "clar_libgit2.h" + +#include "git2/checkout.h" +#include "repository.h" + + +static git_repository *g_repo; + +void test_checkout_checkout__initialize(void) +{ + const char *attributes = "* text eol=lf\n"; + + g_repo = cl_git_sandbox_init("testrepo"); + cl_git_mkfile("./testrepo/.gitattributes", attributes); +} + +void test_checkout_checkout__cleanup(void) +{ + cl_git_sandbox_cleanup(); +} + + +static void test_file_contents(const char *path, const char *expectedcontents) +{ + int fd; + char buffer[1024] = {0}; + + fd = p_open(path, O_RDONLY); + cl_assert(fd >= 0); + + cl_assert_equal_i(p_read(fd, buffer, 1024), strlen(expectedcontents)); + cl_assert_equal_s(expectedcontents, buffer); + cl_git_pass(p_close(fd)); +} + + +void test_checkout_checkout__bare(void) +{ + cl_git_sandbox_cleanup(); + g_repo = cl_git_sandbox_init("testrepo.git"); + cl_git_fail(git_checkout_head(g_repo, NULL, NULL)); +} + +void test_checkout_checkout__default(void) +{ + cl_git_pass(git_checkout_head(g_repo, NULL, NULL)); + test_file_contents("./testrepo/README", "hey there\n"); + test_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n"); + test_file_contents("./testrepo/new.txt", "my new file\n"); +} + + +void test_checkout_checkout__crlf(void) +{ + const char *attributes = + "branch_file.txt text eol=crlf\n" + "new.txt text eol=lf\n"; + const char *expected_readme_text = +#ifdef GIT_WIN32 + "hey there\r\n"; +#else + "hey there\n"; +#endif + cl_git_mkfile("./testrepo/.gitattributes", attributes); + cl_git_pass(git_checkout_head(g_repo, NULL, NULL)); + test_file_contents("./testrepo/README", expected_readme_text); + test_file_contents("./testrepo/new.txt", "my new file\n"); + test_file_contents("./testrepo/branch_file.txt", "hi\r\nbye!\r\n"); +} + +static void enable_symlinks(bool enable) +{ + git_config *cfg; + cl_git_pass(git_repository_config(&cfg, g_repo)); + cl_git_pass(git_config_set_bool(cfg, "core.symlinks", enable)); + git_config_free(cfg); +} + +void test_checkout_checkout__symlinks(void) +{ + /* First try with symlinks forced on */ + enable_symlinks(true); + cl_git_pass(git_checkout_head(g_repo, NULL, NULL)); + +#ifdef GIT_WIN32 + test_file_contents("./testrepo/link_to_new.txt", "new.txt"); +#else + { + char link_data[1024]; + size_t link_size = 1024; + + link_size = p_readlink("./testrepo/link_to_new.txt", link_data, link_size); + link_data[link_size] = '\0'; + cl_assert_equal_i(link_size, strlen("new.txt")); + cl_assert_equal_s(link_data, "new.txt"); + test_file_contents("./testrepo/link_to_new.txt", "my new file\n"); + } +#endif + + /* Now with symlinks forced off */ + cl_git_sandbox_cleanup(); + g_repo = cl_git_sandbox_init("testrepo"); + enable_symlinks(false); + cl_git_pass(git_checkout_head(g_repo, NULL, NULL)); + + test_file_contents("./testrepo/link_to_new.txt", "new.txt"); +} + +void test_checkout_checkout__existing_file_skip(void) +{ + git_checkout_opts opts = {0}; + cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!"); + opts.existing_file_action = GIT_CHECKOUT_SKIP_EXISTING; + cl_git_pass(git_checkout_head(g_repo, &opts, NULL)); + test_file_contents("./testrepo/new.txt", "This isn't what's stored!"); +} + +void test_checkout_checkout__existing_file_overwrite(void) +{ + git_checkout_opts opts = {0}; + cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!"); + opts.existing_file_action = GIT_CHECKOUT_OVERWRITE_EXISTING; + cl_git_pass(git_checkout_head(g_repo, &opts, NULL)); + test_file_contents("./testrepo/new.txt", "my new file\n"); +} + +void test_checkout_checkout__disable_filters(void) +{ + git_checkout_opts opts = {0}; + cl_git_mkfile("./testrepo/.gitattributes", "*.txt text eol=crlf\n"); + /* TODO cl_git_pass(git_checkout_head(g_repo, &opts, NULL));*/ + /* TODO test_file_contents("./testrepo/new.txt", "my new file\r\n");*/ + opts.disable_filters = true; + cl_git_pass(git_checkout_head(g_repo, &opts, NULL)); + test_file_contents("./testrepo/new.txt", "my new file\n"); +} + +void test_checkout_checkout__dir_modes(void) +{ +#ifndef GIT_WIN32 + git_checkout_opts opts = {0}; + struct stat st; + git_reference *ref; + + cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/dir")); + + opts.dir_mode = 0701; + cl_git_pass(git_checkout_reference(ref, &opts, NULL)); + cl_git_pass(p_stat("./testrepo/a", &st)); + cl_assert_equal_i(st.st_mode & 0777, 0701); + + /* File-mode test, since we're on the 'dir' branch */ + cl_git_pass(p_stat("./testrepo/a/b.txt", &st)); + cl_assert_equal_i(st.st_mode & 0777, 0755); + + git_reference_free(ref); +#endif +} + +void test_checkout_checkout__override_file_modes(void) +{ +#ifndef GIT_WIN32 + git_checkout_opts opts = {0}; + struct stat st; + + opts.file_mode = 0700; + cl_git_pass(git_checkout_head(g_repo, &opts, NULL)); + cl_git_pass(p_stat("./testrepo/new.txt", &st)); + cl_assert_equal_i(st.st_mode & 0777, 0700); +#endif +} + +void test_checkout_checkout__open_flags(void) +{ + git_checkout_opts opts = {0}; + + cl_git_mkfile("./testrepo/new.txt", "hi\n"); + opts.file_open_flags = O_CREAT | O_RDWR | O_APPEND; + cl_git_pass(git_checkout_head(g_repo, &opts, NULL)); + test_file_contents("./testrepo/new.txt", "hi\nmy new file\n"); +} + +void test_checkout_checkout__detached_head(void) +{ + /* TODO: write this when git_checkout_commit is implemented. */ +} diff --git a/tests-clar/clone/clone.c b/tests-clar/clone/clone.c new file mode 100644 index 000000000..4cca15ffe --- /dev/null +++ b/tests-clar/clone/clone.c @@ -0,0 +1,139 @@ +#include "clar_libgit2.h" + +#include "git2/clone.h" +#include "repository.h" + +#define DO_LOCAL_TEST 0 +#define DO_LIVE_NETWORK_TESTS 0 +#define LIVE_REPO_URL "http://github.com/libgit2/node-gitteh" + + +static git_repository *g_repo; + +void test_clone_clone__initialize(void) +{ + g_repo = NULL; +} + +void test_clone_clone__cleanup(void) +{ + if (g_repo) { + git_repository_free(g_repo); + g_repo = NULL; + } +} + +// TODO: This is copy/pasted from network/remotelocal.c. +static void build_local_file_url(git_buf *out, const char *fixture) +{ + const char *in_buf; + + git_buf path_buf = GIT_BUF_INIT; + + cl_git_pass(git_path_prettify_dir(&path_buf, fixture, NULL)); + cl_git_pass(git_buf_puts(out, "file://")); + +#ifdef GIT_WIN32 + /* + * A FILE uri matches the following format: file://[host]/path + * where "host" can be empty and "path" is an absolute path to the resource. + * + * In this test, no hostname is used, but we have to ensure the leading triple slashes: + * + * *nix: file:///usr/home/... + * Windows: file:///C:/Users/... + */ + cl_git_pass(git_buf_putc(out, '/')); +#endif + + in_buf = git_buf_cstr(&path_buf); + + /* + * A very hacky Url encoding that only takes care of escaping the spaces + */ + while (*in_buf) { + if (*in_buf == ' ') + cl_git_pass(git_buf_puts(out, "%20")); + else + cl_git_pass(git_buf_putc(out, *in_buf)); + + in_buf++; + } + + git_buf_free(&path_buf); +} + + +void test_clone_clone__bad_url(void) +{ + /* Clone should clean up the mess if the URL isn't a git repository */ + cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", NULL, NULL, NULL)); + cl_assert(!git_path_exists("./foo")); + cl_git_fail(git_clone_bare(&g_repo, "not_a_repo", "./foo.git", NULL)); + cl_assert(!git_path_exists("./foo.git")); +} + + +void test_clone_clone__local(void) +{ + git_buf src = GIT_BUF_INIT; + build_local_file_url(&src, cl_fixture("testrepo.git")); + +#if DO_LOCAL_TEST + cl_git_pass(git_clone(&g_repo, git_buf_cstr(&src), "./local", NULL, NULL, NULL)); + git_repository_free(g_repo); + git_futils_rmdir_r("./local", GIT_DIRREMOVAL_FILES_AND_DIRS); + cl_git_pass(git_clone_bare(&g_repo, git_buf_cstr(&src), "./local.git", NULL)); + git_futils_rmdir_r("./local.git", GIT_DIRREMOVAL_FILES_AND_DIRS); +#endif + + git_buf_free(&src); +} + + +void test_clone_clone__network_full(void) +{ +#if DO_LIVE_NETWORK_TESTS + git_remote *origin; + + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test2", NULL, NULL, NULL)); + cl_assert(!git_repository_is_bare(g_repo)); + cl_git_pass(git_remote_load(&origin, g_repo, "origin")); + git_futils_rmdir_r("./test2", GIT_DIRREMOVAL_FILES_AND_DIRS); +#endif +} + +void test_clone_clone__network_bare(void) +{ +#if DO_LIVE_NETWORK_TESTS + git_remote *origin; + + cl_git_pass(git_clone_bare(&g_repo, LIVE_REPO_URL, "test", NULL)); + cl_assert(git_repository_is_bare(g_repo)); + cl_git_pass(git_remote_load(&origin, g_repo, "origin")); + git_futils_rmdir_r("./test", GIT_DIRREMOVAL_FILES_AND_DIRS); +#endif +} + + +void test_clone_clone__already_exists(void) +{ +#if DO_LIVE_NETWORK_TESTS + /* Should pass with existing-but-empty dir */ + p_mkdir("./foo", GIT_DIR_MODE); + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); + git_repository_free(g_repo); g_repo = NULL; + git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); +#endif + + /* Should fail with a file */ + cl_git_mkfile("./foo", "Bar!"); + cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); + git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); + + /* Should fail with existing-and-nonempty dir */ + p_mkdir("./foo", GIT_DIR_MODE); + cl_git_mkfile("./foo/bar", "Baz!"); + cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); + git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); +} diff --git a/tests-clar/index/read_tree.c b/tests-clar/index/read_tree.c index c657d4f71..0479332dc 100644 --- a/tests-clar/index/read_tree.c +++ b/tests-clar/index/read_tree.c @@ -33,7 +33,7 @@ void test_index_read_tree__read_write_involution(void) /* read-tree */ git_tree_lookup(&tree, repo, &expected); - cl_git_pass(git_index_read_tree(index, tree)); + cl_git_pass(git_index_read_tree(index, tree, NULL)); git_tree_free(tree); cl_git_pass(git_tree_create_fromindex(&tree_oid, index)); diff --git a/tests-clar/refs/create.c b/tests-clar/refs/create.c index dde4c5745..2e42cb607 100644 --- a/tests-clar/refs/create.c +++ b/tests-clar/refs/create.c @@ -4,7 +4,7 @@ #include "git2/reflog.h" #include "reflog.h" -static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"; +static const char *current_master_tip = "099fabac3a9ea935598528c27f866e34089c2eff"; static const char *current_head_target = "refs/heads/master"; static git_repository *g_repo; diff --git a/tests-clar/refs/list.c b/tests-clar/refs/list.c index 2a7b157ca..ac3cc0058 100644 --- a/tests-clar/refs/list.c +++ b/tests-clar/refs/list.c @@ -36,7 +36,7 @@ void test_refs_list__all(void) /* We have exactly 9 refs in total if we include the packed ones: * there is a reference that exists both in the packfile and as * loose, but we only list it once */ - cl_assert(ref_list.count == 9); + cl_assert_equal_i(ref_list.count, 10); git_strarray_free(&ref_list); } diff --git a/tests-clar/resources/testrepo/.gitted/config b/tests-clar/resources/testrepo/.gitted/config index 1a5aacdfa..d0114012f 100644 --- a/tests-clar/resources/testrepo/.gitted/config +++ b/tests-clar/resources/testrepo/.gitted/config @@ -1,7 +1,7 @@ [core] repositoryformatversion = 0 filemode = true - bare = true + bare = false logallrefupdates = true [remote "test"] url = git://github.com/libgit2/libgit2 diff --git a/tests-clar/resources/testrepo/.gitted/objects/09/9fabac3a9ea935598528c27f866e34089c2eff b/tests-clar/resources/testrepo/.gitted/objects/09/9fabac3a9ea935598528c27f866e34089c2eff new file mode 100644 index 000000000..c60c78fb5 --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/09/9fabac3a9ea935598528c27f866e34089c2eff @@ -0,0 +1 @@ +xQ P9^@B!1F'J?#7KJhMVE,.3uVsH-;U,MPIɉ&ĔסKO.2µո$8Nݗr!lCTklUgf0sÓG(
\ No newline at end of file diff --git a/tests-clar/resources/testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0e b/tests-clar/resources/testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0e Binary files differnew file mode 100644 index 000000000..b7d944fa1 --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0e diff --git a/tests-clar/resources/testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925 b/tests-clar/resources/testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925 Binary files differnew file mode 100644 index 000000000..d37b93e4f --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925 diff --git a/tests-clar/resources/testrepo/.gitted/objects/45/dd856fdd4d89b884c340ba0e047752d9b085d6 b/tests-clar/resources/testrepo/.gitted/objects/45/dd856fdd4d89b884c340ba0e047752d9b085d6 Binary files differnew file mode 100644 index 000000000..a83ed9763 --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/45/dd856fdd4d89b884c340ba0e047752d9b085d6 diff --git a/tests-clar/resources/testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63 b/tests-clar/resources/testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63 Binary files differnew file mode 100644 index 000000000..e9150214b --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63 diff --git a/tests-clar/resources/testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dcc b/tests-clar/resources/testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dcc Binary files differnew file mode 100644 index 000000000..b669961d8 --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dcc diff --git a/tests-clar/resources/testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735 b/tests-clar/resources/testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735 Binary files differnew file mode 100644 index 000000000..9ff5eb2b5 --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735 diff --git a/tests-clar/resources/testrepo/.gitted/objects/87/380ae84009e9c503506c2f6143a4fc6c60bf80 b/tests-clar/resources/testrepo/.gitted/objects/87/380ae84009e9c503506c2f6143a4fc6c60bf80 Binary files differnew file mode 100644 index 000000000..3042f5790 --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/87/380ae84009e9c503506c2f6143a4fc6c60bf80 diff --git a/tests-clar/resources/testrepo/.gitted/objects/c0/528fd6cc988c0a40ce0be11bc192fc8dc5346e b/tests-clar/resources/testrepo/.gitted/objects/c0/528fd6cc988c0a40ce0be11bc192fc8dc5346e Binary files differnew file mode 100644 index 000000000..0401ab489 --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/c0/528fd6cc988c0a40ce0be11bc192fc8dc5346e diff --git a/tests-clar/resources/testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9 b/tests-clar/resources/testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9 Binary files differnew file mode 100644 index 000000000..7620c514f --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9 diff --git a/tests-clar/resources/testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83 b/tests-clar/resources/testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83 Binary files differnew file mode 100644 index 000000000..00940f0f2 --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83 diff --git a/tests-clar/resources/testrepo/.gitted/refs/heads/dir b/tests-clar/resources/testrepo/.gitted/refs/heads/dir new file mode 100644 index 000000000..4567d37fa --- /dev/null +++ b/tests-clar/resources/testrepo/.gitted/refs/heads/dir @@ -0,0 +1 @@ +144344043ba4d4a405da03de3844aa829ae8be0e diff --git a/tests-clar/resources/testrepo/.gitted/refs/heads/master b/tests-clar/resources/testrepo/.gitted/refs/heads/master index 3d8f0a402..f31fe781b 100644 --- a/tests-clar/resources/testrepo/.gitted/refs/heads/master +++ b/tests-clar/resources/testrepo/.gitted/refs/heads/master @@ -1 +1 @@ -a65fedf39aefe402d3bb6e24df4d4f5fe4547750 +099fabac3a9ea935598528c27f866e34089c2eff diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c index bfd257a3b..2abf36833 100644 --- a/tests-clar/status/worktree.c +++ b/tests-clar/status/worktree.c @@ -484,7 +484,7 @@ static void fill_index_wth_head_entries(git_repository *repo, git_index *index) cl_git_pass(git_commit_lookup(&commit, repo, &oid)); cl_git_pass(git_commit_tree(&tree, commit)); - cl_git_pass(git_index_read_tree(index, tree)); + cl_git_pass(git_index_read_tree(index, tree, NULL)); cl_git_pass(git_index_write(index)); git_tree_free(tree); |
