4895
4943
expected_output, expected_disk,
4896
4944
expected_status, expected_skip)
4946
# In the following case the reordered hunk2 is smaller offset
4947
# magnitude than hunk2 at the end and the reorder is preferred.
4948
sbox.simple_revert('A/mu')
4949
sbox.simple_append('A/mu',
4951
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
4953
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
4955
'1\n' '2\n' '3\n' 'hunk1\n' '4\n' '5\n' '6\n' +
4957
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n',
4959
sbox.simple_commit()
4963
"===================================================================\n",
4964
"--- A/mu\t(revision 2)\n",
4965
"+++ A/mu\t(working copy)\n",
4966
"@@ -28,7 +28,7 @@\n",
4975
"@@ -44,7 +44,7 @@\n",
4986
patch_file_path = make_patch_path(sbox)
4987
svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))
4990
'U %s\n' % sbox.ospath('A/mu'),
4991
'> applied hunk @@ -44,7 +44,7 @@ with offset -32\n',
4992
'> applied hunk @@ -28,7 +28,7 @@ with offset 1\n',
4994
expected_disk.tweak('A/mu', contents=
4996
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
4998
'1\n' '2\n' '3\n' 'hunk2-mod\n' '4\n' '5\n' '6\n' +
5000
'1\n' '2\n' '3\n' 'hunk1-mod\n' '4\n' '5\n' '6\n' +
5002
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n')
5004
expected_status.tweak('A/mu', status='M ', wc_rev=3)
5005
expected_skip = wc.State('', { })
5006
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5007
expected_output, expected_disk,
5008
expected_status, expected_skip)
5009
sbox.simple_revert('A/mu')
5011
# In this case the reordered hunk2 is further than hunk2 at the end
5012
# and the reordered is not preferred.
5015
"===================================================================\n",
5016
"--- A/mu\t(revision 2)\n",
5017
"+++ A/mu\t(working copy)\n",
5018
"@@ -28,7 +28,7 @@\n",
5027
"@@ -110,7 +110,7 @@\n",
5038
patch_file_path = make_patch_path(sbox)
5039
svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))
5042
'U %s\n' % sbox.ospath('A/mu'),
5043
'> applied hunk @@ -28,7 +28,7 @@ with offset 1\n',
5044
'> applied hunk @@ -110,7 +110,7 @@ with offset 26\n',
5046
expected_disk.tweak('A/mu', contents=
5048
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5050
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5052
'1\n' '2\n' '3\n' 'hunk1-mod\n' '4\n' '5\n' '6\n' +
5054
'1\n' '2\n' '3\n' 'hunk2-mod\n' '4\n' '5\n' '6\n')
5056
expected_status.tweak('A/mu', status='M ', wc_rev=3)
5057
expected_skip = wc.State('', { })
5058
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5059
expected_output, expected_disk,
5060
expected_status, expected_skip)
5063
def patch_hunk_overlap(sbox):
5064
"""hunks that overlap"""
5067
wc_dir = sbox.wc_dir
5069
sbox.simple_append('A/mu',
5070
'AA\n' 'BB\n' 'CC\n' 'DD\n' 'EE\n' 'FF\n'
5071
'GG\n' 'HH\n' 'II\n', truncate=True)
5072
sbox.simple_commit()
5074
# Two hunks that overlap when applied, GNU patch can apply both hunks.
5077
"===================================================================\n",
5078
"--- A/mu\t(revision 1)\n",
5079
"+++ A/mu\t(working copy)\n",
5080
"@@ -2,6 +2,7 @@\n",
5088
"@@ -9,6 +10,7 @@\n",
5098
patch_file_path = make_patch_path(sbox)
5099
svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))
5102
'U %s\n' % sbox.ospath('A/mu'),
5103
'> applied hunk @@ -9,6 +10,7 @@ with offset -5\n',
5105
expected_disk = svntest.main.greek_state.copy()
5106
expected_disk.tweak('A/mu', contents=
5107
'AA\n' 'BB\n' 'CC\n' 'DD\n' '11111\n' 'EE\n' 'FF\n'
5108
'22222\n' 'GG\n' 'HH\n' 'II\n')
5109
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
5110
expected_status.tweak('A/mu', status='M ', wc_rev=2)
5111
expected_skip = wc.State('', { })
5112
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5113
expected_output, expected_disk,
5114
expected_status, expected_skip)
5116
def patch_delete_modified(sbox):
5117
"""patch delete modified"""
5120
wc_dir = sbox.wc_dir
5122
# A patch that deletes beta.
5124
"Index: A/B/E/beta\n",
5125
"===================================================================\n",
5126
"--- A/B/E/beta (revision 1)\n",
5127
"+++ A/B/E/beta (working copy)\n",
5129
"-This is the file 'beta'.\n",
5132
patch_file_path = make_patch_path(sbox)
5133
svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))
5135
# First application deletes beta
5137
'D %s\n' % sbox.ospath('A/B/E/beta'),
5139
expected_disk = svntest.main.greek_state.copy()
5140
expected_disk.remove('A/B/E/beta')
5141
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
5142
expected_status.tweak('A/B/E/beta', status='D ')
5143
expected_skip = wc.State('', { })
5144
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5145
expected_output, expected_disk,
5146
expected_status, expected_skip)
5148
# Second application skips
5150
'Skipped \'%s\'\n' % sbox.ospath('A/B/E/beta'),
5151
] + svntest.main.summary_of_conflicts(skipped_paths=1)
5152
expected_skip = wc.State('', {
5153
sbox.ospath('A/B/E/beta') : Item(verb='Skipped'),
5155
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5156
expected_output, expected_disk,
5157
expected_status, expected_skip)
5159
# Third application, with file present even though state is 'D', also skips
5160
sbox.simple_append('A/B/E/beta', 'Modified', truncate=True)
5161
expected_disk.add({'A/B/E/beta' : Item(contents='Modified')})
5163
'Skipped \'%s\'\n' % sbox.ospath('A/B/E/beta'),
5164
] + svntest.main.summary_of_conflicts(skipped_paths=1)
5165
expected_skip = wc.State('', {
5166
sbox.ospath('A/B/E/beta') : Item(verb='Skipped'),
5168
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5169
expected_output, expected_disk,
5170
expected_status, expected_skip)
5172
# Revert and modify beta, fourth application gives a text conflict.
5173
sbox.simple_revert('A/B/E/beta')
5174
sbox.simple_append('A/B/E/beta', 'Modified', truncate=True)
5177
'C %s\n' % sbox.ospath('A/B/E/beta'),
5178
'> rejected hunk @@ -1,1 +0,0 @@\n',
5179
] + svntest.main.summary_of_conflicts(text_conflicts=1)
5180
expected_skip = wc.State('', { })
5181
reject_file_contents = [
5184
"@@ -1,1 +0,0 @@\n",
5185
"-This is the file 'beta'.\n",
5187
expected_disk.add({'A/B/E/beta.svnpatch.rej'
5188
: Item(contents=''.join(reject_file_contents))
5190
expected_status.tweak('A/B/E/beta', status='M ')
5191
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5192
expected_output, expected_disk,
5193
expected_status, expected_skip)
5195
def patch_closest(sbox):
5199
wc_dir = sbox.wc_dir
5203
"===================================================================\n",
5204
"--- A/mu\t(revision 2)\n",
5205
"+++ A/mu\t(working copy)\n",
5206
"@@ -47,7 +47,7 @@\n",
5215
"@@ -66,7 +66,7 @@\n",
5219
"-rejected-hunk2-\n",
5220
"+rejected-hunk2-mod\n",
5224
"@@ -180,7 +180,7 @@\n",
5234
patch_file_path = make_patch_path(sbox)
5235
svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))
5237
# Previous offset for hunk3 is +4, hunk3 matches at relative offsets
5238
# of -19 and +18, prefer +18 gives final offset +22
5239
sbox.simple_append('A/mu',
5241
'1\n' '2\n' '3\n' 'hunk1\n' '4\n' '5\n' '6\n' +
5243
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5245
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5247
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5250
sbox.simple_commit()
5253
'C %s\n' % sbox.ospath('A/mu'),
5254
'> applied hunk @@ -47,7 +47,7 @@ with offset 4\n',
5255
'> applied hunk @@ -180,7 +180,7 @@ with offset 22\n',
5256
'> rejected hunk @@ -66,7 +66,7 @@\n',
5257
] + svntest.main.summary_of_conflicts(text_conflicts=1)
5258
expected_disk = svntest.main.greek_state.copy()
5259
expected_disk.add({'A/mu.svnpatch.rej' : Item(contents=
5262
"@@ -66,7 +66,7 @@\n" +
5266
"-rejected-hunk2-\n" +
5267
"+rejected-hunk2-mod\n" +
5271
expected_disk.tweak('A/mu', contents=
5273
'1\n' '2\n' '3\n' 'hunk1-mod\n' '4\n' '5\n' '6\n' +
5275
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5277
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5279
'1\n' '2\n' '3\n' 'hunk3-mod\n' '4\n' '5\n' '6\n' +
5281
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
5282
expected_status.tweak('A/mu', status='M ', wc_rev=2)
5283
expected_skip = wc.State('', { })
5284
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5285
expected_output, expected_disk,
5286
expected_status, expected_skip)
5288
# Previous offset for hunk3 is +4, hunk3 matches at relative offsets
5289
# of -19 and +20, prefer -19 gives final offset -15
5290
sbox.simple_append('A/mu',
5292
'1\n' '2\n' '3\n' 'hunk1\n' '4\n' '5\n' '6\n' +
5294
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5296
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5298
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5301
sbox.simple_commit()
5304
'C %s\n' % sbox.ospath('A/mu'),
5305
'> applied hunk @@ -47,7 +47,7 @@ with offset 4\n',
5306
'> applied hunk @@ -180,7 +180,7 @@ with offset -15\n',
5307
'> rejected hunk @@ -66,7 +66,7 @@\n',
5308
] + svntest.main.summary_of_conflicts(text_conflicts=1)
5309
expected_disk.tweak('A/mu', contents=
5311
'1\n' '2\n' '3\n' 'hunk1-mod\n' '4\n' '5\n' '6\n' +
5313
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5315
'1\n' '2\n' '3\n' 'hunk3-mod\n' '4\n' '5\n' '6\n' +
5317
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5319
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
5320
expected_status.tweak('A/mu', status='M ', wc_rev=3)
5321
expected_skip = wc.State('', { })
5322
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5323
expected_output, expected_disk,
5324
expected_status, expected_skip)
5326
# Previous offset for hunk3 is +4, hunk3 matches at relative offsets
5327
# of -19 and +19, prefer -19 gives final offset -15
5328
sbox.simple_append('A/mu',
5330
'1\n' '2\n' '3\n' 'hunk1\n' '4\n' '5\n' '6\n' +
5332
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5334
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5336
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5339
sbox.simple_commit()
5342
'C %s\n' % sbox.ospath('A/mu'),
5343
'> applied hunk @@ -47,7 +47,7 @@ with offset 4\n',
5344
'> applied hunk @@ -180,7 +180,7 @@ with offset -15\n',
5345
'> rejected hunk @@ -66,7 +66,7 @@\n',
5346
] + svntest.main.summary_of_conflicts(text_conflicts=1)
5347
expected_disk.tweak('A/mu', contents=
5349
'1\n' '2\n' '3\n' 'hunk1-mod\n' '4\n' '5\n' '6\n' +
5351
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5353
'1\n' '2\n' '3\n' 'hunk3-mod\n' '4\n' '5\n' '6\n' +
5355
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5357
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
5358
expected_status.tweak('A/mu', status='M ', wc_rev=4)
5359
expected_skip = wc.State('', { })
5360
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5361
expected_output, expected_disk,
5362
expected_status, expected_skip)
5364
# Previous offset for hunk3 is +4, hunk3 matches at relative offsets
5365
# of +173 and -173, prefer +173 gives final offset +177
5366
sbox.simple_append('A/mu',
5368
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5370
'1\n' '2\n' '3\n' 'hunk1\n' '4\n' '5\n' '6\n' +
5372
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5374
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5377
sbox.simple_commit()
5380
'C %s\n' % sbox.ospath('A/mu'),
5381
'> applied hunk @@ -47,7 +47,7 @@ with offset 4\n',
5382
'> applied hunk @@ -180,7 +180,7 @@ with offset 177\n',
5383
'> rejected hunk @@ -66,7 +66,7 @@\n',
5384
] + svntest.main.summary_of_conflicts(text_conflicts=1)
5385
expected_disk.tweak('A/mu', contents=
5387
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5389
'1\n' '2\n' '3\n' 'hunk1-mod\n' '4\n' '5\n' '6\n' +
5391
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5393
'1\n' '2\n' '3\n' 'hunk3-mod\n' '4\n' '5\n' '6\n' +
5395
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
5396
expected_status.tweak('A/mu', status='M ', wc_rev=5)
5397
expected_skip = wc.State('', { })
5398
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5399
expected_output, expected_disk,
5400
expected_status, expected_skip)
5402
# Previous offset for hunk3 is +4, hunk3 matches at relative offsets
5403
# of +174 and -173, prefer -173 gives final offset -169
5404
sbox.simple_append('A/mu',
5406
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5408
'1\n' '2\n' '3\n' 'hunk1\n' '4\n' '5\n' '6\n' +
5410
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5412
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5415
sbox.simple_commit()
5418
'C %s\n' % sbox.ospath('A/mu'),
5419
'> applied hunk @@ -180,7 +180,7 @@ with offset -169\n',
5420
'> applied hunk @@ -47,7 +47,7 @@ with offset 4\n',
5421
'> rejected hunk @@ -66,7 +66,7 @@\n',
5422
] + svntest.main.summary_of_conflicts(text_conflicts=1)
5423
expected_disk.tweak('A/mu', contents=
5425
'1\n' '2\n' '3\n' 'hunk3-mod\n' '4\n' '5\n' '6\n' +
5427
'1\n' '2\n' '3\n' 'hunk1-mod\n' '4\n' '5\n' '6\n' +
5429
'1\n' '2\n' '3\n' 'hunk2\n' '4\n' '5\n' '6\n' +
5431
'1\n' '2\n' '3\n' 'hunk3\n' '4\n' '5\n' '6\n' +
5433
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
5434
expected_status.tweak('A/mu', status='M ', wc_rev=6)
5435
expected_skip = wc.State('', { })
5436
svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
5437
expected_output, expected_disk,
5438
expected_status, expected_skip)
4898
5440
########################################################################