Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Unable to force checkout a modified working tree file that differs only in the type of line endings

Aberta
#7,158 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
42/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
c, git
Domínio
tooling

Direção de pesquisa

Comece em src/libgit2/checkout.c, em checkout_is_workdir_modified, e inspecione como checkout_action_with_wd lida com arquivos filtrados da árvore de trabalho. Reproduza a falha com o ponto de teste checkout::crlf, incluindo checkout::crlf::with_ident, e rastreie as comparações de OID existentes. Está concluído quando um checkout forçado substitui um arquivo modificado por CRLF pelo conteúdo de destino sem causar regressões ou falhas esporádicas nos testes.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Scenario: A file is stored in the repository using LF line endings and checked out in the working tree with LF line endings. If the working tree file then has its line endings changed to CRLF, a force checkout of the file does not replace the content, and the file remains modified.

Here is a test point that fails:

void test_checkout_crlf__filtered_working_tree_file_equals_target(void)
{
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;

	cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");

	if (GIT_EOL_NATIVE == GIT_EOL_CRLF) {
		cl_git_mkfile("./crlf/all-lf", ALL_LF_TEXT_AS_LF);
		cl_git_mkfile("./crlf/all-crlf", ALL_CRLF_TEXT_AS_LF);
	} else {
		cl_git_mkfile("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
		cl_git_mkfile("./crlf/all-crlf", ALL_CRLF_TEXT_AS_LF);
	}

	cl_git_pass(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);
	}
}

I debugged this and found that checkout_is_workdir_modified compares the base/target oid with the FILTERED oid of the working tree file. As the filtered version would have the CRLF line endings switched to LF line endings, checkout_is_workdir_modified returns false.

I tried to augment is_workdir_base_or_new to also compare the oid of the actual file on disk computed with git_odb__hashfile, but another test point checkout::crlf::with_ident then (sporadically!) fails. Probably a performance issue too.

Checkout logic looks quite complicated and I wonder if the cases in checkout_action_with_wd need splitting out further.

Linguagem predominante
C
Estrelas
10.6k
Forks
2.7k
Métricas de merge de PRs
Nenhum PR com merge em 30d

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de libgit2/libgit2

Todas as issues de libgit2/libgit2

Issues semelhantes

Mais issues de C

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.