Skip to content

Commit

Permalink
merge-file: correctly open files when in a subdir
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Aleksander Boruch-Gruszecki authored and Junio C Hamano committed Feb 11, 2015
1 parent 3d8a54e commit 204a8ff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion builtin/merge-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion t/t6023-merge-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 204a8ff

Please sign in to comment.