mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-15 05:21:50 +00:00
commit
91c1833af1
@ -131,17 +131,15 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src)
|
||||
for (; next; scan = next + 1, next = memchr(scan, '\n', end - scan)) {
|
||||
size_t copylen = next - scan;
|
||||
|
||||
/* if we find mixed line endings, bail */
|
||||
if (next > start && next[-1] == '\r') {
|
||||
git_buf_free(tgt);
|
||||
return GIT_PASSTHROUGH;
|
||||
}
|
||||
/* if we find mixed line endings, carry on */
|
||||
if (copylen && next[-1] == '\r')
|
||||
copylen--;
|
||||
|
||||
GITERR_CHECK_ALLOC_ADD(&alloclen, copylen, 3);
|
||||
if (git_buf_grow_by(tgt, alloclen) < 0)
|
||||
return -1;
|
||||
|
||||
if (next > scan) {
|
||||
if (copylen) {
|
||||
memcpy(tgt->ptr + tgt->size, scan, copylen);
|
||||
tgt->size += copylen;
|
||||
}
|
||||
|
@ -58,8 +58,7 @@ extern void git_buf_text_unescape(git_buf *buf);
|
||||
/**
|
||||
* Replace all \r\n with \n.
|
||||
*
|
||||
* @return 0 on success, -1 on memory error, GIT_PASSTHROUGH if the
|
||||
* source buffer has mixed line endings.
|
||||
* @return 0 on success, -1 on memory error
|
||||
*/
|
||||
extern int git_buf_text_crlf_to_lf(git_buf *tgt, const git_buf *src);
|
||||
|
||||
|
56
src/crlf.c
56
src/crlf.c
@ -193,28 +193,29 @@ static const char *line_ending(struct crlf_attrs *ca)
|
||||
case GIT_CRLF_CRLF:
|
||||
return "\r\n";
|
||||
|
||||
case GIT_CRLF_GUESS:
|
||||
if (ca->auto_crlf == GIT_AUTO_CRLF_FALSE)
|
||||
return "\n";
|
||||
break;
|
||||
|
||||
case GIT_CRLF_AUTO:
|
||||
case GIT_CRLF_TEXT:
|
||||
case GIT_CRLF_GUESS:
|
||||
break;
|
||||
|
||||
default:
|
||||
goto line_ending_error;
|
||||
}
|
||||
|
||||
switch (ca->eol) {
|
||||
case GIT_EOL_UNSET:
|
||||
return GIT_EOL_NATIVE == GIT_EOL_CRLF ? "\r\n" : "\n";
|
||||
|
||||
case GIT_EOL_CRLF:
|
||||
if (ca->auto_crlf == GIT_AUTO_CRLF_TRUE)
|
||||
return "\r\n";
|
||||
|
||||
case GIT_EOL_LF:
|
||||
else if (ca->auto_crlf == GIT_AUTO_CRLF_INPUT)
|
||||
return "\n";
|
||||
|
||||
default:
|
||||
goto line_ending_error;
|
||||
}
|
||||
else if (ca->eol == GIT_EOL_UNSET)
|
||||
return GIT_EOL_NATIVE == GIT_EOL_CRLF ? "\r\n" : "\n";
|
||||
else if (ca->eol == GIT_EOL_LF)
|
||||
return "\n";
|
||||
else if (ca->eol == GIT_EOL_CRLF)
|
||||
return "\r\n";
|
||||
|
||||
line_ending_error:
|
||||
giterr_set(GITERR_INVALID, "Invalid input to line ending filter");
|
||||
@ -224,16 +225,14 @@ line_ending_error:
|
||||
static int crlf_apply_to_workdir(
|
||||
struct crlf_attrs *ca, git_buf *to, const git_buf *from)
|
||||
{
|
||||
git_buf_text_stats stats;
|
||||
const char *workdir_ending = NULL;
|
||||
bool is_binary;
|
||||
|
||||
/* Empty file? Nothing to do. */
|
||||
if (git_buf_len(from) == 0)
|
||||
return 0;
|
||||
|
||||
/* Don't filter binary files */
|
||||
if (git_buf_text_is_binary(from))
|
||||
return GIT_PASSTHROUGH;
|
||||
|
||||
/* Determine proper line ending */
|
||||
workdir_ending = line_ending(ca);
|
||||
if (!workdir_ending)
|
||||
@ -243,6 +242,29 @@ static int crlf_apply_to_workdir(
|
||||
if (strcmp(workdir_ending, "\r\n") != 0)
|
||||
return GIT_PASSTHROUGH;
|
||||
|
||||
/* If there are no LFs, or all LFs are part of a CRLF, nothing to do */
|
||||
is_binary = git_buf_text_gather_stats(&stats, from, false);
|
||||
|
||||
if (stats.lf == 0 || stats.lf == stats.crlf)
|
||||
return GIT_PASSTHROUGH;
|
||||
|
||||
if (ca->crlf_action == GIT_CRLF_AUTO ||
|
||||
ca->crlf_action == GIT_CRLF_GUESS) {
|
||||
|
||||
/* If we have any existing CR or CRLF line endings, do nothing */
|
||||
if (ca->crlf_action == GIT_CRLF_GUESS &&
|
||||
stats.cr > 0 && stats.crlf > 0)
|
||||
return GIT_PASSTHROUGH;
|
||||
|
||||
/* If we have bare CR characters, do nothing */
|
||||
if (stats.cr != stats.crlf)
|
||||
return GIT_PASSTHROUGH;
|
||||
|
||||
/* Don't filter binary files */
|
||||
if (is_binary)
|
||||
return GIT_PASSTHROUGH;
|
||||
}
|
||||
|
||||
return git_buf_text_lf_to_crlf(to, from);
|
||||
}
|
||||
|
||||
@ -278,7 +300,7 @@ static int crlf_check(
|
||||
return GIT_PASSTHROUGH;
|
||||
|
||||
if (ca.crlf_action == GIT_CRLF_GUESS ||
|
||||
(ca.crlf_action == GIT_CRLF_AUTO &&
|
||||
((ca.crlf_action == GIT_CRLF_AUTO || ca.crlf_action == GIT_CRLF_TEXT) &&
|
||||
git_filter_source_mode(src) == GIT_FILTER_SMUDGE)) {
|
||||
|
||||
error = git_repository__cvar(
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "clar_libgit2.h"
|
||||
#include "checkout_helpers.h"
|
||||
#include "../filter/crlf.h"
|
||||
#include "fileops.h"
|
||||
|
||||
#include "git2/checkout.h"
|
||||
#include "repository.h"
|
||||
@ -9,14 +10,169 @@
|
||||
|
||||
static git_repository *g_repo;
|
||||
|
||||
static const char *systype;
|
||||
static git_buf expected_fixture = GIT_BUF_INIT;
|
||||
|
||||
void test_checkout_crlf__initialize(void)
|
||||
{
|
||||
g_repo = cl_git_sandbox_init("crlf");
|
||||
|
||||
if (GIT_EOL_NATIVE == GIT_EOL_CRLF)
|
||||
systype = "windows";
|
||||
else
|
||||
systype = "posix";
|
||||
}
|
||||
|
||||
void test_checkout_crlf__cleanup(void)
|
||||
{
|
||||
cl_git_sandbox_cleanup();
|
||||
|
||||
if (expected_fixture.size) {
|
||||
cl_fixture_cleanup(expected_fixture.ptr);
|
||||
git_buf_free(&expected_fixture);
|
||||
}
|
||||
}
|
||||
|
||||
struct compare_data
|
||||
{
|
||||
const char *dirname;
|
||||
const char *autocrlf;
|
||||
const char *attrs;
|
||||
};
|
||||
|
||||
static int compare_file(void *payload, git_buf *actual_path)
|
||||
{
|
||||
git_buf expected_path = GIT_BUF_INIT;
|
||||
git_buf actual_contents = GIT_BUF_INIT;
|
||||
git_buf expected_contents = GIT_BUF_INIT;
|
||||
struct compare_data *cd = payload;
|
||||
bool failed = true;
|
||||
|
||||
if (strcmp(git_path_basename(actual_path->ptr), ".git") == 0 ||
|
||||
strcmp(git_path_basename(actual_path->ptr), ".gitattributes") == 0) {
|
||||
failed = false;
|
||||
goto done;
|
||||
}
|
||||
|
||||
cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname,
|
||||
git_path_basename(actual_path->ptr)));
|
||||
|
||||
if (!git_path_isfile(expected_path.ptr) ||
|
||||
!git_path_isfile(actual_path->ptr))
|
||||
goto done;
|
||||
|
||||
if (git_futils_readbuffer(&actual_contents, actual_path->ptr) < 0 ||
|
||||
git_futils_readbuffer(&expected_contents, expected_path.ptr) < 0)
|
||||
goto done;
|
||||
|
||||
if (actual_contents.size != expected_contents.size)
|
||||
goto done;
|
||||
|
||||
if (memcmp(actual_contents.ptr, expected_contents.ptr, expected_contents.size) != 0)
|
||||
goto done;
|
||||
|
||||
failed = false;
|
||||
|
||||
done:
|
||||
if (failed) {
|
||||
git_buf details = GIT_BUF_INIT;
|
||||
git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, attrs={%s}",
|
||||
git_path_basename(actual_path->ptr), systype, cd->autocrlf, cd->attrs);
|
||||
clar__fail(__FILE__, __LINE__,
|
||||
"checked out contents did not match expected", details.ptr, 0);
|
||||
git_buf_free(&details);
|
||||
}
|
||||
|
||||
git_buf_free(&expected_contents);
|
||||
git_buf_free(&actual_contents);
|
||||
git_buf_free(&expected_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_checkout(const char *autocrlf, const char *attrs)
|
||||
{
|
||||
git_buf attrbuf = GIT_BUF_INIT;
|
||||
git_buf expected_dirname = GIT_BUF_INIT;
|
||||
git_buf sandboxname = GIT_BUF_INIT;
|
||||
git_buf reponame = GIT_BUF_INIT;
|
||||
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
|
||||
struct compare_data compare_data = { NULL, autocrlf, attrs };
|
||||
const char *c;
|
||||
|
||||
git_buf_puts(&reponame, "crlf");
|
||||
|
||||
git_buf_puts(&sandboxname, "autocrlf_");
|
||||
git_buf_puts(&sandboxname, autocrlf);
|
||||
|
||||
if (*attrs) {
|
||||
git_buf_puts(&sandboxname, ",");
|
||||
|
||||
for (c = attrs; *c; c++) {
|
||||
if (*c == ' ')
|
||||
git_buf_putc(&sandboxname, ',');
|
||||
else if (*c == '=')
|
||||
git_buf_putc(&sandboxname, '_');
|
||||
else
|
||||
git_buf_putc(&sandboxname, *c);
|
||||
}
|
||||
|
||||
git_buf_printf(&attrbuf, "* %s\n", attrs);
|
||||
cl_git_mkfile("crlf/.gitattributes", attrbuf.ptr);
|
||||
}
|
||||
|
||||
cl_repo_set_string(g_repo, "core.autocrlf", autocrlf);
|
||||
|
||||
git_buf_joinpath(&expected_dirname, systype, sandboxname.ptr);
|
||||
git_buf_joinpath(&expected_fixture, "crlf_data", expected_dirname.ptr);
|
||||
cl_fixture_sandbox(expected_fixture.ptr);
|
||||
|
||||
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
|
||||
git_checkout_head(g_repo, &opts);
|
||||
|
||||
compare_data.dirname = sandboxname.ptr;
|
||||
cl_git_pass(git_path_direach(&reponame, 0, compare_file, &compare_data));
|
||||
|
||||
cl_fixture_cleanup(expected_fixture.ptr);
|
||||
git_buf_free(&expected_fixture);
|
||||
|
||||
git_buf_free(&attrbuf);
|
||||
git_buf_free(&expected_fixture);
|
||||
git_buf_free(&expected_dirname);
|
||||
git_buf_free(&sandboxname);
|
||||
git_buf_free(&reponame);
|
||||
}
|
||||
|
||||
static void empty_workdir(const char *name)
|
||||
{
|
||||
git_vector contents = GIT_VECTOR_INIT;
|
||||
size_t i;
|
||||
const char *fn;
|
||||
|
||||
git_path_dirload(&contents, name, 0, 0);
|
||||
git_vector_foreach(&contents, i, fn) {
|
||||
if (strncasecmp(git_path_basename(fn), ".git", 4) == 0)
|
||||
continue;
|
||||
p_unlink(fn);
|
||||
}
|
||||
git_vector_free_deep(&contents);
|
||||
}
|
||||
|
||||
void test_checkout_crlf__matches_core_git(void)
|
||||
{
|
||||
const char *autocrlf[] = { "true", "false", "input", NULL };
|
||||
const char *attrs[] = { "", "-crlf", "-text", "eol=crlf", "eol=lf",
|
||||
"text", "text eol=crlf", "text eol=lf",
|
||||
"text=auto", "text=auto eol=crlf", "text=auto eol=lf",
|
||||
NULL };
|
||||
const char **a, **b;
|
||||
|
||||
for (a = autocrlf; *a; a++) {
|
||||
for (b = attrs; *b; b++) {
|
||||
empty_workdir("crlf");
|
||||
test_checkout(*a, *b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_checkout_crlf__detect_crlf_autocrlf_false(void)
|
||||
@ -64,47 +220,7 @@ void test_checkout_crlf__detect_crlf_autocrlf_true(void)
|
||||
|
||||
git_checkout_head(g_repo, &opts);
|
||||
|
||||
if (GIT_EOL_NATIVE == GIT_EOL_LF)
|
||||
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
|
||||
else
|
||||
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
|
||||
|
||||
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
|
||||
}
|
||||
|
||||
void test_checkout_crlf__more_lf_autocrlf_true(void)
|
||||
{
|
||||
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
|
||||
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
|
||||
|
||||
cl_repo_set_bool(g_repo, "core.autocrlf", true);
|
||||
|
||||
git_checkout_head(g_repo, &opts);
|
||||
|
||||
check_file_contents("./crlf/more-lf", MORE_LF_TEXT_RAW);
|
||||
}
|
||||
|
||||
void test_checkout_crlf__more_crlf_autocrlf_true(void)
|
||||
{
|
||||
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
|
||||
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
|
||||
|
||||
cl_repo_set_bool(g_repo, "core.autocrlf", true);
|
||||
|
||||
git_checkout_head(g_repo, &opts);
|
||||
|
||||
check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_RAW);
|
||||
}
|
||||
|
||||
void test_checkout_crlf__all_crlf_autocrlf_true(void)
|
||||
{
|
||||
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
|
||||
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
|
||||
|
||||
cl_repo_set_bool(g_repo, "core.autocrlf", true);
|
||||
|
||||
git_checkout_head(g_repo, &opts);
|
||||
|
||||
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
|
||||
}
|
||||
|
||||
@ -115,22 +231,14 @@ void test_checkout_crlf__detect_crlf_autocrlf_true_utf8(void)
|
||||
|
||||
cl_repo_set_bool(g_repo, "core.autocrlf", true);
|
||||
|
||||
git_repository_set_head(g_repo, "refs/heads/utf8");
|
||||
git_repository_set_head(g_repo, "refs/heads/master");
|
||||
git_checkout_head(g_repo, &opts);
|
||||
|
||||
if (GIT_EOL_NATIVE == GIT_EOL_LF)
|
||||
{
|
||||
check_file_contents("./crlf/few-utf8-chars-lf.txt", FEW_UTF8_LF_RAW);
|
||||
check_file_contents("./crlf/many-utf8-chars-lf.txt", MANY_UTF8_LF_RAW);
|
||||
}
|
||||
else
|
||||
{
|
||||
check_file_contents("./crlf/few-utf8-chars-lf.txt", FEW_UTF8_CRLF_RAW);
|
||||
check_file_contents("./crlf/many-utf8-chars-lf.txt", MANY_UTF8_CRLF_RAW);
|
||||
}
|
||||
check_file_contents("./crlf/few-utf8-chars-lf", FEW_UTF8_CRLF_RAW);
|
||||
check_file_contents("./crlf/many-utf8-chars-lf", MANY_UTF8_CRLF_RAW);
|
||||
|
||||
check_file_contents("./crlf/few-utf8-chars-crlf.txt", FEW_UTF8_CRLF_RAW);
|
||||
check_file_contents("./crlf/many-utf8-chars-crlf.txt", MANY_UTF8_CRLF_RAW);
|
||||
check_file_contents("./crlf/few-utf8-chars-crlf", FEW_UTF8_CRLF_RAW);
|
||||
check_file_contents("./crlf/many-utf8-chars-crlf", MANY_UTF8_CRLF_RAW);
|
||||
}
|
||||
|
||||
void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
|
||||
@ -149,9 +257,6 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
|
||||
|
||||
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
|
||||
|
||||
if (GIT_EOL_NATIVE == GIT_EOL_LF)
|
||||
cl_assert_equal_sz(strlen(ALL_LF_TEXT_RAW), entry->file_size);
|
||||
else
|
||||
cl_assert_equal_sz(strlen(ALL_LF_TEXT_AS_CRLF), entry->file_size);
|
||||
|
||||
cl_assert((entry = git_index_get_bypath(index, "all-crlf", 0)) != NULL);
|
||||
@ -221,16 +326,6 @@ void test_checkout_crlf__with_ident(void)
|
||||
|
||||
git_checkout_head(g_repo, &opts);
|
||||
|
||||
if (GIT_EOL_NATIVE == GIT_EOL_LF) {
|
||||
cl_assert_equal_file(
|
||||
ALL_LF_TEXT_RAW
|
||||
"\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467 $\n",
|
||||
0, "crlf/lf.ident");
|
||||
cl_assert_equal_file(
|
||||
ALL_CRLF_TEXT_AS_LF
|
||||
"\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857 $\n\n",
|
||||
0, "crlf/crlf.ident");
|
||||
} else {
|
||||
cl_assert_equal_file(
|
||||
ALL_LF_TEXT_AS_CRLF
|
||||
"\r\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467 $\r\n",
|
||||
@ -239,7 +334,6 @@ void test_checkout_crlf__with_ident(void)
|
||||
ALL_CRLF_TEXT_RAW
|
||||
"\r\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857 $\r\n\r\n",
|
||||
0, "crlf/crlf.ident");
|
||||
}
|
||||
|
||||
cl_assert_equal_file(
|
||||
"$Id: f7830382dac1f1583422be5530fdfbd26289431b $\n"
|
||||
@ -274,13 +368,8 @@ void test_checkout_crlf__autocrlf_true_no_attrs(void)
|
||||
|
||||
git_checkout_head(g_repo, &opts);
|
||||
|
||||
if (GIT_EOL_NATIVE == GIT_EOL_CRLF) {
|
||||
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
|
||||
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
|
||||
} else {
|
||||
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
|
||||
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
|
||||
}
|
||||
}
|
||||
|
||||
void test_checkout_crlf__autocrlf_input_no_attrs(void)
|
||||
@ -327,13 +416,8 @@ void test_checkout_crlf__autocrlf_true_text_auto_attr(void)
|
||||
|
||||
git_checkout_head(g_repo, &opts);
|
||||
|
||||
if (GIT_EOL_NATIVE == GIT_EOL_CRLF) {
|
||||
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
|
||||
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
|
||||
} else {
|
||||
check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
|
||||
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
|
||||
}
|
||||
}
|
||||
|
||||
void test_checkout_crlf__autocrlf_input_text_auto_attr(void)
|
||||
@ -363,9 +447,6 @@ void test_checkout_crlf__can_write_empty_file(void)
|
||||
|
||||
check_file_contents("./crlf/test1.txt", "");
|
||||
|
||||
if (GIT_EOL_NATIVE == GIT_EOL_LF)
|
||||
check_file_contents("./crlf/test2.txt", "test2.txt's content\n");
|
||||
else
|
||||
check_file_contents("./crlf/test2.txt", "test2.txt's content\r\n");
|
||||
|
||||
check_file_contents("./crlf/test3.txt", "");
|
||||
|
@ -20,6 +20,19 @@ fixture_path(const char *base, const char *fixture_name)
|
||||
return _path;
|
||||
}
|
||||
|
||||
static const char *
|
||||
fixture_basename(const char *fixture_name)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
for (p = fixture_name; *p; p++) {
|
||||
if (p[0] == '/' && p[1] && p[1] != '/')
|
||||
fixture_name = p+1;
|
||||
}
|
||||
|
||||
return fixture_name;
|
||||
}
|
||||
|
||||
#ifdef CLAR_FIXTURE_PATH
|
||||
const char *cl_fixture(const char *fixture_name)
|
||||
{
|
||||
@ -33,6 +46,6 @@ void cl_fixture_sandbox(const char *fixture_name)
|
||||
|
||||
void cl_fixture_cleanup(const char *fixture_name)
|
||||
{
|
||||
fs_rm(fixture_path(_clar_path, fixture_name));
|
||||
fs_rm(fixture_path(_clar_path, fixture_basename(fixture_name)));
|
||||
}
|
||||
#endif
|
||||
|
@ -1054,14 +1054,20 @@ void test_core_buffer__lf_and_crlf_conversions(void)
|
||||
|
||||
git_buf_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
|
||||
|
||||
cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
check_buf("crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n", tgt);
|
||||
|
||||
git_buf_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
|
||||
|
||||
cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
|
||||
check_buf("crlf\ncrlf\ncrlf\ncrlf\n", tgt);
|
||||
|
||||
git_buf_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
|
||||
|
||||
cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
check_buf("\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf", tgt);
|
||||
|
||||
git_buf_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
|
||||
|
||||
cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
|
||||
check_buf("\ncrlf\ncrlf\ncrlf\ncrlf\ncrlf", tgt);
|
||||
@ -1070,7 +1076,11 @@ void test_core_buffer__lf_and_crlf_conversions(void)
|
||||
|
||||
git_buf_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
|
||||
|
||||
cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
check_buf("\r\nlf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\ncrlf\r\n", tgt);
|
||||
|
||||
git_buf_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
|
||||
|
||||
cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
|
||||
check_buf("\nlf\nlf\ncrlf\nlf\nlf\ncrlf\n", tgt);
|
||||
|
||||
@ -1078,7 +1088,9 @@ void test_core_buffer__lf_and_crlf_conversions(void)
|
||||
|
||||
git_buf_sets(&src, "\ncrlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf");
|
||||
|
||||
cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
check_buf("\r\ncrlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf", tgt);
|
||||
|
||||
cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
|
||||
check_buf("\ncrlf\ncrlf\nlf\ncrlf\ncrlf", tgt);
|
||||
|
||||
@ -1086,7 +1098,11 @@ void test_core_buffer__lf_and_crlf_conversions(void)
|
||||
|
||||
git_buf_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
|
||||
|
||||
cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
check_buf("\rcrlf\r\nlf\r\nlf\r\ncr\rcrlf\r\nlf\r\ncr\r", tgt);
|
||||
|
||||
git_buf_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
|
||||
|
||||
cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
|
||||
check_buf("\rcrlf\nlf\nlf\ncr\rcrlf\nlf\ncr\r", tgt);
|
||||
|
||||
@ -1102,7 +1118,9 @@ void test_core_buffer__lf_and_crlf_conversions(void)
|
||||
/* blob correspondence tests */
|
||||
|
||||
git_buf_sets(&src, ALL_CRLF_TEXT_RAW);
|
||||
cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
check_buf(ALL_CRLF_TEXT_AS_CRLF, tgt);
|
||||
git_buf_sets(&src, ALL_CRLF_TEXT_RAW);
|
||||
cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
|
||||
check_buf(ALL_CRLF_TEXT_AS_LF, tgt);
|
||||
git_buf_free(&src);
|
||||
@ -1111,20 +1129,25 @@ void test_core_buffer__lf_and_crlf_conversions(void)
|
||||
git_buf_sets(&src, ALL_LF_TEXT_RAW);
|
||||
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
check_buf(ALL_LF_TEXT_AS_CRLF, tgt);
|
||||
git_buf_sets(&src, ALL_LF_TEXT_RAW);
|
||||
cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
|
||||
check_buf(ALL_LF_TEXT_AS_LF, tgt);
|
||||
git_buf_free(&src);
|
||||
git_buf_free(&tgt);
|
||||
|
||||
git_buf_sets(&src, MORE_CRLF_TEXT_RAW);
|
||||
cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
check_buf(MORE_CRLF_TEXT_AS_CRLF, tgt);
|
||||
git_buf_sets(&src, MORE_CRLF_TEXT_RAW);
|
||||
cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
|
||||
check_buf(MORE_CRLF_TEXT_AS_LF, tgt);
|
||||
git_buf_free(&src);
|
||||
git_buf_free(&tgt);
|
||||
|
||||
git_buf_sets(&src, MORE_LF_TEXT_RAW);
|
||||
cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
|
||||
check_buf(MORE_LF_TEXT_AS_CRLF, tgt);
|
||||
git_buf_sets(&src, MORE_LF_TEXT_RAW);
|
||||
cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
|
||||
check_buf(MORE_LF_TEXT_AS_LF, tgt);
|
||||
git_buf_free(&src);
|
||||
|
@ -38,11 +38,7 @@ void test_filter_crlf__to_worktree(void)
|
||||
|
||||
cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
|
||||
|
||||
#ifdef GIT_WIN32
|
||||
cl_assert_equal_s("Some text\r\nRight here\r\n", out.ptr);
|
||||
#else
|
||||
cl_assert_equal_s("Some text\nRight here\n", out.ptr);
|
||||
#endif
|
||||
|
||||
git_filter_list_free(fl);
|
||||
git_buf_free(&out);
|
||||
|
73
tests/generate_crlf.sh
Normal file
73
tests/generate_crlf.sh
Normal file
@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" == "" -o "$2" == "" ]; then
|
||||
echo "usage: $0 crlfrepo directory [tempdir]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
input=$1
|
||||
output=$2
|
||||
tempdir=$3
|
||||
|
||||
set -u
|
||||
|
||||
create_repo() {
|
||||
local input=$1
|
||||
local output=$2
|
||||
local tempdir=$3
|
||||
local systype=$4
|
||||
local autocrlf=$5
|
||||
local attr=$6
|
||||
|
||||
local worktree="${output}/${systype}/autocrlf_${autocrlf}"
|
||||
|
||||
if [ "$attr" != "" ]; then
|
||||
local attrdir=`echo $attr | sed -e "s/ /,/g" | sed -e "s/=/_/g"`
|
||||
worktree="${worktree},${attrdir}"
|
||||
fi
|
||||
|
||||
if [ "$tempdir" = "" ]; then
|
||||
local gitdir="${worktree}/.git"
|
||||
else
|
||||
local gitdir="${tempdir}/generate_crlf_${RANDOM}"
|
||||
fi
|
||||
|
||||
echo "Creating ${worktree}"
|
||||
mkdir -p "${worktree}"
|
||||
|
||||
git clone --no-checkout --quiet --bare "${input}/.gitted" "${gitdir}"
|
||||
git --work-tree="${worktree}" --git-dir="${gitdir}" config core.autocrlf ${autocrlf}
|
||||
|
||||
if [ "$attr" != "" ]; then
|
||||
echo "* ${attr}" >> "${worktree}/.gitattributes"
|
||||
fi
|
||||
|
||||
git --work-tree="${worktree}" --git-dir="${gitdir}" checkout HEAD
|
||||
|
||||
if [ "$attr" != "" ]; then
|
||||
rm "${worktree}/.gitattributes"
|
||||
fi
|
||||
|
||||
if [ "$tempdir" != "" ]; then
|
||||
rm -rf "${gitdir}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ `uname -s` == MINGW* ]]; then
|
||||
systype="windows"
|
||||
else
|
||||
systype="posix"
|
||||
fi
|
||||
|
||||
for autocrlf in true false input; do
|
||||
for attr in "" text text=auto -text crlf -crlf eol=lf eol=crlf \
|
||||
"text eol=lf" "text eol=crlf" \
|
||||
"text=auto eol=lf" "text=auto eol=crlf"; do
|
||||
|
||||
create_repo "${input}" "${output}" "${tempdir}" \
|
||||
"${systype}" "${autocrlf}" "${attr}"
|
||||
done
|
||||
done
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/.gitattributes
vendored
Normal file
BIN
tests/resources/crlf_data/.gitattributes
vendored
Normal file
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,-crlf/all-crlf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,-crlf/all-crlf
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,-crlf/all-lf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,-crlf/all-lf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,-crlf/mixed-lf-cr
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,-crlf/mixed-lf-cr
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,-crlf/more-crlf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,-crlf/more-crlf
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,-crlf/more-lf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,-crlf/more-lf
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,-text/all-crlf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,-text/all-crlf
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,-text/all-lf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,-text/all-lf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,-text/mixed-lf-cr
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,-text/mixed-lf-cr
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,-text/more-crlf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,-text/more-crlf
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,-text/more-lf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,-text/more-lf
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,crlf/all-crlf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,crlf/all-crlf
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,crlf/all-lf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,crlf/all-lf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,crlf/mixed-lf-cr
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,crlf/mixed-lf-cr
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,crlf/more-crlf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,crlf/more-crlf
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,crlf/more-lf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,crlf/more-lf
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,eol_crlf/all-crlf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,eol_crlf/all-crlf
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/crlf_data/posix/autocrlf_false,eol_crlf/all-lf
Normal file
BIN
tests/resources/crlf_data/posix/autocrlf_false,eol_crlf/all-lf
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user