merge-file: correctly open files when in a subdir

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 referring to the file from the user's working directory perspective. Signed-off-by: Aleksander Boruch-Gruszecki <aleksander.boruchgruszecki@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Aleksander Boruch-Gruszecki committed Feb 8, 2015 at 17:53 UTC 204a8ffe67d2b789a34a14a06618a24756f7d9a9
2 files changed +4 -2
builtin/merge-file.c
+2 -1
@@ -90,7 +90,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
90
91 if (ret >= 0) {
92 const char *filename = argv[0];
93 - FILE *f = to_stdout ? stdout : fopen(filename, "wb");
93 + const char *fpath = prefix_filename(prefix, prefixlen, argv[0]);
94 + FILE *f = to_stdout ? stdout : fopen(fpath, "wb");
95
96 if (!f)
97 ret = error("Could not open %s for writing", filename);
t/t6023-merge-file.sh
+2 -1
@@ -69,7 +69,8 @@ test_expect_success 'works in subdirectory' '
69 cp new1.txt dir/a.txt &&
70 cp orig.txt dir/o.txt &&
71 cp new2.txt dir/b.txt &&
72 - ( cd dir && git merge-file a.txt o.txt b.txt )
72 + ( cd dir && git merge-file a.txt o.txt b.txt ) &&
73 + test_path_is_missing a.txt
74 '
75
76 cp new1.txt test.txt