Git development
 help / color / mirror / Atom feed
* [PATCH] checkout_entry: only try to create directories when no file existed there
@ 2007-08-08 21:00 Johannes Schindelin
  2007-08-08 21:17 ` Junio C Hamano
  2007-08-08 21:27 ` David Kastrup
  0 siblings, 2 replies; 6+ messages in thread
From: Johannes Schindelin @ 2007-08-08 21:00 UTC (permalink / raw)
  To: gitster, git


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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-08-08 22:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-08 21:00 [PATCH] checkout_entry: only try to create directories when no file existed there Johannes Schindelin
2007-08-08 21:17 ` Junio C Hamano
2007-08-08 21:42   ` Johannes Schindelin
2007-08-08 22:40     ` Junio C Hamano
2007-08-08 22:54       ` Johannes Schindelin
2007-08-08 21:27 ` David Kastrup

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox