Blame tests/checkout/crlf.c

Packit Service 20376f
#include "clar_libgit2.h"
Packit Service 20376f
#include "checkout_helpers.h"
Packit Service 20376f
#include "../filter/crlf.h"
Packit Service 20376f
#include "fileops.h"
Packit Service 20376f
Packit Service 20376f
#include "git2/checkout.h"
Packit Service 20376f
#include "repository.h"
Packit Service 20376f
#include "index.h"
Packit Service 20376f
#include "posix.h"
Packit Service 20376f
Packit Service 20376f
static git_repository *g_repo;
Packit Service 20376f
Packit Service 20376f
static const char *systype;
Packit Service 20376f
static git_buf expected_fixture = GIT_BUF_INIT;
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__initialize(void)
Packit Service 20376f
{
Packit Service 20376f
	g_repo = cl_git_sandbox_init("crlf");
Packit Service 20376f
Packit Service 20376f
	if (GIT_EOL_NATIVE == GIT_EOL_CRLF)
Packit Service 20376f
		systype = "windows";
Packit Service 20376f
	else
Packit Service 20376f
		systype = "posix";
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__cleanup(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_git_sandbox_cleanup();
Packit Service 20376f
Packit Service 20376f
	if (expected_fixture.size) {
Packit Service 20376f
		cl_fixture_cleanup(expected_fixture.ptr);
Packit Service 20376f
		git_buf_free(&expected_fixture);
Packit Service 20376f
	}
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
struct compare_data
Packit Service 20376f
{
Packit Service 20376f
	const char *dirname;
Packit Service 20376f
	const char *autocrlf;
Packit Service 20376f
	const char *attrs;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
static int compare_file(void *payload, git_buf *actual_path)
Packit Service 20376f
{
Packit Service 20376f
	git_buf expected_path = GIT_BUF_INIT;
Packit Service 20376f
	git_buf actual_contents = GIT_BUF_INIT;
Packit Service 20376f
	git_buf expected_contents = GIT_BUF_INIT;
Packit Service 20376f
	struct compare_data *cd = payload;
Packit Service 20376f
	bool failed = true;
Packit Service 20376f
	int cmp_git, cmp_gitattributes;
Packit Service 20376f
	char *basename;
Packit Service 20376f
Packit Service 20376f
	basename = git_path_basename(actual_path->ptr);
Packit Service 20376f
	cmp_git = strcmp(basename, ".git");
Packit Service 20376f
	cmp_gitattributes = strcmp(basename, ".gitattributes");
Packit Service 20376f
Packit Service 20376f
	if (cmp_git == 0 || cmp_gitattributes == 0) {
Packit Service 20376f
		failed = false;
Packit Service 20376f
		goto done;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname, basename));
Packit Service 20376f
Packit Service 20376f
	if (!git_path_isfile(expected_path.ptr) ||
Packit Service 20376f
		!git_path_isfile(actual_path->ptr))
Packit Service 20376f
		goto done;
Packit Service 20376f
Packit Service 20376f
	if (git_futils_readbuffer(&actual_contents, actual_path->ptr) < 0 ||
Packit Service 20376f
		git_futils_readbuffer(&expected_contents, expected_path.ptr) < 0)
Packit Service 20376f
		goto done;
Packit Service 20376f
Packit Service 20376f
	if (actual_contents.size != expected_contents.size)
Packit Service 20376f
		goto done;
Packit Service 20376f
Packit Service 20376f
	if (memcmp(actual_contents.ptr, expected_contents.ptr, expected_contents.size) != 0)
Packit Service 20376f
		goto done;
Packit Service 20376f
Packit Service 20376f
	failed = false;
Packit Service 20376f
Packit Service 20376f
done:
Packit Service 20376f
	if (failed) {
Packit Service 20376f
		git_buf details = GIT_BUF_INIT;
Packit Service 20376f
		git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, attrs={%s}",
Packit Service 20376f
			git_path_basename(actual_path->ptr), systype, cd->autocrlf, cd->attrs);
Packit Service 20376f
		clar__fail(__FILE__, __LINE__,
Packit Service 20376f
			"checked out contents did not match expected", details.ptr, 0);
Packit Service 20376f
		git_buf_free(&details);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	git__free(basename);
Packit Service 20376f
	git_buf_free(&expected_contents);
Packit Service 20376f
	git_buf_free(&actual_contents);
Packit Service 20376f
	git_buf_free(&expected_path);
Packit Service 20376f
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static void test_checkout(const char *autocrlf, const char *attrs)
Packit Service 20376f
{
Packit Service 20376f
	git_buf attrbuf = GIT_BUF_INIT;
Packit Service 20376f
	git_buf expected_dirname = GIT_BUF_INIT;
Packit Service 20376f
	git_buf sandboxname = GIT_BUF_INIT;
Packit Service 20376f
	git_buf reponame = GIT_BUF_INIT;
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	struct compare_data compare_data = { NULL, autocrlf, attrs };
Packit Service 20376f
	const char *c;
Packit Service 20376f
Packit Service 20376f
	git_buf_puts(&reponame, "crlf");
Packit Service 20376f
Packit Service 20376f
	git_buf_puts(&sandboxname, "autocrlf_");
Packit Service 20376f
	git_buf_puts(&sandboxname, autocrlf);
Packit Service 20376f
Packit Service 20376f
	if (*attrs) {
Packit Service 20376f
		git_buf_puts(&sandboxname, ",");
Packit Service 20376f
Packit Service 20376f
		for (c = attrs; *c; c++) {
Packit Service 20376f
			if (*c == ' ')
Packit Service 20376f
				git_buf_putc(&sandboxname, ',');
Packit Service 20376f
			else if (*c == '=')
Packit Service 20376f
				git_buf_putc(&sandboxname, '_');
Packit Service 20376f
			else
Packit Service 20376f
				git_buf_putc(&sandboxname, *c);
Packit Service 20376f
		}
Packit Service 20376f
Packit Service 20376f
		git_buf_printf(&attrbuf, "* %s\n", attrs);
Packit Service 20376f
		cl_git_mkfile("crlf/.gitattributes", attrbuf.ptr);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_string(g_repo, "core.autocrlf", autocrlf);
Packit Service 20376f
Packit Service 20376f
	git_buf_joinpath(&expected_dirname, systype, sandboxname.ptr);
Packit Service 20376f
	git_buf_joinpath(&expected_fixture, "crlf_data", expected_dirname.ptr);
Packit Service 20376f
	cl_fixture_sandbox(expected_fixture.ptr);
Packit Service 20376f
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	compare_data.dirname = sandboxname.ptr;
Packit Service 20376f
	cl_git_pass(git_path_direach(&reponame, 0, compare_file, &compare_data));
Packit Service 20376f
Packit Service 20376f
	cl_fixture_cleanup(expected_fixture.ptr);
Packit Service 20376f
	git_buf_free(&expected_fixture);
Packit Service 20376f
Packit Service 20376f
	git_buf_free(&attrbuf);
Packit Service 20376f
	git_buf_free(&expected_fixture);
Packit Service 20376f
	git_buf_free(&expected_dirname);
Packit Service 20376f
	git_buf_free(&sandboxname);
Packit Service 20376f
	git_buf_free(&reponame);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static void empty_workdir(const char *name)
Packit Service 20376f
{
Packit Service 20376f
	git_vector contents = GIT_VECTOR_INIT;
Packit Service 20376f
	size_t i;
Packit Service 20376f
	const char *fn;
Packit Service 20376f
Packit Service 20376f
	git_path_dirload(&contents, name, 0, 0);
Packit Service 20376f
	git_vector_foreach(&contents, i, fn) {
Packit Service 20376f
		char *basename = git_path_basename(fn);
Packit Service 20376f
		int cmp = strncasecmp(basename, ".git", 4);
Packit Service 20376f
Packit Service 20376f
		git__free(basename);
Packit Service 20376f
Packit Service 20376f
		if (cmp == 0)
Packit Service 20376f
			continue;
Packit Service 20376f
		p_unlink(fn);
Packit Service 20376f
	}
Packit Service 20376f
	git_vector_free_deep(&contents);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__matches_core_git(void)
Packit Service 20376f
{
Packit Service 20376f
	const char *autocrlf[] = { "true", "false", "input", NULL };
Packit Service 20376f
	const char *attrs[] = { "", "-crlf", "-text", "eol=crlf", "eol=lf",
Packit Service 20376f
		"text", "text eol=crlf", "text eol=lf",
Packit Service 20376f
		"text=auto", "text=auto eol=crlf", "text=auto eol=lf", 
Packit Service 20376f
		NULL };
Packit Service 20376f
	const char **a, **b;
Packit Service 20376f
Packit Service 20376f
	for (a = autocrlf; *a; a++) {
Packit Service 20376f
		for (b = attrs; *b; b++) {
Packit Service 20376f
			empty_workdir("crlf");
Packit Service 20376f
			test_checkout(*a, *b);
Packit Service 20376f
		}
Packit Service 20376f
	}
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__detect_crlf_autocrlf_false(void)
Packit Service 20376f
{
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", false);
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
Packit Service 20376f
	check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	const git_index_entry *entry;
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", false);
Packit Service 20376f
Packit Service 20376f
	git_repository_index(&index, g_repo);
Packit Service 20376f
	tick_index(index);
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
Packit Service 20376f
	cl_assert(entry->file_size == strlen(ALL_LF_TEXT_RAW));
Packit Service 20376f
Packit Service 20376f
	cl_assert((entry = git_index_get_bypath(index, "all-crlf", 0)) != NULL);
Packit Service 20376f
	cl_assert(entry->file_size == strlen(ALL_CRLF_TEXT_RAW));
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__detect_crlf_autocrlf_true(void)
Packit Service 20376f
{
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", true);
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
Packit Service 20376f
	check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__detect_crlf_autocrlf_true_utf8(void)
Packit Service 20376f
{
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", true);
Packit Service 20376f
Packit Service 20376f
	git_repository_set_head(g_repo, "refs/heads/master");
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/few-utf8-chars-lf", FEW_UTF8_CRLF_RAW);
Packit Service 20376f
	check_file_contents("./crlf/many-utf8-chars-lf", MANY_UTF8_CRLF_RAW);
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/few-utf8-chars-crlf", FEW_UTF8_CRLF_RAW);
Packit Service 20376f
	check_file_contents("./crlf/many-utf8-chars-crlf", MANY_UTF8_CRLF_RAW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	const git_index_entry *entry;
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", true);
Packit Service 20376f
Packit Service 20376f
	git_repository_index(&index, g_repo);
Packit Service 20376f
	tick_index(index);
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_sz(strlen(ALL_LF_TEXT_AS_CRLF), entry->file_size);
Packit Service 20376f
Packit Service 20376f
	cl_assert((entry = git_index_get_bypath(index, "all-crlf", 0)) != NULL);
Packit Service 20376f
	cl_assert_equal_sz(strlen(ALL_CRLF_TEXT_RAW), entry->file_size);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__with_ident(void)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	const git_index_entry *entry;
Packit Service 20376f
	git_blob *blob;
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("crlf/.gitattributes",
Packit Service 20376f
		"*.txt text\n*.bin binary\n"
Packit Service 20376f
		"*.crlf text eol=crlf\n"
Packit Service 20376f
		"*.lf text eol=lf\n"
Packit Service 20376f
		"*.ident text ident\n"
Packit Service 20376f
		"*.identcrlf ident text eol=crlf\n"
Packit Service 20376f
		"*.identlf ident text eol=lf\n");
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", true);
Packit Service 20376f
Packit Service 20376f
	/* add files with $Id$ */
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("crlf/lf.ident", ALL_LF_TEXT_RAW "\n$Id: initial content$\n");
Packit Service 20376f
	cl_git_mkfile("crlf/crlf.ident", ALL_CRLF_TEXT_RAW "\r\n$Id$\r\n\r\n");
Packit Service 20376f
	cl_git_mkfile("crlf/more1.identlf", "$Id$\n" MORE_LF_TEXT_RAW);
Packit Service 20376f
	cl_git_mkfile("crlf/more2.identcrlf", "\r\n$Id: ?$\r\n" MORE_CRLF_TEXT_RAW);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(index, "lf.ident"));
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(index, "crlf.ident"));
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(index, "more1.identlf"));
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(index, "more2.identcrlf"));
Packit Service 20376f
	cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "Some ident files\n");
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	/* check that blobs have $Id$ */
Packit Service 20376f
Packit Service 20376f
	cl_assert((entry = git_index_get_bypath(index, "lf.ident", 0)));
Packit Service 20376f
	cl_git_pass(git_blob_lookup(&blob, g_repo, &entry->id));
Packit Service 20376f
	cl_assert_equal_s(
Packit Service 20376f
		ALL_LF_TEXT_RAW "\n$Id$\n", git_blob_rawcontent(blob));
Packit Service 20376f
	git_blob_free(blob);
Packit Service 20376f
Packit Service 20376f
	cl_assert((entry = git_index_get_bypath(index, "more2.identcrlf", 0)));
Packit Service 20376f
	cl_git_pass(git_blob_lookup(&blob, g_repo, &entry->id));
Packit Service 20376f
	cl_assert_equal_s(
Packit Service 20376f
		"\n$Id$\n" MORE_CRLF_TEXT_AS_LF, git_blob_rawcontent(blob));
Packit Service 20376f
	git_blob_free(blob);
Packit Service 20376f
Packit Service 20376f
	/* check that filesystem is initially untouched - matching core Git */
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_file(
Packit Service 20376f
		ALL_LF_TEXT_RAW "\n$Id: initial content$\n", 0, "crlf/lf.ident");
Packit Service 20376f
Packit Service 20376f
	/* check that forced checkout rewrites correctly */
Packit Service 20376f
Packit Service 20376f
	p_unlink("crlf/lf.ident");
Packit Service 20376f
	p_unlink("crlf/crlf.ident");
Packit Service 20376f
	p_unlink("crlf/more1.identlf");
Packit Service 20376f
	p_unlink("crlf/more2.identcrlf");
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_file(
Packit Service 20376f
		ALL_LF_TEXT_AS_CRLF
Packit Service 20376f
		"\r\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467 $\r\n",
Packit Service 20376f
		0, "crlf/lf.ident");
Packit Service 20376f
	cl_assert_equal_file(
Packit Service 20376f
		ALL_CRLF_TEXT_RAW
Packit Service 20376f
		"\r\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857 $\r\n\r\n",
Packit Service 20376f
		0, "crlf/crlf.ident");
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_file(
Packit Service 20376f
		"$Id: f7830382dac1f1583422be5530fdfbd26289431b $\n"
Packit Service 20376f
		MORE_LF_TEXT_AS_LF, 0, "crlf/more1.identlf");
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_file(
Packit Service 20376f
		"\r\n$Id: 74677a68413012ce8d7e7cfc3f12603df3a3eac4 $\r\n"
Packit Service 20376f
		MORE_CRLF_TEXT_AS_CRLF, 0, "crlf/more2.identcrlf");
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__autocrlf_false_no_attrs(void)
Packit Service 20376f
{
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", false);
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
Packit Service 20376f
	check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__autocrlf_true_no_attrs(void)
Packit Service 20376f
{
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", true);
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
Packit Service 20376f
	check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__autocrlf_input_no_attrs(void)
Packit Service 20376f
{
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_string(g_repo, "core.autocrlf", "input");
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
Packit Service 20376f
	check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__autocrlf_false_text_auto_attr(void)
Packit Service 20376f
{
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", false);
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	if (GIT_EOL_NATIVE == GIT_EOL_CRLF) {
Packit Service 20376f
		check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
Packit Service 20376f
		check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
Packit Service 20376f
	} else {
Packit Service 20376f
		check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
Packit Service 20376f
		check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
Packit Service 20376f
	}
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__autocrlf_true_text_auto_attr(void)
Packit Service 20376f
{
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", true);
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
Packit Service 20376f
	check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__autocrlf_input_text_auto_attr(void)
Packit Service 20376f
{
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_string(g_repo, "core.autocrlf", "input");
Packit Service 20376f
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
Packit Service 20376f
	check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_checkout_crlf__can_write_empty_file(void)
Packit Service 20376f
{
Packit Service 20376f
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
Packit Service 20376f
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(g_repo, "core.autocrlf", true);
Packit Service 20376f
Packit Service 20376f
	git_repository_set_head(g_repo, "refs/heads/empty-files");
Packit Service 20376f
	git_checkout_head(g_repo, &opts);
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/test1.txt", "");
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/test2.txt", "test2.txt's content\r\n");
Packit Service 20376f
Packit Service 20376f
	check_file_contents("./crlf/test3.txt", "");
Packit Service 20376f
}