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

[PATCH] checkout_entry: only try to create directories when no file existed there

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 8, 2007, 21:00 UTC
Message-ID
<Pine.LNX.4.64.0708082200240.14781@racer.site>

It is obvious that we do not have to create directories when the file we want to check out already existed.

Besides, it fixes the obscure use case, where you want to track a file which is _outside_ of your working tree, by creating a symbolic link to the directory it lives in, and adding the file with something like "git add symlink/file". Without this patch, "git checkout symlink/file" would actually _replace_ "symlink" by a directory of the same name.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 entry.c                     |    8 +++++---
 t/t2007-checkout-symlink.sh |   11 +++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/entry.c b/entry.c
index 0625112..eacdba2 100644
--- a/entry.c
+++ b/entry.c
@@ -223,8 +223,10 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
 				return error("%s is a directory", path);
 			remove_subtree(path);
 		}
-	} else if (state->not_new)
-		return 0;
-	create_directories(path, state);
+	} else {
+		if (state->not_new)
+			return 0;
+		create_directories(path, state);
+	}
 	return write_entry(ce, path, state, 0);
 }
diff --git a/t/t2007-checkout-symlink.sh b/t/t2007-checkout-symlink.sh
index 0526fce..02224eb 100755
--- a/t/t2007-checkout-symlink.sh
+++ b/t/t2007-checkout-symlink.sh
@@ -47,4 +47,15 @@ test_expect_success 'switch from dir to symlink' '
 
 '
 
+test_expect_success 'checkout does not replace symlink/file with dir/file' '
+	mkdir 123 &&
+	ln -s 123 abc &&
+	echo 1 > abc/1 &&
+	echo 2 > abc/2 &&
+	echo 3 > abc/3 &&
+	git add abc/? &&
+	echo 0 > abc/3 &&
+	git checkout abc/3 &&
+	test -h abc
+'
 test_done
-- 
1.5.3.rc4.26.g782e
Next: Junio C Hamano
Message 1 of 6 in “checkout_entry: only try to create directories when no file existed there”
  1. checkout_entry: only try to create directories when no file existed thereJohannes Schindelin, Aug 8, 2007
  2. Junio C HamanoAug 8, 2007
  3. Johannes SchindelinAug 8, 2007
  4. Junio C HamanoAug 8, 2007
  5. Johannes SchindelinAug 8, 2007
  6. David KastrupAug 8, 2007

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.