Skip to content

Commit 204a8ff

Browse files
abgruszeckigitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d8a54e commit 204a8ff

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

builtin/merge-file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
9090

9191
if (ret >= 0) {
9292
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");
9495

9596
if (!f)
9697
ret = error("Could not open %s for writing", filename);

t/t6023-merge-file.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ test_expect_success 'works in subdirectory' '
6969
cp new1.txt dir/a.txt &&
7070
cp orig.txt dir/o.txt &&
7171
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
7374
'
7475

7576
cp new1.txt test.txt

0 commit comments

Comments
 (0)