void test_core_filebuf__symlink_follow(void) { git_filebuf file = GIT_FILEBUF_INIT; const char *dir = "linkdir", *source = "linkdir/link"; #ifdef GIT_WIN32 cl_skip(); #endif cl_git_pass(p_mkdir(dir, 0777)); cl_git_pass(p_symlink("target", source)); cl_git_pass(git_filebuf_open(&file, source, 0, 0666)); cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); cl_assert_equal_i(true, git_path_exists("linkdir/target.lock")); cl_git_pass(git_filebuf_commit(&file)); cl_assert_equal_i(true, git_path_exists("linkdir/target")); git_filebuf_cleanup(&file); /* The second time around, the target file does exist */ cl_git_pass(git_filebuf_open(&file, source, 0, 0666)); cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); cl_assert_equal_i(true, git_path_exists("linkdir/target.lock")); cl_git_pass(git_filebuf_commit(&file)); cl_assert_equal_i(true, git_path_exists("linkdir/target")); git_filebuf_cleanup(&file); cl_git_pass(git_futils_rmdir_r(dir, NULL, GIT_RMDIR_REMOVE_FILES)); }
void test_checkout_icase__overwrites_links_for_folders_when_forced(void) { checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE; 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"); }
void test_checkout_icase__refuses_to_overwrite_links_for_folders(void) { checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE|GIT_CHECKOUT_RECREATE_MISSING; cl_must_pass(p_symlink("..", "testrepo/A")); cl_git_fail(git_checkout_tree(repo, obj, &checkout_opts)); cl_assert(!git_path_exists("b.txt")); assert_name_is("testrepo/A"); }
static int symlink_or_fake(git_repository *repo, const char *a, const char *b) { int symlinks; cl_git_pass(git_repository__cvar(&symlinks, repo, GIT_CVAR_SYMLINKS)); if (symlinks) return p_symlink(a, b); else return git_futils_fake_symlink(a, b); }
void test_attr_ignore__symlink_to_outside(void) { #ifdef GIT_WIN32 cl_skip(); #endif cl_git_rewritefile("attr/.gitignore", "symlink\n"); cl_git_mkfile("target", "target"); cl_git_pass(p_symlink("../target", "attr/symlink")); assert_is_ignored(true, "symlink"); assert_is_ignored(true, "lala/../symlink"); }
static int blob_content_to_link(git_blob *blob, const char *path, bool can_symlink) { git_buf linktarget = GIT_BUF_INIT; int error; if ((error = git_blob__getbuf(&linktarget, blob)) < 0) return error; if (can_symlink) error = p_symlink(git_buf_cstr(&linktarget), path); else error = git_futils_fake_symlink(git_buf_cstr(&linktarget), path); git_buf_free(&linktarget); return error; }
void test_core_filebuf__symlink_depth(void) { git_filebuf file = GIT_FILEBUF_INIT; const char *dir = "linkdir", *source = "linkdir/link"; #ifdef GIT_WIN32 cl_skip(); #endif cl_git_pass(p_mkdir(dir, 0777)); /* Endless loop */ cl_git_pass(p_symlink("link", source)); cl_git_fail(git_filebuf_open(&file, source, 0, 0666)); cl_git_pass(git_futils_rmdir_r(dir, NULL, GIT_RMDIR_REMOVE_FILES)); }
static bool are_symlinks_supported(const char *wd_path) { git_buf path = GIT_BUF_INIT; int fd; struct stat st; int symlinks_supported = -1; if ((fd = git_futils_mktmp(&path, wd_path, 0666)) < 0 || p_close(fd) < 0 || p_unlink(path.ptr) < 0 || p_symlink("testing", path.ptr) < 0 || p_lstat(path.ptr, &st) < 0) symlinks_supported = false; else symlinks_supported = (S_ISLNK(st.st_mode) != 0); (void)p_unlink(path.ptr); git_buf_free(&path); return symlinks_supported; }