{"thread":{"id":"6502","subject":"[PATCH 5/3] merge-one-file: make sure that leading directories exist","startedAt":"2007-01-24T11:27:20Z","lastAt":"2007-01-24T11:27:20Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"32509","messageId":"Pine.LNX.4.63.0701241226360.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6502","inReplyTo":null,"subject":"[PATCH 5/3] merge-one-file: make sure that leading directories exist","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-01-24T11:27:20Z","receivedAt":"2007-01-24T11:27:20Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThis ports half of the reasoning of v0.99~298 to the builtin version.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n---\n\tWhen trying to verify that checkout-index was there for the\n\tsole purpose of setting the modes correctly, I found (thanks\n\tto annotate!) that the leading directories were the\n\tmotivation, not the modes.\n\n merge-file.c              |    8 ++++++++\n t/t6025-merge-one-file.sh |   10 ++++++++++\n 2 files changed, 18 insertions(+), 0 deletions(-)\n\ndiff --git a/merge-file.c b/merge-file.c\nindex ba54c96..b585b69 100644\n--- a/merge-file.c\n+++ b/merge-file.c\n@@ -138,9 +138,17 @@ int remove_from_index(const char *path)\n int update_file(const char *path, void *buffer, unsigned long size,\n \t\tint mode, int update_index)\n {\n+\tint ret;\n+\tchar *p;\n \tif (update_index && remove_from_index(path))\n \t\treturn -1;\n \n+\tp = xstrdup(path);\n+\tret = safe_create_leading_directories(p);\n+\tfree(p);\n+\tif (ret)\n+\t\treturn error(\"Could not create leading path for %s\", path);\n+\n \tif (S_ISLNK(mode)) {\n \t\tchar *target = buffer;\n \t\ttarget[size] = '\\0';\ndiff --git a/t/t6025-merge-one-file.sh b/t/t6025-merge-one-file.sh\nindex 6b79202..0b367af 100644\n--- a/t/t6025-merge-one-file.sh\n+++ b/t/t6025-merge-one-file.sh\n@@ -59,6 +59,16 @@ test_expect_success \"created identically\" \\\n \n test_expect_success \"-> correct file\" \"test z$(cat two) = zone\"\n \n+git-update-index --index-info << EOF\n+10644 $hash_one 2\ta/sub/dir/two\n+10644 $hash_one 3\ta/sub/dir/two\n+EOF\n+\n+test_expect_success \"created identically, in subdir\" \\\n+\t\"git-merge-one-file '' $hash_one $hash_one a/sub/dir/two '' 0644 0644\"\n+\n+test_expect_success \"-> correct file\" \"test z$(cat a/sub/dir/two) = zone\"\n+\n cat one three > thirteen\n hash_13=$(git-hash-object -t blob -w thirteen)\n \n-- \n1.5.0.rc2.gee75e-dirty\n"}]}