git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add test that checkout does not overwrite entries in .git/info/exclude

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Nov 21, 2011, 08:17 UTC
Message-ID
<20111121081701.GA7985@do>
In-Reply-To
<4EC9FC81.3080306@viscovery.net>
On Mon, Nov 21, 2011 at 08:23:45AM +0100, Johannes Sixt wrote:
Show 15 quoted lines
> From: Johannes Sixt <j6t@kdbg.org>
> 
> It is an unintended accident that entries matched by .git/info/exclude are
> considered precious, but entries matched by .gitignore are not. That is,
> 'git checkout' will overwrite untracked files matched by .gitignore, but
> refuses to overwrite files matched by .git/info/exclude.
> 
> It is a lucky accident: it allows the distinction between "untracked but
> precious" and "untracked and garbage". And it is a doubly lucky accident:
> .gitignore entries are meant for files like build products, which usually
> affect all consumers of a repository, whereas .git/info/exclude is
> intended for personal files, which frequently are precious (think of a
> TODO file).
> 
> Add a test that codifies the accident as wanted behavior.

If you want to keep this accident (which is a bug to me), you may want to add the reason: callers to unpack_trees() are supposed to also setup exclude rules in .git/info/exclude before calling unpack_trees(), which they don't.

So .git/info/exclude is entirely dismissed. This patch makes t2023.3 fail. I haven't dug into history to see if this is on purpose though.

-- 8< --
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2a80772..c2fc2ba 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -412,6 +412,8 @@ static int merge_working_tree(struct checkout_opts *opts,
 		topts.dir = xcalloc(1, sizeof(*topts.dir));
 		topts.dir->flags |= DIR_SHOW_IGNORED;
 		topts.dir->exclude_per_dir = ".gitignore";
+		if (!access(git_path("info/exclude"), R_OK))
+			add_excludes_from_file(topts.dir, git_path("info/exclude"));
 		tree = parse_tree_indirect(old->commit ?
 					   old->commit->object.sha1 :
 					   EMPTY_TREE_SHA1_BIN);
-- 8< --
--
Duy
Previous: Nguyen Thai Ngoc DuyNext: Junio C Hamano
Message 12 of 23 in “Bug report - local (and git ignored) file silently removed after checkout”
  1. Bertrand BENOITNov 20, 2011
  2. Junio C HamanoNov 20, 2011
  3. Taylor HedbergNov 20, 2011
  4. Junio C HamanoNov 21, 2011
  5. Add test that checkout does not overwrite entries in .git/info/excludeJohannes Sixt, Nov 21, 2011
  6. Philip OakleyNov 21, 2011
  7. Junio C HamanoNov 21, 2011
  8. Junio C HamanoNov 21, 2011
  9. Nguyen Thai Ngoc DuyNov 21, 2011
  10. Junio C HamanoNov 21, 2011
  11. Nguyen Thai Ngoc DuyNov 23, 2011
  12. Nguyen Thai Ngoc DuyNov 21, 2011
  13. Junio C HamanoNov 21, 2011
  14. Bertrand BENOITNov 21, 2011
  15. Nguyen Thai Ngoc DuyNov 23, 2011
  16. Junio C HamanoNov 23, 2011
  17. Nguyen Thai Ngoc DuyNov 24, 2011
  18. Junio C HamanoNov 24, 2011
  19. Nguyen Thai Ngoc DuyNov 24, 2011
  20. Nguyen Thai Ngoc DuyNov 27, 2011
  21. 1/2 checkout,merge: loosen overwriting untracked file check based on info/excludeNguyễn Thái Ngọc Duy, Nov 27, 2011
  22. 2/2 checkout,merge: disallow overwriting ignored files with --no-overwrite-ignoreNguyễn Thái Ngọc Duy, Nov 27, 2011
  23. Junio C HamanoNov 29, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.