void test_checkout_icase__conflicts_with_casechanged_subtrees(void) { git_reference *orig_ref; git_object *orig, *subtrees; git_oid oid; git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; cl_git_pass(git_reference_lookup_resolved(&orig_ref, repo, "HEAD", 100)); cl_git_pass(git_object_lookup(&orig, repo, git_reference_target(orig_ref), GIT_OBJ_COMMIT)); cl_git_pass(git_reset(repo, (git_object *)orig, GIT_RESET_HARD, NULL)); cl_must_pass(p_mkdir("testrepo/AB", 0777)); cl_must_pass(p_mkdir("testrepo/AB/C", 0777)); cl_git_write2file("testrepo/AB/C/3.txt", "Foobar!\n", 8, O_RDWR|O_CREAT, 0666); cl_git_pass(git_reference_name_to_id(&oid, repo, "refs/heads/subtrees")); cl_git_pass(git_object_lookup(&subtrees, repo, &oid, GIT_OBJ_ANY)); cl_git_fail(git_checkout_tree(repo, subtrees, &checkout_opts)); git_object_free(orig); git_object_free(subtrees); git_reference_free(orig_ref); }
void test_repo_iterator__unreadable_dir(void) { git_iterator *i; const git_index_entry *e; if (!cl_is_chmod_supported()) return; g_repo = cl_git_sandbox_init("empty_standard_repo"); cl_must_pass(p_mkdir("empty_standard_repo/r", 0777)); cl_git_mkfile("empty_standard_repo/r/a", "hello"); cl_must_pass(p_mkdir("empty_standard_repo/r/b", 0777)); cl_git_mkfile("empty_standard_repo/r/b/problem", "not me"); cl_must_pass(p_chmod("empty_standard_repo/r/b", 0000)); cl_must_pass(p_mkdir("empty_standard_repo/r/c", 0777)); cl_git_mkfile("empty_standard_repo/r/d", "final"); cl_git_pass(git_iterator_for_filesystem( &i, "empty_standard_repo/r", NULL)); cl_git_pass(git_iterator_advance(&e, i)); /* a */ cl_git_fail(git_iterator_advance(&e, i)); /* b */ cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&e, i)); cl_must_pass(p_chmod("empty_standard_repo/r/b", 0777)); git_iterator_free(i); }
/* make sure git_filebuf_commit takes umask into account */ void test_core_filebuf__umask(void) { git_filebuf file = GIT_FILEBUF_INIT; char test[] = "test"; struct stat statbuf; mode_t mask, os_mask; #ifdef GIT_WIN32 os_mask = 0600; #else os_mask = 0777; #endif p_umask(mask = p_umask(0)); cl_assert(file.buffer == NULL); cl_git_pass(git_filebuf_open(&file, test, 0, 0666)); cl_assert(file.buffer != NULL); cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); cl_assert(file.buffer != NULL); cl_git_pass(git_filebuf_commit(&file)); cl_assert(file.buffer == NULL); cl_must_pass(p_stat("test", &statbuf)); cl_assert_equal_i(statbuf.st_mode & os_mask, (0666 & ~mask) & os_mask); cl_must_pass(p_unlink(test)); }
void test_path_win32__absolute_from_relative(void) { #ifdef GIT_WIN32 char cwd_backup[MAX_PATH]; cl_must_pass(p_getcwd(cwd_backup, MAX_PATH)); cl_must_pass(p_chdir("C:/")); test_utf8_to_utf16("Foo", L"\\\\?\\C:\\Foo"); test_utf8_to_utf16("..\\..\\Foo", L"\\\\?\\C:\\Foo"); test_utf8_to_utf16("Foo\\..", L"\\\\?\\C:\\"); test_utf8_to_utf16("Foo\\..\\..", L"\\\\?\\C:\\"); test_utf8_to_utf16("", L"\\\\?\\C:\\"); cl_must_pass(p_chdir("C:/Windows")); test_utf8_to_utf16("Foo", L"\\\\?\\C:\\Windows\\Foo"); test_utf8_to_utf16("Foo\\Bar", L"\\\\?\\C:\\Windows\\Foo\\Bar"); test_utf8_to_utf16("..\\Foo", L"\\\\?\\C:\\Foo"); test_utf8_to_utf16("Foo\\..\\Bar", L"\\\\?\\C:\\Windows\\Bar"); test_utf8_to_utf16("", L"\\\\?\\C:\\Windows"); cl_must_pass(p_chdir(cwd_backup)); #endif }
/* Ensure that the .gitignore in the subdirectory only affects * items in the subdirectory. */ void test_attr_ignore__gitignore_in_subdir(void) { cl_git_rmfile("attr/.gitignore"); cl_must_pass(p_mkdir("attr/dir1", 0777)); cl_must_pass(p_mkdir("attr/dir1/dir2", 0777)); cl_must_pass(p_mkdir("attr/dir1/dir2/dir3", 0777)); cl_git_mkfile("attr/dir1/dir2/dir3/.gitignore", "dir1/\ndir1/subdir/"); assert_is_ignored(false, "dir1/file"); assert_is_ignored(false, "dir1/dir2/file"); assert_is_ignored(false, "dir1/dir2/dir3/file"); assert_is_ignored(true, "dir1/dir2/dir3/dir1/file"); assert_is_ignored(true, "dir1/dir2/dir3/dir1/subdir/foo"); if (cl_repo_get_bool(g_repo, "core.ignorecase")) { cl_git_mkfile("attr/dir1/dir2/dir3/.gitignore", "DiR1/\nDiR1/subdir/\n"); assert_is_ignored(false, "dir1/file"); assert_is_ignored(false, "dir1/dir2/file"); assert_is_ignored(false, "dir1/dir2/dir3/file"); assert_is_ignored(true, "dir1/dir2/dir3/dir1/file"); assert_is_ignored(true, "dir1/dir2/dir3/dir1/subdir/foo"); } }
/* Test that writing an invalid filename fails */ void test_index_tests__add_invalid_filename(void) { git_repository *repo; p_mkdir("invalid", 0700); cl_git_pass(git_repository_init(&repo, "./invalid", 0)); cl_must_pass(p_mkdir("./invalid/subdir", 0777)); /* cl_git_mkfile() needs the dir to exist */ if (!git_path_exists("./invalid/.GIT")) cl_must_pass(p_mkdir("./invalid/.GIT", 0777)); if (!git_path_exists("./invalid/.GiT")) cl_must_pass(p_mkdir("./invalid/.GiT", 0777)); add_invalid_filename(repo, ".git/hello"); add_invalid_filename(repo, ".GIT/hello"); add_invalid_filename(repo, ".GiT/hello"); add_invalid_filename(repo, "./.git/hello"); add_invalid_filename(repo, "./foo"); add_invalid_filename(repo, "./bar"); add_invalid_filename(repo, "subdir/../bar"); git_repository_free(repo); cl_fixture_cleanup("invalid"); }
void test_odb_freshen__loose_object(void) { git_oid expected_id, id; struct stat before, after; struct p_timeval old_times[2]; cl_git_pass(git_oid_fromstr(&expected_id, LOOSE_ID)); old_times[0].tv_sec = 1234567890; old_times[0].tv_usec = 0; old_times[1].tv_sec = 1234567890; old_times[1].tv_usec = 0; /* set time to way back */ cl_must_pass(p_utimes("testrepo.git/objects/" LOOSE_FN, old_times)); cl_must_pass(p_lstat("testrepo.git/objects/" LOOSE_FN, &before)); cl_git_pass(git_odb_write(&id, odb, LOOSE_STR, CONST_STRLEN(LOOSE_STR), GIT_OBJ_BLOB)); cl_assert_equal_oid(&expected_id, &id); cl_must_pass(p_lstat("testrepo.git/objects/" LOOSE_FN, &after)); cl_assert(before.st_atime < after.st_atime); cl_assert(before.st_mtime < after.st_mtime); }
/* Ensure that files do not match folder cases */ void test_attr_ignore__dont_ignore_files_for_folder(void) { cl_git_rmfile("attr/.gitignore"); cl_git_mkfile("attr/dir/.gitignore", "test/\n"); /* Create "test" as a file; ensure it is not ignored. */ cl_git_mkfile("attr/dir/test", "This is a file."); assert_is_ignored(false, "dir/test"); if (cl_repo_get_bool(g_repo, "core.ignorecase")) assert_is_ignored(false, "dir/TeSt"); /* Create "test" as a directory; ensure it is ignored. */ cl_git_rmfile("attr/dir/test"); cl_must_pass(p_mkdir("attr/dir/test", 0777)); assert_is_ignored(true, "dir/test"); if (cl_repo_get_bool(g_repo, "core.ignorecase")) assert_is_ignored(true, "dir/TeSt"); /* Remove "test" entirely; ensure it is not ignored. * (As it doesn't exist, it is not a directory.) */ cl_must_pass(p_rmdir("attr/dir/test")); assert_is_ignored(false, "dir/test"); if (cl_repo_get_bool(g_repo, "core.ignorecase")) assert_is_ignored(false, "dir/TeSt"); }
void test_path_win32__8dot3_name(void) { #ifdef GIT_WIN32 char *shortname; if (!cl_sandbox_supports_8dot3()) clar__skip(); /* Some guaranteed short names */ cl_assert_equal_s("PROGRA~1", (shortname = git_win32_path_8dot3_name("C:\\Program Files"))); git__free(shortname); cl_assert_equal_s("WINDOWS", (shortname = git_win32_path_8dot3_name("C:\\WINDOWS"))); git__free(shortname); /* Create some predictible short names */ cl_must_pass(p_mkdir(".foo", 0777)); cl_assert_equal_s("FOO~1", (shortname = git_win32_path_8dot3_name(".foo"))); git__free(shortname); cl_git_write2file("bar~1", "foobar\n", 7, O_RDWR|O_CREAT, 0666); cl_must_pass(p_mkdir(".bar", 0777)); cl_assert_equal_s("BAR~2", (shortname = git_win32_path_8dot3_name(".bar"))); git__free(shortname); #endif }
void test_core_filebuf__detects_directory(void) { git_filebuf file = GIT_FILEBUF_INIT, fail = GIT_FILEBUF_INIT; cl_must_pass(p_mkdir("foo", 0777)); cl_git_fail_with(GIT_EDIRECTORY, git_filebuf_open(&file, "foo", 0, 0666)); cl_must_pass(p_rmdir("foo")); }
static void file_create(const char *filename, const char *content) { int fd = p_creat(filename, 0644); cl_assert(fd >= 0); cl_must_pass(p_write(fd, content, strlen(content))); cl_must_pass(p_close(fd)); }
void cl_git_write2file( const char *filename, const char *new_content, int flags, unsigned int mode) { int fd = p_open(filename, flags, mode); cl_assert(fd >= 0); if (!new_content) new_content = "\n"; cl_must_pass(p_write(fd, new_content, strlen(new_content))); cl_must_pass(p_close(fd)); }
bool cl_toggle_filemode(const char *filename) { struct stat st1, st2; cl_must_pass(p_stat(filename, &st1)); cl_must_pass(p_chmod(filename, st1.st_mode ^ 0100)); cl_must_pass(p_stat(filename, &st2)); return (st1.st_mode != st2.st_mode); }
void test_iterator_workdir__advance_over(void) { git_iterator *i; git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT; i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND; g_repo = cl_git_sandbox_init("icase"); /* create an empty directory */ cl_must_pass(p_mkdir("icase/empty", 0777)); /* create a directory in which all contents are ignored */ cl_must_pass(p_mkdir("icase/all_ignored", 0777)); cl_git_rewritefile("icase/all_ignored/one", "This is ignored\n"); cl_git_rewritefile("icase/all_ignored/two", "This, too, is ignored\n"); cl_git_rewritefile("icase/all_ignored/.gitignore", ".gitignore\none\ntwo\n"); /* create a directory in which not all contents are ignored */ cl_must_pass(p_mkdir("icase/some_ignored", 0777)); cl_git_rewritefile("icase/some_ignored/one", "This is ignored\n"); cl_git_rewritefile("icase/some_ignored/two", "This is not ignored\n"); cl_git_rewritefile("icase/some_ignored/.gitignore", ".gitignore\none\n"); /* create a directory which has some empty children */ cl_must_pass(p_mkdir("icase/empty_children", 0777)); cl_must_pass(p_mkdir("icase/empty_children/empty1", 0777)); cl_must_pass(p_mkdir("icase/empty_children/empty2", 0777)); cl_must_pass(p_mkdir("icase/empty_children/empty3", 0777)); /* create a directory which will disappear! */ cl_must_pass(p_mkdir("icase/missing_directory", 0777)); cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts)); cl_must_pass(p_rmdir("icase/missing_directory")); expect_advance_over(i, "B", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "D", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "F", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "H", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "J", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "L/", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "a", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "all_ignored/", GIT_ITERATOR_STATUS_IGNORED); expect_advance_over(i, "c", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "e", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "empty/", GIT_ITERATOR_STATUS_EMPTY); expect_advance_over(i, "empty_children/", GIT_ITERATOR_STATUS_EMPTY); expect_advance_over(i, "g", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "i", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "k/", GIT_ITERATOR_STATUS_NORMAL); expect_advance_over(i, "missing_directory/", GIT_ITERATOR_STATUS_EMPTY); expect_advance_over(i, "some_ignored/", GIT_ITERATOR_STATUS_NORMAL); cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i)); git_iterator_free(i); }
static void env_cd_( const char *path, void (*passfail_)(const char *, const char *, int), const char *file, int line) { git_buf cwd_buf = GIT_BUF_INIT; cl_git_pass(git_path_prettify_dir(&cwd_buf, ".", NULL)); cl_must_pass(p_chdir(path)); passfail_(NULL, file, line); cl_must_pass(p_chdir(git_buf_cstr(&cwd_buf))); git_buf_free(&cwd_buf); }
/* A tree that contains an entry "git~2", when we have forced the short * name for ".git" into "GIT~2". */ void test_checkout_nasty__git_custom_shortname(void) { #ifdef GIT_WIN32 if (!cl_sandbox_supports_8dot3()) clar__skip(); cl_must_pass(p_rename("nasty/.git", "nasty/_temp")); cl_git_write2file("nasty/git~1", "", 0, O_RDWR|O_CREAT, 0666); cl_must_pass(p_rename("nasty/_temp", "nasty/.git")); test_checkout_fails("refs/heads/git_tilde2", ".git/foobar"); #endif }
void cl_git_write2file( const char *path, const char *content, size_t content_len, int flags, unsigned int mode) { int fd; cl_assert(path && content); cl_assert((fd = p_open(path, flags, mode)) >= 0); if (!content_len) content_len = strlen(content); cl_must_pass(p_write(fd, content, content_len)); cl_must_pass(p_close(fd)); }
void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_filepath(void) { git_buf full_path = GIT_BUF_INIT; repo = cl_git_sandbox_init(BARE_REPO); cl_must_pass(p_mkdir(ELSEWHERE, 0777)); cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL)); cl_must_pass(git_buf_puts(&full_path, "test.txt")); assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_fromdisk); git_buf_free(&full_path); cl_must_pass(git_futils_rmdir_r(ELSEWHERE, GIT_DIRREMOVAL_FILES_AND_DIRS)); }
void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolute_filepath_pointing_outside_of_the_working_directory(void) { git_buf full_path = GIT_BUF_INIT; repo = cl_git_sandbox_init(WORKDIR); cl_must_pass(p_mkdir(ELSEWHERE, 0777)); cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL)); cl_must_pass(git_buf_puts(&full_path, "test.txt")); assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_fromdisk); git_buf_free(&full_path); cl_must_pass(git_futils_rmdir_r(ELSEWHERE, GIT_DIRREMOVAL_FILES_AND_DIRS)); }
void test_core_posix__utimes(void) { struct timeval times[2]; struct stat st; time_t curtime; int fd; /* test p_utimes */ times[0].tv_sec = 1234567890; times[0].tv_usec = 0; times[1].tv_sec = 1234567890; times[1].tv_usec = 0; cl_git_mkfile("foo", "Dummy file."); cl_must_pass(p_utimes("foo", times)); p_stat("foo", &st); cl_assert_equal_i(1234567890, st.st_atime); cl_assert_equal_i(1234567890, st.st_mtime); /* test p_futimes */ times[0].tv_sec = 1414141414; times[0].tv_usec = 0; times[1].tv_sec = 1414141414; times[1].tv_usec = 0; cl_must_pass(fd = p_open("foo", O_RDWR)); cl_must_pass(p_futimes(fd, times)); p_close(fd); p_stat("foo", &st); cl_assert_equal_i(1414141414, st.st_atime); cl_assert_equal_i(1414141414, st.st_mtime); /* test p_utimes with current time, assume that * it takes < 5 seconds to get the time...! */ cl_must_pass(p_utimes("foo", NULL)); curtime = time(NULL); p_stat("foo", &st); cl_assert((st.st_atime - curtime) < 5); cl_assert((st.st_mtime - curtime) < 5); p_unlink("foo"); }
static void create_paths(const char *root, int depth) { git_buf fullpath = GIT_BUF_INIT; size_t root_len; int i; cl_git_pass(git_buf_puts(&fullpath, root)); cl_git_pass(git_buf_putc(&fullpath, '/')); root_len = fullpath.size; for (i = 0; i < 8; i++) { bool file = (depth == 0 || (i % 2) == 0); git_buf_truncate(&fullpath, root_len); cl_git_pass(git_buf_printf(&fullpath, "item%d", i)); if (file) { cl_git_rewritefile(fullpath.ptr, "This is a file!\n"); } else { cl_must_pass(p_mkdir(fullpath.ptr, 0777)); if (depth > 0) create_paths(fullpath.ptr, (depth - 1)); } } git_buf_dispose(&fullpath); }
void cl_git_mkfile(const char *filename, const char *content) { int fd; fd = p_creat(filename, 0666); cl_assert(fd != 0); if (content) { cl_must_pass(p_write(fd, content, strlen(content))); } else { cl_must_pass(p_write(fd, filename, strlen(filename))); cl_must_pass(p_write(fd, "\n", 1)); } cl_must_pass(p_close(fd)); }
void test_repo_init__external_templates_with_leading_dot(void) { git_buf template_path = GIT_BUF_INIT; git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; cl_set_cleanup(&cleanup_repository, "templated.git"); template_sandbox("template"); cl_must_pass(p_rename("template", ".template_with_leading_dot")); cl_git_pass(git_buf_joinpath(&template_path, clar_sandbox_path(), ".template_with_leading_dot")); configure_templatedir(template_path.ptr); opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts)); validate_templates(_repo, ".template_with_leading_dot"); cl_fixture_cleanup(".template_with_leading_dot"); git_buf_free(&template_path); }
static const char *template_sandbox(const char *name) { git_buf hooks_path = GIT_BUF_INIT, link_path = GIT_BUF_INIT, dotfile_path = GIT_BUF_INIT; const char *path = cl_fixture(name); cl_fixture_sandbox(name); /* create a symlink from link.sample to update.sample if the filesystem * supports it. */ cl_git_pass(git_buf_joinpath(&hooks_path, name, "hooks")); cl_git_pass(git_buf_joinpath(&link_path, hooks_path.ptr, "link.sample")); #ifdef GIT_WIN32 cl_git_mkfile(link_path.ptr, "#!/bin/sh\necho hello, world\n"); #else cl_must_pass(symlink("update.sample", link_path.ptr)); #endif /* create a file starting with a dot */ cl_git_pass(git_buf_joinpath(&dotfile_path, hooks_path.ptr, ".dotfile")); cl_git_mkfile(dotfile_path.ptr, "something\n"); git_buf_free(&dotfile_path); git_buf_free(&dotfile_path); git_buf_free(&link_path); git_buf_free(&hooks_path); return path; }
static void check_stat_data(git_index *index, const char *path, bool match) { const git_index_entry *entry; struct stat st; cl_must_pass(p_lstat(path, &st)); /* skip repo base dir name */ while (*path != '/') ++path; ++path; entry = git_index_get_bypath(index, path, 0); cl_assert(entry); if (match) { cl_assert(st.st_ctime == entry->ctime.seconds); cl_assert(st.st_mtime == entry->mtime.seconds); cl_assert(st.st_size == entry->file_size); cl_assert(st.st_uid == entry->uid); cl_assert(st.st_gid == entry->gid); cl_assert_equal_i_fmt( GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o"); if (cl_is_chmod_supported()) cl_assert_equal_b( GIT_PERMS_IS_EXEC(st.st_mode), GIT_PERMS_IS_EXEC(entry->mode)); } else { /* most things will still match */ cl_assert(st.st_size != entry->file_size); /* would check mtime, but with second resolution it won't work :( */ } }
/* make sure git_filebuf_open doesn't delete an existing lock */ void test_core_filebuf__0(void) { git_filebuf file; int fd; char test[] = "test", testlock[] = "test.lock"; fd = p_creat(testlock, 0744); cl_must_pass(fd); cl_must_pass(p_close(fd)); cl_git_fail(git_filebuf_open(&file, test, 0)); cl_git_pass(git_futils_exists(testlock)); cl_must_pass(p_unlink(testlock)); }
void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void) { git_reference *ref; git_buf log_path = GIT_BUF_INIT; git_oid id; /* Create a new branch pointing at the HEAD */ git_oid_fromstr(&id, current_master_tip); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL)); git_reference_free(ref); git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head"); cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path))); /* delete the ref manually, leave the reflog */ cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head")); /* new ref creation should fail since new-dir contains reflogs still */ git_oid_fromstr(&id, current_master_tip); cl_git_fail_with(GIT_EDIRECTORY, git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL)); git_reference_free(ref); git_buf_dispose(&log_path); }
/* make sure git_filebuf_open doesn't delete an existing lock */ void test_core_filebuf__0(void) { git_filebuf file = GIT_FILEBUF_INIT; int fd; char test[] = "test", testlock[] = "test.lock"; fd = p_creat(testlock, 0744); //-V536 cl_must_pass(fd); cl_must_pass(p_close(fd)); cl_git_fail(git_filebuf_open(&file, test, 0, 0666)); cl_assert(git_path_exists(testlock)); cl_must_pass(p_unlink(testlock)); }
void test_attr_ignore__expand_tilde_to_homedir(void) { git_buf path = GIT_BUF_INIT; git_config *cfg; assert_is_ignored(false, "example.global_with_tilde"); /* construct fake home with fake global excludes */ cl_must_pass(p_mkdir("home", 0777)); cl_git_pass(git_path_prettify(&path, "home", NULL)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); cl_git_mkfile("home/globalexcludes", "# found me\n*.global_with_tilde\n"); cl_git_pass(git_repository_config(&cfg, g_repo)); cl_git_pass(git_config_set_string(cfg, "core.excludesfile", "~/globalexcludes")); git_config_free(cfg); git_attr_cache_flush(g_repo); /* must reset to pick up change */ assert_is_ignored(true, "example.global_with_tilde"); cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, NULL)); git_buf_free(&path); }
/* 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")); 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); }