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

[PATCH 5/3] merge-one-file: make sure that leading directories exist

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 24, 2007, 11:27 UTC
Message-ID
<Pine.LNX.4.63.0701241226360.22628@wbgn013.biozentrum.uni-wuerzburg.de>
This ports half of the reasoning of v0.99~298 to the builtin version.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	When trying to verify that checkout-index was there for the
	sole purpose of setting the modes correctly, I found (thanks
	to annotate!) that the leading directories were the
	motivation, not the modes.
 merge-file.c              |    8 ++++++++
 t/t6025-merge-one-file.sh |   10 ++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/merge-file.c b/merge-file.c
index ba54c96..b585b69 100644
--- a/merge-file.c
+++ b/merge-file.c
@@ -138,9 +138,17 @@ int remove_from_index(const char *path)
 int update_file(const char *path, void *buffer, unsigned long size,
 		int mode, int update_index)
 {
+	int ret;
+	char *p;
 	if (update_index && remove_from_index(path))
 		return -1;
 
+	p = xstrdup(path);
+	ret = safe_create_leading_directories(p);
+	free(p);
+	if (ret)
+		return error("Could not create leading path for %s", path);
+
 	if (S_ISLNK(mode)) {
 		char *target = buffer;
 		target[size] = '\0';
diff --git a/t/t6025-merge-one-file.sh b/t/t6025-merge-one-file.sh
index 6b79202..0b367af 100644
--- a/t/t6025-merge-one-file.sh
+++ b/t/t6025-merge-one-file.sh
@@ -59,6 +59,16 @@ test_expect_success "created identically" \
 
 test_expect_success "-> correct file" "test z$(cat two) = zone"
 
+git-update-index --index-info << EOF
+10644 $hash_one 2	a/sub/dir/two
+10644 $hash_one 3	a/sub/dir/two
+EOF
+
+test_expect_success "created identically, in subdir" \
+	"git-merge-one-file '' $hash_one $hash_one a/sub/dir/two '' 0644 0644"
+
+test_expect_success "-> correct file" "test z$(cat a/sub/dir/two) = zone"
+
 cat one three > thirteen
 hash_13=$(git-hash-object -t blob -w thirteen)
 
-- 
1.5.0.rc2.gee75e-dirty
Message 1 of 1 in “merge-one-file: make sure that leading directories exist”
  1. 5/3 merge-one-file: make sure that leading directories existJohannes Schindelin, Jan 24, 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.