Merge branch 'ab/merge-file-prefix'
authorJunio C Hamano <gitster@pobox.com>
Sun, 22 Feb 2015 20:28:25 +0000 (12:28 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 22 Feb 2015 20:28:25 +0000 (12:28 -0800)
"git merge-file" did not work correctly in a subdirectory.

* ab/merge-file-prefix:
merge-file: correctly open files when in a subdir

builtin/merge-file.c
t/t6023-merge-file.sh
index 131edc245fdc0f5f8cb1e5d3da4120d072858d3f..ea8093f6769e278c4f7871faf405fe1e3f0a7544 100644 (file)
@@ -90,7 +90,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
 
        if (ret >= 0) {
                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);
index 3758961765635c4ce504eec1540605f65efd386a..190ee903cf6269071809e82d61d6065f1de679c6 100755 (executable)
@@ -69,7 +69,8 @@ test_expect_success 'works in subdirectory' '
        cp new1.txt dir/a.txt &&
        cp orig.txt dir/o.txt &&
        cp new2.txt dir/b.txt &&
-       ( cd dir && git merge-file a.txt o.txt b.txt )
+       ( cd dir && git merge-file a.txt o.txt b.txt ) &&
+       test_path_is_missing a.txt
 '
 
 cp new1.txt test.txt