Skip to content

Commit 4c8d4c1

Browse files
bebarinogitster
authored andcommitted
apply, fmt-merge-msg: use relative filenames
Commit dbd0f5c (Files given on the command line are relative to $cwd, 2008-08-06) only fixed git-commit and git-tag. But, git-apply and git-fmt-merge-msg didn't get the update and exhibit the same behavior. Fix them and add tests for "apply --build-fake-ancestor" and "fmt-merge-msg -F". Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aae94ff commit 4c8d4c1

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

builtin-apply.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3316,6 +3316,10 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
33163316

33173317
argc = parse_options(argc, argv, builtin_apply_options,
33183318
apply_usage, 0);
3319+
fake_ancestor = parse_options_fix_filename(prefix, fake_ancestor);
3320+
if (fake_ancestor)
3321+
fake_ancestor = xstrdup(fake_ancestor);
3322+
33193323
if (apply_with_reject)
33203324
apply = apply_verbosely = 1;
33213325
if (!force_apply && (diffstat || numstat || summary || check || fake_ancestor))

builtin-fmt-merge-msg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
365365
argc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0);
366366
if (argc > 0)
367367
usage_with_options(fmt_merge_msg_usage, options);
368+
inpath = parse_options_fix_filename(prefix, inpath);
368369

369370
if (inpath && strcmp(inpath, "-")) {
370371
in = fopen(inpath, "r");

t/t4131-apply-fake-ancestor.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2009 Stephen Boyd
4+
#
5+
6+
test_description='git apply --build-fake-ancestor handling.'
7+
8+
. ./test-lib.sh
9+
10+
test_expect_success 'setup' '
11+
test_commit 1 &&
12+
test_commit 2 &&
13+
mkdir sub &&
14+
test_commit 3 sub/3 &&
15+
test_commit 4
16+
'
17+
18+
test_expect_success 'apply --build-fake-ancestor' '
19+
git checkout 2 &&
20+
echo "A" > 1.t &&
21+
git diff > 1.patch &&
22+
git reset --hard &&
23+
git checkout 1 &&
24+
git apply --build-fake-ancestor 1.ancestor 1.patch
25+
'
26+
27+
test_expect_success 'apply --build-fake-ancestor in a subdirectory' '
28+
git checkout 3 &&
29+
echo "C" > sub/3.t &&
30+
git diff > 3.patch &&
31+
git reset --hard &&
32+
git checkout 4 &&
33+
(
34+
cd sub &&
35+
git apply --build-fake-ancestor 3.ancestor ../3.patch &&
36+
test -f 3.ancestor
37+
) &&
38+
git apply --build-fake-ancestor 3.ancestor 3.patch &&
39+
test_cmp sub/3.ancestor 3.ancestor
40+
'
41+
42+
test_done

t/t6200-fmt-merge-msg.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,36 @@ test_expect_success 'merge-msg test #5-2' '
208208
test_cmp expected actual
209209
'
210210

211+
test_expect_success 'merge-msg -F' '
212+
213+
git config --unset-all merge.log
214+
git config --unset-all merge.summary
215+
git config merge.summary yes &&
216+
217+
git checkout master &&
218+
setdate &&
219+
git fetch . left right &&
220+
221+
git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
222+
test_cmp expected actual
223+
'
224+
225+
test_expect_success 'merge-msg -F in subdirectory' '
226+
227+
git config --unset-all merge.log
228+
git config --unset-all merge.summary
229+
git config merge.summary yes &&
230+
231+
git checkout master &&
232+
setdate &&
233+
git fetch . left right &&
234+
mkdir sub &&
235+
cp .git/FETCH_HEAD sub/FETCH_HEAD &&
236+
(
237+
cd sub &&
238+
git fmt-merge-msg -F FETCH_HEAD >../actual
239+
) &&
240+
test_cmp expected actual
241+
'
242+
211243
test_done

0 commit comments

Comments
 (0)