зеркало из https://github.com/microsoft/git.git
Merge branch 'jc/maint-apply-match-beginning'
* jc/maint-apply-match-beginning: Fix "git apply" to correctly enforce "match at the beginning"
This commit is contained in:
Коммит
a1c0dca43a
|
@ -1937,21 +1937,24 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
|
||||||
trailing = frag->trailing;
|
trailing = frag->trailing;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we don't have any leading/trailing data in the patch,
|
* A hunk to change lines at the beginning would begin with
|
||||||
* we want it to match at the beginning/end of the file.
|
* @@ -1,L +N,M @@
|
||||||
*
|
*
|
||||||
* But that would break if the patch is generated with
|
* And a hunk to add to an empty file would begin with
|
||||||
* --unified=0; sane people wouldn't do that to cause us
|
* @@ -0,0 +N,M @@
|
||||||
* trouble, but we try to please not so sane ones as well.
|
*
|
||||||
|
* In other words, a hunk that is (frag->oldpos <= 1) with or
|
||||||
|
* without leading context must match at the beginning.
|
||||||
*/
|
*/
|
||||||
if (unidiff_zero) {
|
match_beginning = frag->oldpos <= 1;
|
||||||
match_beginning = (!leading && !frag->oldpos);
|
|
||||||
match_end = 0;
|
/*
|
||||||
}
|
* A hunk without trailing lines must match at the end.
|
||||||
else {
|
* However, we simply cannot tell if a hunk must match end
|
||||||
match_beginning = !leading && (frag->oldpos == 1);
|
* from the lack of trailing lines if the patch was generated
|
||||||
match_end = !trailing;
|
* with unidiff without any context.
|
||||||
}
|
*/
|
||||||
|
match_end = !unidiff_zero && !trailing;
|
||||||
|
|
||||||
pos = frag->newpos ? (frag->newpos - 1) : 0;
|
pos = frag->newpos ? (frag->newpos - 1) : 0;
|
||||||
preimage.buf = oldlines;
|
preimage.buf = oldlines;
|
||||||
|
|
|
@ -112,4 +112,17 @@ do
|
||||||
'
|
'
|
||||||
done
|
done
|
||||||
|
|
||||||
|
test_expect_success 'two lines' '
|
||||||
|
|
||||||
|
>file &&
|
||||||
|
git add file &&
|
||||||
|
echo aaa >file &&
|
||||||
|
git diff >patch &&
|
||||||
|
git add file &&
|
||||||
|
echo bbb >file &&
|
||||||
|
git add file &&
|
||||||
|
test_must_fail git apply --check patch
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Загрузка…
Ссылка в новой задаче