#include "checkout_helpers.h"
#include "git2/checkout.h"
-#include "fileops.h"
+#include "futils.h"
#include "repository.h"
#include "remote.h"
#include "repo/repo_helpers.h"
cl_assert_equal_i(false, git_path_isdir("./testrepo/dir"));
}
+void test_checkout_index__can_disable_pathspec_match(void)
+{
+ char *files_to_checkout[] = { "test10.txt", "test11.txt"};
+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+ git_object *objects;
+ git_index *index;
+
+ /* reset to beginning of history (i.e. just a README file) */
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+
+ cl_git_pass(git_revparse_single(&objects, g_repo, "8496071c1b46c854b31185ea97743be6a8774479"));
+ cl_git_pass(git_checkout_tree(g_repo, objects, &opts));
+ cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(objects)));
+ git_object_free(objects);
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ /* We create 4 files and commit them */
+ cl_git_mkfile("testrepo/test9.txt", "original\n");
+ cl_git_mkfile("testrepo/test10.txt", "original\n");
+ cl_git_mkfile("testrepo/test11.txt", "original\n");
+ cl_git_mkfile("testrepo/test12.txt", "original\n");
+
+ cl_git_pass(git_index_add_bypath(index, "test9.txt"));
+ cl_git_pass(git_index_add_bypath(index, "test10.txt"));
+ cl_git_pass(git_index_add_bypath(index, "test11.txt"));
+ cl_git_pass(git_index_add_bypath(index, "test12.txt"));
+ cl_git_pass(git_index_write(index));
+
+ cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "commit our test files");
+
+ /* We modify the content of all 4 of our files */
+ cl_git_rewritefile("testrepo/test9.txt", "modified\n");
+ cl_git_rewritefile("testrepo/test10.txt", "modified\n");
+ cl_git_rewritefile("testrepo/test11.txt", "modified\n");
+ cl_git_rewritefile("testrepo/test12.txt", "modified\n");
+
+ /* We checkout only test10.txt and test11.txt */
+ opts.checkout_strategy =
+ GIT_CHECKOUT_FORCE |
+ GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH;
+ opts.paths.strings = files_to_checkout;
+ opts.paths.count = ARRAY_SIZE(files_to_checkout);
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ /* The only files that have been reverted to their original content
+ should be test10.txt and test11.txt */
+ check_file_contents("testrepo/test9.txt", "modified\n");
+ check_file_contents("testrepo/test10.txt", "original\n");
+ check_file_contents("testrepo/test11.txt", "original\n");
+ check_file_contents("testrepo/test12.txt", "modified\n");
+
+ git_index_free(index);
+}
+
void test_checkout_index__honor_the_specified_pathspecs(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
static void populate_symlink_workdir(void)
{
+ git_buf path = GIT_BUF_INIT;
git_repository *repo;
git_remote *origin;
git_object *target;
const char *url = git_repository_path(g_repo);
- cl_git_pass(git_repository_init(&repo, "../symlink.git", true));
+ cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), "symlink.git"));
+ cl_git_pass(git_repository_init(&repo, path.ptr, true));
cl_git_pass(git_repository_set_workdir(repo, "symlink", 1));
/* Delete the `origin` repo (if it exists) so we can recreate it. */
cl_git_pass(git_revparse_single(&target, repo, "remotes/origin/master"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
+
git_object_free(target);
git_repository_free(repo);
+ git_buf_dispose(&path);
}
void test_checkout_index__honor_coresymlinks_default_true(void)
cl_must_pass(p_mkdir("symlink", 0777));
- if (!filesystem_supports_symlinks("symlink/test"))
+ if (!git_path_supports_symlinks("symlink/test"))
cl_skip();
#ifdef GIT_WIN32
* supports symlinks. Bail entirely on POSIX platforms that
* do support symlinks.
*/
- if (filesystem_supports_symlinks("symlink/test"))
+ if (git_path_supports_symlinks("symlink/test"))
cl_skip();
#endif
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- if (filesystem_supports_symlinks("testrepo/test")) {
+ if (git_path_supports_symlinks("testrepo/test")) {
cl_skip();
}
char link_data[GIT_PATH_MAX];
size_t link_size = GIT_PATH_MAX;
- if (!filesystem_supports_symlinks("testrepo/test")) {
+ if (!git_path_supports_symlinks("testrepo/test")) {
cl_skip();
}