Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: [PATCH v2] merge-file: correctly open files when in a subdir

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:03:47

Aleksander Boruch-Gruszecki [off-list ref]
writes:
run_setup_gently() is called before merge-file. This may result in changing
current working directory, which wasn't taken into account when opening a file
for writing.

Fix by prepending the passed prefix. Previous var is left so that error
messages keep refering to the file from the user's working directory
perspective.

Signed-off-by: Aleksander Boruch-Gruszecki
    [off-list ref]
Please don't line wrap the footer.
---
 builtin/merge-file.c  | 3 ++-
 t/t6023-merge-file.sh | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
This patch does not apply.
quoted hunk
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 844f84f..232b768 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -90,7 +90,8 @@ int cmd_merge_file(int argc, const char **argv,
const char *prefix)
Please do not line-wrap the patch, either.
     if (ret >= 0) {
The original has a single tab at the beginning of this line to
indent, not four spaces.
quoted hunk
         const char *filename = argv[0];
-        FILE *f = to_stdout ? stdout : fopen(filename, "wb");
+        const char *fpath = prefix_filename(prefix, prefixlen, argv[0]);
+        FILE *f = to_stdout ? stdout : fopen(fpath, "wb");

         if (!f)
             ret = error("Could not open %s for writing", filename);
diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh
index 3758961..fdd104c 100755
--- a/t/t6023-merge-file.sh
+++ b/t/t6023-merge-file.sh
@@ -72,6 +72,12 @@ test_expect_success 'works in subdirectory' '
     ( cd dir && git merge-file a.txt o.txt b.txt )
 '

+mkdir -p dir/deep
+cp new1.txt orig.txt new2.txt dir/deep
+test_expect_success 'accounts for subdirectory when writing' '
+    (cd dir && git merge-file deep/new1.txt deep/orig.txt deep/new2.txt)
+'
Interesting.  Makes us wonder why the one before this new one you
added did not catch the issue, doesn't it?
+
 cp new1.txt test.txt
 test_expect_success "merge without conflict (--quiet)" \
     "git merge-file --quiet test.txt orig.txt new2.txt"
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help