Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#7,158 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
c, git
Ambito
tooling

Direzione di ricerca

Inizia in src/libgit2/checkout.c, in corrispondenza di checkout_is_workdir_modified, e analizza come checkout_action_with_wd gestisce i file filtrati dell’albero di lavoro. Riproduci il problema con il test point checkout::crlf, incluso checkout::crlf::with_ident, e segui i confronti OID esistenti. Il lavoro è completo quando un checkout forzato sostituisce un file modificato da CRLF con il contenuto di destinazione senza causare regressioni o fallimenti sporadici dei test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C
Stelle
10.6k
Fork
2.7k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di libgit2/libgit2

Tutte le issue di libgit2/libgit2

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.