]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-file: correctly open files when in a subdir
authorAleksander Boruch-Gruszecki <aleksander.boruchgruszecki@gmail.com>
Sun, 8 Feb 2015 16:53:53 +0000 (17:53 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Feb 2015 19:01:50 +0000 (11:01 -0800)
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>
builtin/merge-file.c
t/t6023-merge-file.sh

index 844f84f40bf0f8b9d95f4e9f0496c010386a9fb8..232b76857cf4f6dbd9bec12fa12266e1afc90a5c 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 432f086c063198e82ad8a2f7c8dd175a8685fdf5..d0df869001b6441e31bc75fb78f336c748e1640e 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