[PATCH 5/3] merge-one-file: make sure that leading directories exist
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