@matheusbsbs / matheus-bagliano / commits / 55846b9abd
Fork 0

merge-file: correctly find files when called in subdir

Since b541248 (merge.conflictstyle: choose between "merge" and "diff3 -m" styles, 2008-08-29), git-merge-file uses setup_directory_gently(), thus cd'ing around to find any possible config files to use. This broke merge-file when it is called from within a subdirectory of a repository, and the arguments are all relative paths. Fix by prepending the prefix, as passed down from the main git setup code, if there is any. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Oct 17, 2010 at 21:23 UTC 55846b9abd128185388418e025651cfd6a299a0e
2 files changed +14 -1
builtin/merge-file.c
+6 -1
@@ -28,6 +28,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
28 xmparam_t xmp = {{0}};
29 int ret = 0, i = 0, to_stdout = 0;
30 int quiet = 0;
31 + int prefixlen = 0;
32 struct option options[] = {
33 OPT_BOOLEAN('p', "stdout", &to_stdout, "send results to standard output"),
34 OPT_SET_INT(0, "diff3", &xmp.style, "use a diff3 based merge", XDL_MERGE_DIFF3),
@@ -65,10 +66,14 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
66 "%s\n", strerror(errno));
67 }
68
69 + if (prefix)
70 + prefixlen = strlen(prefix);
71 +
72 for (i = 0; i < 3; i++) {
73 + const char *fname = prefix_filename(prefix, prefixlen, argv[i]);
74 if (!names[i])
75 names[i] = argv[i];
71 - if (read_mmfile(mmfs + i, argv[i]))
76 + if (read_mmfile(mmfs + i, fname))
77 return -1;
78 if (buffer_is_binary(mmfs[i].ptr, mmfs[i].size))
79 return error("Cannot merge binary files: %s\n",
t/t6023-merge-file.sh
+8
@@ -64,6 +64,14 @@ cp new1.txt test.txt
64 test_expect_success "merge without conflict" \
65 "git merge-file test.txt orig.txt new2.txt"
66
67 +test_expect_success 'works in subdirectory' '
68 + mkdir dir &&
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 )
73 +'
74 +
75 cp new1.txt test.txt
76 test_expect_success "merge without conflict (--quiet)" \
77 "git merge-file --quiet test.txt orig.txt new2.txt"