##// END OF EJS Templates
filemerge: make capability check for internal tools ignore merge-tools section...
FUJIWARA Katsunori -
r39302:82555d71 default
parent child Browse files
Show More
@@ -1,1002 +1,1001 b''
1 1 # filemerge.py - file-level merge handling for Mercurial
2 2 #
3 3 # Copyright 2006, 2007, 2008 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from __future__ import absolute_import
9 9
10 10 import contextlib
11 11 import os
12 12 import re
13 13 import shutil
14 14
15 15 from .i18n import _
16 16 from .node import nullid, short
17 17
18 18 from . import (
19 19 encoding,
20 20 error,
21 21 formatter,
22 22 match,
23 23 pycompat,
24 24 registrar,
25 25 scmutil,
26 26 simplemerge,
27 27 tagmerge,
28 28 templatekw,
29 29 templater,
30 30 util,
31 31 )
32 32
33 33 from .utils import (
34 34 procutil,
35 35 stringutil,
36 36 )
37 37
38 38 def _toolstr(ui, tool, part, *args):
39 39 return ui.config("merge-tools", tool + "." + part, *args)
40 40
41 41 def _toolbool(ui, tool, part,*args):
42 42 return ui.configbool("merge-tools", tool + "." + part, *args)
43 43
44 44 def _toollist(ui, tool, part):
45 45 return ui.configlist("merge-tools", tool + "." + part)
46 46
47 47 internals = {}
48 48 # Merge tools to document.
49 49 internalsdoc = {}
50 50
51 51 internaltool = registrar.internalmerge()
52 52
53 53 # internal tool merge types
54 54 nomerge = internaltool.nomerge
55 55 mergeonly = internaltool.mergeonly # just the full merge, no premerge
56 56 fullmerge = internaltool.fullmerge # both premerge and merge
57 57
58 58 _localchangedotherdeletedmsg = _(
59 59 "local%(l)s changed %(fd)s which other%(o)s deleted\n"
60 60 "use (c)hanged version, (d)elete, or leave (u)nresolved?"
61 61 "$$ &Changed $$ &Delete $$ &Unresolved")
62 62
63 63 _otherchangedlocaldeletedmsg = _(
64 64 "other%(o)s changed %(fd)s which local%(l)s deleted\n"
65 65 "use (c)hanged version, leave (d)eleted, or "
66 66 "leave (u)nresolved?"
67 67 "$$ &Changed $$ &Deleted $$ &Unresolved")
68 68
69 69 class absentfilectx(object):
70 70 """Represents a file that's ostensibly in a context but is actually not
71 71 present in it.
72 72
73 73 This is here because it's very specific to the filemerge code for now --
74 74 other code is likely going to break with the values this returns."""
75 75 def __init__(self, ctx, f):
76 76 self._ctx = ctx
77 77 self._f = f
78 78
79 79 def path(self):
80 80 return self._f
81 81
82 82 def size(self):
83 83 return None
84 84
85 85 def data(self):
86 86 return None
87 87
88 88 def filenode(self):
89 89 return nullid
90 90
91 91 _customcmp = True
92 92 def cmp(self, fctx):
93 93 """compare with other file context
94 94
95 95 returns True if different from fctx.
96 96 """
97 97 return not (fctx.isabsent() and
98 98 fctx.ctx() == self.ctx() and
99 99 fctx.path() == self.path())
100 100
101 101 def flags(self):
102 102 return ''
103 103
104 104 def changectx(self):
105 105 return self._ctx
106 106
107 107 def isbinary(self):
108 108 return False
109 109
110 110 def isabsent(self):
111 111 return True
112 112
113 113 def _findtool(ui, tool):
114 114 if tool in internals:
115 115 return tool
116 116 cmd = _toolstr(ui, tool, "executable", tool)
117 117 if cmd.startswith('python:'):
118 118 return cmd
119 119 return findexternaltool(ui, tool)
120 120
121 121 def _quotetoolpath(cmd):
122 122 if cmd.startswith('python:'):
123 123 return cmd
124 124 return procutil.shellquote(cmd)
125 125
126 126 def findexternaltool(ui, tool):
127 127 for kn in ("regkey", "regkeyalt"):
128 128 k = _toolstr(ui, tool, kn)
129 129 if not k:
130 130 continue
131 131 p = util.lookupreg(k, _toolstr(ui, tool, "regname"))
132 132 if p:
133 133 p = procutil.findexe(p + _toolstr(ui, tool, "regappend", ""))
134 134 if p:
135 135 return p
136 136 exe = _toolstr(ui, tool, "executable", tool)
137 137 return procutil.findexe(util.expandpath(exe))
138 138
139 139 def _picktool(repo, ui, path, binary, symlink, changedelete):
140 140 strictcheck = ui.configbool('merge', 'strict-capability-check')
141 141
142 142 def hascapability(tool, capability, strict=False):
143 if strict and tool in internals:
144 if internals[tool].capabilities.get(capability):
145 return True
143 if tool in internals:
144 return strict and internals[tool].capabilities.get(capability)
146 145 return _toolbool(ui, tool, capability)
147 146
148 147 def supportscd(tool):
149 148 return tool in internals and internals[tool].mergetype == nomerge
150 149
151 150 def check(tool, pat, symlink, binary, changedelete):
152 151 tmsg = tool
153 152 if pat:
154 153 tmsg = _("%s (for pattern %s)") % (tool, pat)
155 154 if not _findtool(ui, tool):
156 155 if pat: # explicitly requested tool deserves a warning
157 156 ui.warn(_("couldn't find merge tool %s\n") % tmsg)
158 157 else: # configured but non-existing tools are more silent
159 158 ui.note(_("couldn't find merge tool %s\n") % tmsg)
160 159 elif symlink and not hascapability(tool, "symlink", strictcheck):
161 160 ui.warn(_("tool %s can't handle symlinks\n") % tmsg)
162 161 elif binary and not hascapability(tool, "binary", strictcheck):
163 162 ui.warn(_("tool %s can't handle binary\n") % tmsg)
164 163 elif changedelete and not supportscd(tool):
165 164 # the nomerge tools are the only tools that support change/delete
166 165 # conflicts
167 166 pass
168 167 elif not procutil.gui() and _toolbool(ui, tool, "gui"):
169 168 ui.warn(_("tool %s requires a GUI\n") % tmsg)
170 169 else:
171 170 return True
172 171 return False
173 172
174 173 # internal config: ui.forcemerge
175 174 # forcemerge comes from command line arguments, highest priority
176 175 force = ui.config('ui', 'forcemerge')
177 176 if force:
178 177 toolpath = _findtool(ui, force)
179 178 if changedelete and not supportscd(toolpath):
180 179 return ":prompt", None
181 180 else:
182 181 if toolpath:
183 182 return (force, _quotetoolpath(toolpath))
184 183 else:
185 184 # mimic HGMERGE if given tool not found
186 185 return (force, force)
187 186
188 187 # HGMERGE takes next precedence
189 188 hgmerge = encoding.environ.get("HGMERGE")
190 189 if hgmerge:
191 190 if changedelete and not supportscd(hgmerge):
192 191 return ":prompt", None
193 192 else:
194 193 return (hgmerge, hgmerge)
195 194
196 195 # then patterns
197 196
198 197 # whether binary capability should be checked strictly
199 198 binarycap = binary and strictcheck
200 199
201 200 for pat, tool in ui.configitems("merge-patterns"):
202 201 mf = match.match(repo.root, '', [pat])
203 202 if mf(path) and check(tool, pat, symlink, binarycap, changedelete):
204 203 if binary and not hascapability(tool, "binary", strict=True):
205 204 ui.warn(_("warning: check merge-patterns configurations,"
206 205 " if %r for binary file %r is unintentional\n"
207 206 "(see 'hg help merge-tools'"
208 207 " for binary files capability)\n")
209 208 % (pycompat.bytestr(tool), pycompat.bytestr(path)))
210 209 toolpath = _findtool(ui, tool)
211 210 return (tool, _quotetoolpath(toolpath))
212 211
213 212 # then merge tools
214 213 tools = {}
215 214 disabled = set()
216 215 for k, v in ui.configitems("merge-tools"):
217 216 t = k.split('.')[0]
218 217 if t not in tools:
219 218 tools[t] = int(_toolstr(ui, t, "priority"))
220 219 if _toolbool(ui, t, "disabled"):
221 220 disabled.add(t)
222 221 names = tools.keys()
223 222 tools = sorted([(-p, tool) for tool, p in tools.items()
224 223 if tool not in disabled])
225 224 uimerge = ui.config("ui", "merge")
226 225 if uimerge:
227 226 # external tools defined in uimerge won't be able to handle
228 227 # change/delete conflicts
229 228 if check(uimerge, path, symlink, binary, changedelete):
230 229 if uimerge not in names and not changedelete:
231 230 return (uimerge, uimerge)
232 231 tools.insert(0, (None, uimerge)) # highest priority
233 232 tools.append((None, "hgmerge")) # the old default, if found
234 233 for p, t in tools:
235 234 if check(t, None, symlink, binary, changedelete):
236 235 toolpath = _findtool(ui, t)
237 236 return (t, _quotetoolpath(toolpath))
238 237
239 238 # internal merge or prompt as last resort
240 239 if symlink or binary or changedelete:
241 240 if not changedelete and len(tools):
242 241 # any tool is rejected by capability for symlink or binary
243 242 ui.warn(_("no tool found to merge %s\n") % path)
244 243 return ":prompt", None
245 244 return ":merge", None
246 245
247 246 def _eoltype(data):
248 247 "Guess the EOL type of a file"
249 248 if '\0' in data: # binary
250 249 return None
251 250 if '\r\n' in data: # Windows
252 251 return '\r\n'
253 252 if '\r' in data: # Old Mac
254 253 return '\r'
255 254 if '\n' in data: # UNIX
256 255 return '\n'
257 256 return None # unknown
258 257
259 258 def _matcheol(file, back):
260 259 "Convert EOL markers in a file to match origfile"
261 260 tostyle = _eoltype(back.data()) # No repo.wread filters?
262 261 if tostyle:
263 262 data = util.readfile(file)
264 263 style = _eoltype(data)
265 264 if style:
266 265 newdata = data.replace(style, tostyle)
267 266 if newdata != data:
268 267 util.writefile(file, newdata)
269 268
270 269 @internaltool('prompt', nomerge)
271 270 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
272 271 """Asks the user which of the local `p1()` or the other `p2()` version to
273 272 keep as the merged version."""
274 273 ui = repo.ui
275 274 fd = fcd.path()
276 275
277 276 # Avoid prompting during an in-memory merge since it doesn't support merge
278 277 # conflicts.
279 278 if fcd.changectx().isinmemory():
280 279 raise error.InMemoryMergeConflictsError('in-memory merge does not '
281 280 'support file conflicts')
282 281
283 282 prompts = partextras(labels)
284 283 prompts['fd'] = fd
285 284 try:
286 285 if fco.isabsent():
287 286 index = ui.promptchoice(
288 287 _localchangedotherdeletedmsg % prompts, 2)
289 288 choice = ['local', 'other', 'unresolved'][index]
290 289 elif fcd.isabsent():
291 290 index = ui.promptchoice(
292 291 _otherchangedlocaldeletedmsg % prompts, 2)
293 292 choice = ['other', 'local', 'unresolved'][index]
294 293 else:
295 294 index = ui.promptchoice(
296 295 _("keep (l)ocal%(l)s, take (o)ther%(o)s, or leave (u)nresolved"
297 296 " for %(fd)s?"
298 297 "$$ &Local $$ &Other $$ &Unresolved") % prompts, 2)
299 298 choice = ['local', 'other', 'unresolved'][index]
300 299
301 300 if choice == 'other':
302 301 return _iother(repo, mynode, orig, fcd, fco, fca, toolconf,
303 302 labels)
304 303 elif choice == 'local':
305 304 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf,
306 305 labels)
307 306 elif choice == 'unresolved':
308 307 return _ifail(repo, mynode, orig, fcd, fco, fca, toolconf,
309 308 labels)
310 309 except error.ResponseExpected:
311 310 ui.write("\n")
312 311 return _ifail(repo, mynode, orig, fcd, fco, fca, toolconf,
313 312 labels)
314 313
315 314 @internaltool('local', nomerge)
316 315 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
317 316 """Uses the local `p1()` version of files as the merged version."""
318 317 return 0, fcd.isabsent()
319 318
320 319 @internaltool('other', nomerge)
321 320 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
322 321 """Uses the other `p2()` version of files as the merged version."""
323 322 if fco.isabsent():
324 323 # local changed, remote deleted -- 'deleted' picked
325 324 _underlyingfctxifabsent(fcd).remove()
326 325 deleted = True
327 326 else:
328 327 _underlyingfctxifabsent(fcd).write(fco.data(), fco.flags())
329 328 deleted = False
330 329 return 0, deleted
331 330
332 331 @internaltool('fail', nomerge)
333 332 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
334 333 """
335 334 Rather than attempting to merge files that were modified on both
336 335 branches, it marks them as unresolved. The resolve command must be
337 336 used to resolve these conflicts."""
338 337 # for change/delete conflicts write out the changed version, then fail
339 338 if fcd.isabsent():
340 339 _underlyingfctxifabsent(fcd).write(fco.data(), fco.flags())
341 340 return 1, False
342 341
343 342 def _underlyingfctxifabsent(filectx):
344 343 """Sometimes when resolving, our fcd is actually an absentfilectx, but
345 344 we want to write to it (to do the resolve). This helper returns the
346 345 underyling workingfilectx in that case.
347 346 """
348 347 if filectx.isabsent():
349 348 return filectx.changectx()[filectx.path()]
350 349 else:
351 350 return filectx
352 351
353 352 def _premerge(repo, fcd, fco, fca, toolconf, files, labels=None):
354 353 tool, toolpath, binary, symlink, scriptfn = toolconf
355 354 if symlink or fcd.isabsent() or fco.isabsent():
356 355 return 1
357 356 unused, unused, unused, back = files
358 357
359 358 ui = repo.ui
360 359
361 360 validkeep = ['keep', 'keep-merge3']
362 361
363 362 # do we attempt to simplemerge first?
364 363 try:
365 364 premerge = _toolbool(ui, tool, "premerge", not binary)
366 365 except error.ConfigError:
367 366 premerge = _toolstr(ui, tool, "premerge", "").lower()
368 367 if premerge not in validkeep:
369 368 _valid = ', '.join(["'" + v + "'" for v in validkeep])
370 369 raise error.ConfigError(_("%s.premerge not valid "
371 370 "('%s' is neither boolean nor %s)") %
372 371 (tool, premerge, _valid))
373 372
374 373 if premerge:
375 374 if premerge == 'keep-merge3':
376 375 if not labels:
377 376 labels = _defaultconflictlabels
378 377 if len(labels) < 3:
379 378 labels.append('base')
380 379 r = simplemerge.simplemerge(ui, fcd, fca, fco, quiet=True, label=labels)
381 380 if not r:
382 381 ui.debug(" premerge successful\n")
383 382 return 0
384 383 if premerge not in validkeep:
385 384 # restore from backup and try again
386 385 _restorebackup(fcd, back)
387 386 return 1 # continue merging
388 387
389 388 def _mergecheck(repo, mynode, orig, fcd, fco, fca, toolconf):
390 389 tool, toolpath, binary, symlink, scriptfn = toolconf
391 390 if symlink:
392 391 repo.ui.warn(_('warning: internal %s cannot merge symlinks '
393 392 'for %s\n') % (tool, fcd.path()))
394 393 return False
395 394 if fcd.isabsent() or fco.isabsent():
396 395 repo.ui.warn(_('warning: internal %s cannot merge change/delete '
397 396 'conflict for %s\n') % (tool, fcd.path()))
398 397 return False
399 398 return True
400 399
401 400 def _merge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels, mode):
402 401 """
403 402 Uses the internal non-interactive simple merge algorithm for merging
404 403 files. It will fail if there are any conflicts and leave markers in
405 404 the partially merged file. Markers will have two sections, one for each side
406 405 of merge, unless mode equals 'union' which suppresses the markers."""
407 406 ui = repo.ui
408 407
409 408 r = simplemerge.simplemerge(ui, fcd, fca, fco, label=labels, mode=mode)
410 409 return True, r, False
411 410
412 411 @internaltool('union', fullmerge,
413 412 _("warning: conflicts while merging %s! "
414 413 "(edit, then use 'hg resolve --mark')\n"),
415 414 precheck=_mergecheck)
416 415 def _iunion(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
417 416 """
418 417 Uses the internal non-interactive simple merge algorithm for merging
419 418 files. It will use both left and right sides for conflict regions.
420 419 No markers are inserted."""
421 420 return _merge(repo, mynode, orig, fcd, fco, fca, toolconf,
422 421 files, labels, 'union')
423 422
424 423 @internaltool('merge', fullmerge,
425 424 _("warning: conflicts while merging %s! "
426 425 "(edit, then use 'hg resolve --mark')\n"),
427 426 precheck=_mergecheck)
428 427 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
429 428 """
430 429 Uses the internal non-interactive simple merge algorithm for merging
431 430 files. It will fail if there are any conflicts and leave markers in
432 431 the partially merged file. Markers will have two sections, one for each side
433 432 of merge."""
434 433 return _merge(repo, mynode, orig, fcd, fco, fca, toolconf,
435 434 files, labels, 'merge')
436 435
437 436 @internaltool('merge3', fullmerge,
438 437 _("warning: conflicts while merging %s! "
439 438 "(edit, then use 'hg resolve --mark')\n"),
440 439 precheck=_mergecheck)
441 440 def _imerge3(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
442 441 """
443 442 Uses the internal non-interactive simple merge algorithm for merging
444 443 files. It will fail if there are any conflicts and leave markers in
445 444 the partially merged file. Marker will have three sections, one from each
446 445 side of the merge and one for the base content."""
447 446 if not labels:
448 447 labels = _defaultconflictlabels
449 448 if len(labels) < 3:
450 449 labels.append('base')
451 450 return _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels)
452 451
453 452 def _imergeauto(repo, mynode, orig, fcd, fco, fca, toolconf, files,
454 453 labels=None, localorother=None):
455 454 """
456 455 Generic driver for _imergelocal and _imergeother
457 456 """
458 457 assert localorother is not None
459 458 tool, toolpath, binary, symlink, scriptfn = toolconf
460 459 r = simplemerge.simplemerge(repo.ui, fcd, fca, fco, label=labels,
461 460 localorother=localorother)
462 461 return True, r
463 462
464 463 @internaltool('merge-local', mergeonly, precheck=_mergecheck)
465 464 def _imergelocal(*args, **kwargs):
466 465 """
467 466 Like :merge, but resolve all conflicts non-interactively in favor
468 467 of the local `p1()` changes."""
469 468 success, status = _imergeauto(localorother='local', *args, **kwargs)
470 469 return success, status, False
471 470
472 471 @internaltool('merge-other', mergeonly, precheck=_mergecheck)
473 472 def _imergeother(*args, **kwargs):
474 473 """
475 474 Like :merge, but resolve all conflicts non-interactively in favor
476 475 of the other `p2()` changes."""
477 476 success, status = _imergeauto(localorother='other', *args, **kwargs)
478 477 return success, status, False
479 478
480 479 @internaltool('tagmerge', mergeonly,
481 480 _("automatic tag merging of %s failed! "
482 481 "(use 'hg resolve --tool :merge' or another merge "
483 482 "tool of your choice)\n"))
484 483 def _itagmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
485 484 """
486 485 Uses the internal tag merge algorithm (experimental).
487 486 """
488 487 success, status = tagmerge.merge(repo, fcd, fco, fca)
489 488 return success, status, False
490 489
491 490 @internaltool('dump', fullmerge, binary=True, symlink=True)
492 491 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
493 492 """
494 493 Creates three versions of the files to merge, containing the
495 494 contents of local, other and base. These files can then be used to
496 495 perform a merge manually. If the file to be merged is named
497 496 ``a.txt``, these files will accordingly be named ``a.txt.local``,
498 497 ``a.txt.other`` and ``a.txt.base`` and they will be placed in the
499 498 same directory as ``a.txt``.
500 499
501 500 This implies premerge. Therefore, files aren't dumped, if premerge
502 501 runs successfully. Use :forcedump to forcibly write files out.
503 502 """
504 503 a = _workingpath(repo, fcd)
505 504 fd = fcd.path()
506 505
507 506 from . import context
508 507 if isinstance(fcd, context.overlayworkingfilectx):
509 508 raise error.InMemoryMergeConflictsError('in-memory merge does not '
510 509 'support the :dump tool.')
511 510
512 511 util.writefile(a + ".local", fcd.decodeddata())
513 512 repo.wwrite(fd + ".other", fco.data(), fco.flags())
514 513 repo.wwrite(fd + ".base", fca.data(), fca.flags())
515 514 return False, 1, False
516 515
517 516 @internaltool('forcedump', mergeonly, binary=True, symlink=True)
518 517 def _forcedump(repo, mynode, orig, fcd, fco, fca, toolconf, files,
519 518 labels=None):
520 519 """
521 520 Creates three versions of the files as same as :dump, but omits premerge.
522 521 """
523 522 return _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files,
524 523 labels=labels)
525 524
526 525 def _xmergeimm(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
527 526 # In-memory merge simply raises an exception on all external merge tools,
528 527 # for now.
529 528 #
530 529 # It would be possible to run most tools with temporary files, but this
531 530 # raises the question of what to do if the user only partially resolves the
532 531 # file -- we can't leave a merge state. (Copy to somewhere in the .hg/
533 532 # directory and tell the user how to get it is my best idea, but it's
534 533 # clunky.)
535 534 raise error.InMemoryMergeConflictsError('in-memory merge does not support '
536 535 'external merge tools')
537 536
538 537 def _xmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
539 538 tool, toolpath, binary, symlink, scriptfn = toolconf
540 539 if fcd.isabsent() or fco.isabsent():
541 540 repo.ui.warn(_('warning: %s cannot merge change/delete conflict '
542 541 'for %s\n') % (tool, fcd.path()))
543 542 return False, 1, None
544 543 unused, unused, unused, back = files
545 544 localpath = _workingpath(repo, fcd)
546 545 args = _toolstr(repo.ui, tool, "args")
547 546
548 547 with _maketempfiles(repo, fco, fca, repo.wvfs.join(back.path()),
549 548 "$output" in args) as temppaths:
550 549 basepath, otherpath, localoutputpath = temppaths
551 550 outpath = ""
552 551 mylabel, otherlabel = labels[:2]
553 552 if len(labels) >= 3:
554 553 baselabel = labels[2]
555 554 else:
556 555 baselabel = 'base'
557 556 env = {'HG_FILE': fcd.path(),
558 557 'HG_MY_NODE': short(mynode),
559 558 'HG_OTHER_NODE': short(fco.changectx().node()),
560 559 'HG_BASE_NODE': short(fca.changectx().node()),
561 560 'HG_MY_ISLINK': 'l' in fcd.flags(),
562 561 'HG_OTHER_ISLINK': 'l' in fco.flags(),
563 562 'HG_BASE_ISLINK': 'l' in fca.flags(),
564 563 'HG_MY_LABEL': mylabel,
565 564 'HG_OTHER_LABEL': otherlabel,
566 565 'HG_BASE_LABEL': baselabel,
567 566 }
568 567 ui = repo.ui
569 568
570 569 if "$output" in args:
571 570 # read input from backup, write to original
572 571 outpath = localpath
573 572 localpath = localoutputpath
574 573 replace = {'local': localpath, 'base': basepath, 'other': otherpath,
575 574 'output': outpath, 'labellocal': mylabel,
576 575 'labelother': otherlabel, 'labelbase': baselabel}
577 576 args = util.interpolate(
578 577 br'\$', replace, args,
579 578 lambda s: procutil.shellquote(util.localpath(s)))
580 579 if _toolbool(ui, tool, "gui"):
581 580 repo.ui.status(_('running merge tool %s for file %s\n') %
582 581 (tool, fcd.path()))
583 582 if scriptfn is None:
584 583 cmd = toolpath + ' ' + args
585 584 repo.ui.debug('launching merge tool: %s\n' % cmd)
586 585 r = ui.system(cmd, cwd=repo.root, environ=env,
587 586 blockedtag='mergetool')
588 587 else:
589 588 repo.ui.debug('launching python merge script: %s:%s\n' %
590 589 (toolpath, scriptfn))
591 590 r = 0
592 591 try:
593 592 # avoid cycle cmdutil->merge->filemerge->extensions->cmdutil
594 593 from . import extensions
595 594 mod = extensions.loadpath(toolpath, 'hgmerge.%s' % tool)
596 595 except Exception:
597 596 raise error.Abort(_("loading python merge script failed: %s") %
598 597 toolpath)
599 598 mergefn = getattr(mod, scriptfn, None)
600 599 if mergefn is None:
601 600 raise error.Abort(_("%s does not have function: %s") %
602 601 (toolpath, scriptfn))
603 602 argslist = procutil.shellsplit(args)
604 603 # avoid cycle cmdutil->merge->filemerge->hook->extensions->cmdutil
605 604 from . import hook
606 605 ret, raised = hook.pythonhook(ui, repo, "merge", toolpath,
607 606 mergefn, {'args': argslist}, True)
608 607 if raised:
609 608 r = 1
610 609 repo.ui.debug('merge tool returned: %d\n' % r)
611 610 return True, r, False
612 611
613 612 def _formatconflictmarker(ctx, template, label, pad):
614 613 """Applies the given template to the ctx, prefixed by the label.
615 614
616 615 Pad is the minimum width of the label prefix, so that multiple markers
617 616 can have aligned templated parts.
618 617 """
619 618 if ctx.node() is None:
620 619 ctx = ctx.p1()
621 620
622 621 props = {'ctx': ctx}
623 622 templateresult = template.renderdefault(props)
624 623
625 624 label = ('%s:' % label).ljust(pad + 1)
626 625 mark = '%s %s' % (label, templateresult)
627 626
628 627 if mark:
629 628 mark = mark.splitlines()[0] # split for safety
630 629
631 630 # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ')
632 631 return stringutil.ellipsis(mark, 80 - 8)
633 632
634 633 _defaultconflictlabels = ['local', 'other']
635 634
636 635 def _formatlabels(repo, fcd, fco, fca, labels, tool=None):
637 636 """Formats the given labels using the conflict marker template.
638 637
639 638 Returns a list of formatted labels.
640 639 """
641 640 cd = fcd.changectx()
642 641 co = fco.changectx()
643 642 ca = fca.changectx()
644 643
645 644 ui = repo.ui
646 645 template = ui.config('ui', 'mergemarkertemplate')
647 646 if tool is not None:
648 647 template = _toolstr(ui, tool, 'mergemarkertemplate', template)
649 648 template = templater.unquotestring(template)
650 649 tres = formatter.templateresources(ui, repo)
651 650 tmpl = formatter.maketemplater(ui, template, defaults=templatekw.keywords,
652 651 resources=tres)
653 652
654 653 pad = max(len(l) for l in labels)
655 654
656 655 newlabels = [_formatconflictmarker(cd, tmpl, labels[0], pad),
657 656 _formatconflictmarker(co, tmpl, labels[1], pad)]
658 657 if len(labels) > 2:
659 658 newlabels.append(_formatconflictmarker(ca, tmpl, labels[2], pad))
660 659 return newlabels
661 660
662 661 def partextras(labels):
663 662 """Return a dictionary of extra labels for use in prompts to the user
664 663
665 664 Intended use is in strings of the form "(l)ocal%(l)s".
666 665 """
667 666 if labels is None:
668 667 return {
669 668 "l": "",
670 669 "o": "",
671 670 }
672 671
673 672 return {
674 673 "l": " [%s]" % labels[0],
675 674 "o": " [%s]" % labels[1],
676 675 }
677 676
678 677 def _restorebackup(fcd, back):
679 678 # TODO: Add a workingfilectx.write(otherfilectx) path so we can use
680 679 # util.copy here instead.
681 680 fcd.write(back.data(), fcd.flags())
682 681
683 682 def _makebackup(repo, ui, wctx, fcd, premerge):
684 683 """Makes and returns a filectx-like object for ``fcd``'s backup file.
685 684
686 685 In addition to preserving the user's pre-existing modifications to `fcd`
687 686 (if any), the backup is used to undo certain premerges, confirm whether a
688 687 merge changed anything, and determine what line endings the new file should
689 688 have.
690 689
691 690 Backups only need to be written once (right before the premerge) since their
692 691 content doesn't change afterwards.
693 692 """
694 693 if fcd.isabsent():
695 694 return None
696 695 # TODO: Break this import cycle somehow. (filectx -> ctx -> fileset ->
697 696 # merge -> filemerge). (I suspect the fileset import is the weakest link)
698 697 from . import context
699 698 a = _workingpath(repo, fcd)
700 699 back = scmutil.origpath(ui, repo, a)
701 700 inworkingdir = (back.startswith(repo.wvfs.base) and not
702 701 back.startswith(repo.vfs.base))
703 702 if isinstance(fcd, context.overlayworkingfilectx) and inworkingdir:
704 703 # If the backup file is to be in the working directory, and we're
705 704 # merging in-memory, we must redirect the backup to the memory context
706 705 # so we don't disturb the working directory.
707 706 relpath = back[len(repo.wvfs.base) + 1:]
708 707 if premerge:
709 708 wctx[relpath].write(fcd.data(), fcd.flags())
710 709 return wctx[relpath]
711 710 else:
712 711 if premerge:
713 712 # Otherwise, write to wherever path the user specified the backups
714 713 # should go. We still need to switch based on whether the source is
715 714 # in-memory so we can use the fast path of ``util.copy`` if both are
716 715 # on disk.
717 716 if isinstance(fcd, context.overlayworkingfilectx):
718 717 util.writefile(back, fcd.data())
719 718 else:
720 719 util.copyfile(a, back)
721 720 # A arbitraryfilectx is returned, so we can run the same functions on
722 721 # the backup context regardless of where it lives.
723 722 return context.arbitraryfilectx(back, repo=repo)
724 723
725 724 @contextlib.contextmanager
726 725 def _maketempfiles(repo, fco, fca, localpath, uselocalpath):
727 726 """Writes out `fco` and `fca` as temporary files, and (if uselocalpath)
728 727 copies `localpath` to another temporary file, so an external merge tool may
729 728 use them.
730 729 """
731 730 tmproot = None
732 731 tmprootprefix = repo.ui.config('experimental', 'mergetempdirprefix')
733 732 if tmprootprefix:
734 733 tmproot = pycompat.mkdtemp(prefix=tmprootprefix)
735 734
736 735 def maketempfrompath(prefix, path):
737 736 fullbase, ext = os.path.splitext(path)
738 737 pre = "%s~%s" % (os.path.basename(fullbase), prefix)
739 738 if tmproot:
740 739 name = os.path.join(tmproot, pre)
741 740 if ext:
742 741 name += ext
743 742 f = open(name, r"wb")
744 743 else:
745 744 fd, name = pycompat.mkstemp(prefix=pre + '.', suffix=ext)
746 745 f = os.fdopen(fd, r"wb")
747 746 return f, name
748 747
749 748 def tempfromcontext(prefix, ctx):
750 749 f, name = maketempfrompath(prefix, ctx.path())
751 750 data = repo.wwritedata(ctx.path(), ctx.data())
752 751 f.write(data)
753 752 f.close()
754 753 return name
755 754
756 755 b = tempfromcontext("base", fca)
757 756 c = tempfromcontext("other", fco)
758 757 d = localpath
759 758 if uselocalpath:
760 759 # We start off with this being the backup filename, so remove the .orig
761 760 # to make syntax-highlighting more likely.
762 761 if d.endswith('.orig'):
763 762 d, _ = os.path.splitext(d)
764 763 f, d = maketempfrompath("local", d)
765 764 with open(localpath, 'rb') as src:
766 765 f.write(src.read())
767 766 f.close()
768 767
769 768 try:
770 769 yield b, c, d
771 770 finally:
772 771 if tmproot:
773 772 shutil.rmtree(tmproot)
774 773 else:
775 774 util.unlink(b)
776 775 util.unlink(c)
777 776 # if not uselocalpath, d is the 'orig'/backup file which we
778 777 # shouldn't delete.
779 778 if d and uselocalpath:
780 779 util.unlink(d)
781 780
782 781 def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None):
783 782 """perform a 3-way merge in the working directory
784 783
785 784 premerge = whether this is a premerge
786 785 mynode = parent node before merge
787 786 orig = original local filename before merge
788 787 fco = other file context
789 788 fca = ancestor file context
790 789 fcd = local file context for current/destination file
791 790
792 791 Returns whether the merge is complete, the return value of the merge, and
793 792 a boolean indicating whether the file was deleted from disk."""
794 793
795 794 if not fco.cmp(fcd): # files identical?
796 795 return True, None, False
797 796
798 797 ui = repo.ui
799 798 fd = fcd.path()
800 799 binary = fcd.isbinary() or fco.isbinary() or fca.isbinary()
801 800 symlink = 'l' in fcd.flags() + fco.flags()
802 801 changedelete = fcd.isabsent() or fco.isabsent()
803 802 tool, toolpath = _picktool(repo, ui, fd, binary, symlink, changedelete)
804 803 scriptfn = None
805 804 if tool in internals and tool.startswith('internal:'):
806 805 # normalize to new-style names (':merge' etc)
807 806 tool = tool[len('internal'):]
808 807 if toolpath and toolpath.startswith('python:'):
809 808 invalidsyntax = False
810 809 if toolpath.count(':') >= 2:
811 810 script, scriptfn = toolpath[7:].rsplit(':', 1)
812 811 if not scriptfn:
813 812 invalidsyntax = True
814 813 # missing :callable can lead to spliting on windows drive letter
815 814 if '\\' in scriptfn or '/' in scriptfn:
816 815 invalidsyntax = True
817 816 else:
818 817 invalidsyntax = True
819 818 if invalidsyntax:
820 819 raise error.Abort(_("invalid 'python:' syntax: %s") % toolpath)
821 820 toolpath = script
822 821 ui.debug("picked tool '%s' for %s (binary %s symlink %s changedelete %s)\n"
823 822 % (tool, fd, pycompat.bytestr(binary), pycompat.bytestr(symlink),
824 823 pycompat.bytestr(changedelete)))
825 824
826 825 if tool in internals:
827 826 func = internals[tool]
828 827 mergetype = func.mergetype
829 828 onfailure = func.onfailure
830 829 precheck = func.precheck
831 830 isexternal = False
832 831 else:
833 832 if wctx.isinmemory():
834 833 func = _xmergeimm
835 834 else:
836 835 func = _xmerge
837 836 mergetype = fullmerge
838 837 onfailure = _("merging %s failed!\n")
839 838 precheck = None
840 839 isexternal = True
841 840
842 841 toolconf = tool, toolpath, binary, symlink, scriptfn
843 842
844 843 if mergetype == nomerge:
845 844 r, deleted = func(repo, mynode, orig, fcd, fco, fca, toolconf, labels)
846 845 return True, r, deleted
847 846
848 847 if premerge:
849 848 if orig != fco.path():
850 849 ui.status(_("merging %s and %s to %s\n") % (orig, fco.path(), fd))
851 850 else:
852 851 ui.status(_("merging %s\n") % fd)
853 852
854 853 ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca))
855 854
856 855 if precheck and not precheck(repo, mynode, orig, fcd, fco, fca,
857 856 toolconf):
858 857 if onfailure:
859 858 if wctx.isinmemory():
860 859 raise error.InMemoryMergeConflictsError('in-memory merge does '
861 860 'not support merge '
862 861 'conflicts')
863 862 ui.warn(onfailure % fd)
864 863 return True, 1, False
865 864
866 865 back = _makebackup(repo, ui, wctx, fcd, premerge)
867 866 files = (None, None, None, back)
868 867 r = 1
869 868 try:
870 869 internalmarkerstyle = ui.config('ui', 'mergemarkers')
871 870 if isexternal:
872 871 markerstyle = _toolstr(ui, tool, 'mergemarkers')
873 872 else:
874 873 markerstyle = internalmarkerstyle
875 874
876 875 if not labels:
877 876 labels = _defaultconflictlabels
878 877 formattedlabels = labels
879 878 if markerstyle != 'basic':
880 879 formattedlabels = _formatlabels(repo, fcd, fco, fca, labels,
881 880 tool=tool)
882 881
883 882 if premerge and mergetype == fullmerge:
884 883 # conflict markers generated by premerge will use 'detailed'
885 884 # settings if either ui.mergemarkers or the tool's mergemarkers
886 885 # setting is 'detailed'. This way tools can have basic labels in
887 886 # space-constrained areas of the UI, but still get full information
888 887 # in conflict markers if premerge is 'keep' or 'keep-merge3'.
889 888 premergelabels = labels
890 889 labeltool = None
891 890 if markerstyle != 'basic':
892 891 # respect 'tool's mergemarkertemplate (which defaults to
893 892 # ui.mergemarkertemplate)
894 893 labeltool = tool
895 894 if internalmarkerstyle != 'basic' or markerstyle != 'basic':
896 895 premergelabels = _formatlabels(repo, fcd, fco, fca,
897 896 premergelabels, tool=labeltool)
898 897
899 898 r = _premerge(repo, fcd, fco, fca, toolconf, files,
900 899 labels=premergelabels)
901 900 # complete if premerge successful (r is 0)
902 901 return not r, r, False
903 902
904 903 needcheck, r, deleted = func(repo, mynode, orig, fcd, fco, fca,
905 904 toolconf, files, labels=formattedlabels)
906 905
907 906 if needcheck:
908 907 r = _check(repo, r, ui, tool, fcd, files)
909 908
910 909 if r:
911 910 if onfailure:
912 911 if wctx.isinmemory():
913 912 raise error.InMemoryMergeConflictsError('in-memory merge '
914 913 'does not support '
915 914 'merge conflicts')
916 915 ui.warn(onfailure % fd)
917 916 _onfilemergefailure(ui)
918 917
919 918 return True, r, deleted
920 919 finally:
921 920 if not r and back is not None:
922 921 back.remove()
923 922
924 923 def _haltmerge():
925 924 msg = _('merge halted after failed merge (see hg resolve)')
926 925 raise error.InterventionRequired(msg)
927 926
928 927 def _onfilemergefailure(ui):
929 928 action = ui.config('merge', 'on-failure')
930 929 if action == 'prompt':
931 930 msg = _('continue merge operation (yn)?' '$$ &Yes $$ &No')
932 931 if ui.promptchoice(msg, 0) == 1:
933 932 _haltmerge()
934 933 if action == 'halt':
935 934 _haltmerge()
936 935 # default action is 'continue', in which case we neither prompt nor halt
937 936
938 937 def hasconflictmarkers(data):
939 938 return bool(re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", data,
940 939 re.MULTILINE))
941 940
942 941 def _check(repo, r, ui, tool, fcd, files):
943 942 fd = fcd.path()
944 943 unused, unused, unused, back = files
945 944
946 945 if not r and (_toolbool(ui, tool, "checkconflicts") or
947 946 'conflicts' in _toollist(ui, tool, "check")):
948 947 if hasconflictmarkers(fcd.data()):
949 948 r = 1
950 949
951 950 checked = False
952 951 if 'prompt' in _toollist(ui, tool, "check"):
953 952 checked = True
954 953 if ui.promptchoice(_("was merge of '%s' successful (yn)?"
955 954 "$$ &Yes $$ &No") % fd, 1):
956 955 r = 1
957 956
958 957 if not r and not checked and (_toolbool(ui, tool, "checkchanged") or
959 958 'changed' in
960 959 _toollist(ui, tool, "check")):
961 960 if back is not None and not fcd.cmp(back):
962 961 if ui.promptchoice(_(" output file %s appears unchanged\n"
963 962 "was merge successful (yn)?"
964 963 "$$ &Yes $$ &No") % fd, 1):
965 964 r = 1
966 965
967 966 if back is not None and _toolbool(ui, tool, "fixeol"):
968 967 _matcheol(_workingpath(repo, fcd), back)
969 968
970 969 return r
971 970
972 971 def _workingpath(repo, ctx):
973 972 return repo.wjoin(ctx.path())
974 973
975 974 def premerge(repo, wctx, mynode, orig, fcd, fco, fca, labels=None):
976 975 return _filemerge(True, repo, wctx, mynode, orig, fcd, fco, fca,
977 976 labels=labels)
978 977
979 978 def filemerge(repo, wctx, mynode, orig, fcd, fco, fca, labels=None):
980 979 return _filemerge(False, repo, wctx, mynode, orig, fcd, fco, fca,
981 980 labels=labels)
982 981
983 982 def loadinternalmerge(ui, extname, registrarobj):
984 983 """Load internal merge tool from specified registrarobj
985 984 """
986 985 for name, func in registrarobj._table.iteritems():
987 986 fullname = ':' + name
988 987 internals[fullname] = func
989 988 internals['internal:' + name] = func
990 989 internalsdoc[fullname] = func
991 990
992 991 capabilities = sorted([k for k, v in func.capabilities.items() if v])
993 992 if capabilities:
994 993 capdesc = _("(actual capabilities: %s)") % ', '.join(capabilities)
995 994 func.__doc__ = (func.__doc__ +
996 995 pycompat.sysstr("\n\n %s" % capdesc))
997 996
998 997 # load built-in merge tools explicitly to setup internalsdoc
999 998 loadinternalmerge(None, None, internaltool)
1000 999
1001 1000 # tell hggettext to extract docstrings from these functions:
1002 1001 i18nfunctions = internals.values()
@@ -1,2038 +1,2050 b''
1 1 test merge-tools configuration - mostly exercising filemerge.py
2 2
3 3 $ unset HGMERGE # make sure HGMERGE doesn't interfere with the test
4 4 $ hg init repo
5 5 $ cd repo
6 6
7 7 revision 0
8 8
9 9 $ echo "revision 0" > f
10 10 $ echo "space" >> f
11 11 $ hg commit -Am "revision 0"
12 12 adding f
13 13
14 14 revision 1
15 15
16 16 $ echo "revision 1" > f
17 17 $ echo "space" >> f
18 18 $ hg commit -Am "revision 1"
19 19 $ hg update 0 > /dev/null
20 20
21 21 revision 2
22 22
23 23 $ echo "revision 2" > f
24 24 $ echo "space" >> f
25 25 $ hg commit -Am "revision 2"
26 26 created new head
27 27 $ hg update 0 > /dev/null
28 28
29 29 revision 3 - simple to merge
30 30
31 31 $ echo "revision 3" >> f
32 32 $ hg commit -Am "revision 3"
33 33 created new head
34 34
35 35 revision 4 - hard to merge
36 36
37 37 $ hg update 0 > /dev/null
38 38 $ echo "revision 4" > f
39 39 $ hg commit -Am "revision 4"
40 40 created new head
41 41
42 42 $ echo "[merge-tools]" > .hg/hgrc
43 43
44 44 $ beforemerge() {
45 45 > cat .hg/hgrc
46 46 > echo "# hg update -C 1"
47 47 > hg update -C 1 > /dev/null
48 48 > }
49 49 $ aftermerge() {
50 50 > echo "# cat f"
51 51 > cat f
52 52 > echo "# hg stat"
53 53 > hg stat
54 54 > echo "# hg resolve --list"
55 55 > hg resolve --list
56 56 > rm -f f.orig
57 57 > }
58 58
59 59 Tool selection
60 60
61 61 default is internal merge:
62 62
63 63 $ beforemerge
64 64 [merge-tools]
65 65 # hg update -C 1
66 66
67 67 hg merge -r 2
68 68 override $PATH to ensure hgmerge not visible; use $PYTHON in case we're
69 69 running from a devel copy, not a temp installation
70 70
71 71 $ PATH="$BINDIR:/usr/sbin" $PYTHON "$BINDIR"/hg merge -r 2
72 72 merging f
73 73 warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
74 74 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
75 75 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
76 76 [1]
77 77 $ aftermerge
78 78 # cat f
79 79 <<<<<<< working copy: ef83787e2614 - test: revision 1
80 80 revision 1
81 81 =======
82 82 revision 2
83 83 >>>>>>> merge rev: 0185f4e0cf02 - test: revision 2
84 84 space
85 85 # hg stat
86 86 M f
87 87 ? f.orig
88 88 # hg resolve --list
89 89 U f
90 90
91 91 simplest hgrc using false for merge:
92 92
93 93 $ echo "false.whatever=" >> .hg/hgrc
94 94 $ beforemerge
95 95 [merge-tools]
96 96 false.whatever=
97 97 # hg update -C 1
98 98 $ hg merge -r 2
99 99 merging f
100 100 merging f failed!
101 101 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
102 102 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
103 103 [1]
104 104 $ aftermerge
105 105 # cat f
106 106 revision 1
107 107 space
108 108 # hg stat
109 109 M f
110 110 ? f.orig
111 111 # hg resolve --list
112 112 U f
113 113
114 114 #if unix-permissions
115 115
116 116 unexecutable file in $PATH shouldn't be found:
117 117
118 118 $ echo "echo fail" > false
119 119 $ hg up -qC 1
120 120 $ PATH="`pwd`:$BINDIR:/usr/sbin" $PYTHON "$BINDIR"/hg merge -r 2
121 121 merging f
122 122 warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
123 123 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
124 124 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
125 125 [1]
126 126 $ rm false
127 127
128 128 #endif
129 129
130 130 executable directory in $PATH shouldn't be found:
131 131
132 132 $ mkdir false
133 133 $ hg up -qC 1
134 134 $ PATH="`pwd`:$BINDIR:/usr/sbin" $PYTHON "$BINDIR"/hg merge -r 2
135 135 merging f
136 136 warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
137 137 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
138 138 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
139 139 [1]
140 140 $ rmdir false
141 141
142 142 true with higher .priority gets precedence:
143 143
144 144 $ echo "true.priority=1" >> .hg/hgrc
145 145 $ beforemerge
146 146 [merge-tools]
147 147 false.whatever=
148 148 true.priority=1
149 149 # hg update -C 1
150 150 $ hg merge -r 2
151 151 merging f
152 152 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
153 153 (branch merge, don't forget to commit)
154 154 $ aftermerge
155 155 # cat f
156 156 revision 1
157 157 space
158 158 # hg stat
159 159 M f
160 160 # hg resolve --list
161 161 R f
162 162
163 163 unless lowered on command line:
164 164
165 165 $ beforemerge
166 166 [merge-tools]
167 167 false.whatever=
168 168 true.priority=1
169 169 # hg update -C 1
170 170 $ hg merge -r 2 --config merge-tools.true.priority=-7
171 171 merging f
172 172 merging f failed!
173 173 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
174 174 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
175 175 [1]
176 176 $ aftermerge
177 177 # cat f
178 178 revision 1
179 179 space
180 180 # hg stat
181 181 M f
182 182 ? f.orig
183 183 # hg resolve --list
184 184 U f
185 185
186 186 or false set higher on command line:
187 187
188 188 $ beforemerge
189 189 [merge-tools]
190 190 false.whatever=
191 191 true.priority=1
192 192 # hg update -C 1
193 193 $ hg merge -r 2 --config merge-tools.false.priority=117
194 194 merging f
195 195 merging f failed!
196 196 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
197 197 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
198 198 [1]
199 199 $ aftermerge
200 200 # cat f
201 201 revision 1
202 202 space
203 203 # hg stat
204 204 M f
205 205 ? f.orig
206 206 # hg resolve --list
207 207 U f
208 208
209 209 or true set to disabled:
210 210 $ beforemerge
211 211 [merge-tools]
212 212 false.whatever=
213 213 true.priority=1
214 214 # hg update -C 1
215 215 $ hg merge -r 2 --config merge-tools.true.disabled=yes
216 216 merging f
217 217 merging f failed!
218 218 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
219 219 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
220 220 [1]
221 221 $ aftermerge
222 222 # cat f
223 223 revision 1
224 224 space
225 225 # hg stat
226 226 M f
227 227 ? f.orig
228 228 # hg resolve --list
229 229 U f
230 230
231 231 or true.executable not found in PATH:
232 232
233 233 $ beforemerge
234 234 [merge-tools]
235 235 false.whatever=
236 236 true.priority=1
237 237 # hg update -C 1
238 238 $ hg merge -r 2 --config merge-tools.true.executable=nonexistentmergetool
239 239 merging f
240 240 merging f failed!
241 241 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
242 242 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
243 243 [1]
244 244 $ aftermerge
245 245 # cat f
246 246 revision 1
247 247 space
248 248 # hg stat
249 249 M f
250 250 ? f.orig
251 251 # hg resolve --list
252 252 U f
253 253
254 254 or true.executable with bogus path:
255 255
256 256 $ beforemerge
257 257 [merge-tools]
258 258 false.whatever=
259 259 true.priority=1
260 260 # hg update -C 1
261 261 $ hg merge -r 2 --config merge-tools.true.executable=/nonexistent/mergetool
262 262 merging f
263 263 merging f failed!
264 264 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
265 265 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
266 266 [1]
267 267 $ aftermerge
268 268 # cat f
269 269 revision 1
270 270 space
271 271 # hg stat
272 272 M f
273 273 ? f.orig
274 274 # hg resolve --list
275 275 U f
276 276
277 277 but true.executable set to cat found in PATH works:
278 278
279 279 $ echo "true.executable=cat" >> .hg/hgrc
280 280 $ beforemerge
281 281 [merge-tools]
282 282 false.whatever=
283 283 true.priority=1
284 284 true.executable=cat
285 285 # hg update -C 1
286 286 $ hg merge -r 2
287 287 merging f
288 288 revision 1
289 289 space
290 290 revision 0
291 291 space
292 292 revision 2
293 293 space
294 294 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
295 295 (branch merge, don't forget to commit)
296 296 $ aftermerge
297 297 # cat f
298 298 revision 1
299 299 space
300 300 # hg stat
301 301 M f
302 302 # hg resolve --list
303 303 R f
304 304
305 305 and true.executable set to cat with path works:
306 306
307 307 $ beforemerge
308 308 [merge-tools]
309 309 false.whatever=
310 310 true.priority=1
311 311 true.executable=cat
312 312 # hg update -C 1
313 313 $ hg merge -r 2 --config merge-tools.true.executable=cat
314 314 merging f
315 315 revision 1
316 316 space
317 317 revision 0
318 318 space
319 319 revision 2
320 320 space
321 321 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
322 322 (branch merge, don't forget to commit)
323 323 $ aftermerge
324 324 # cat f
325 325 revision 1
326 326 space
327 327 # hg stat
328 328 M f
329 329 # hg resolve --list
330 330 R f
331 331
332 332 executable set to python script that succeeds:
333 333
334 334 $ cat > "$TESTTMP/myworkingmerge.py" <<EOF
335 335 > def myworkingmergefn(ui, repo, args, **kwargs):
336 336 > return False
337 337 > EOF
338 338 $ beforemerge
339 339 [merge-tools]
340 340 false.whatever=
341 341 true.priority=1
342 342 true.executable=cat
343 343 # hg update -C 1
344 344 $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/myworkingmerge.py:myworkingmergefn"
345 345 merging f
346 346 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
347 347 (branch merge, don't forget to commit)
348 348 $ aftermerge
349 349 # cat f
350 350 revision 1
351 351 space
352 352 # hg stat
353 353 M f
354 354 # hg resolve --list
355 355 R f
356 356
357 357 executable set to python script that fails:
358 358
359 359 $ cat > "$TESTTMP/mybrokenmerge.py" <<EOF
360 360 > def mybrokenmergefn(ui, repo, args, **kwargs):
361 361 > ui.write(b"some fail message\n")
362 362 > return True
363 363 > EOF
364 364 $ beforemerge
365 365 [merge-tools]
366 366 false.whatever=
367 367 true.priority=1
368 368 true.executable=cat
369 369 # hg update -C 1
370 370 $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/mybrokenmerge.py:mybrokenmergefn"
371 371 merging f
372 372 some fail message
373 373 abort: $TESTTMP/mybrokenmerge.py hook failed
374 374 [255]
375 375 $ aftermerge
376 376 # cat f
377 377 revision 1
378 378 space
379 379 # hg stat
380 380 ? f.orig
381 381 # hg resolve --list
382 382 U f
383 383
384 384 executable set to python script that is missing function:
385 385
386 386 $ beforemerge
387 387 [merge-tools]
388 388 false.whatever=
389 389 true.priority=1
390 390 true.executable=cat
391 391 # hg update -C 1
392 392 $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/myworkingmerge.py:missingFunction"
393 393 merging f
394 394 abort: $TESTTMP/myworkingmerge.py does not have function: missingFunction
395 395 [255]
396 396 $ aftermerge
397 397 # cat f
398 398 revision 1
399 399 space
400 400 # hg stat
401 401 ? f.orig
402 402 # hg resolve --list
403 403 U f
404 404
405 405 executable set to missing python script:
406 406
407 407 $ beforemerge
408 408 [merge-tools]
409 409 false.whatever=
410 410 true.priority=1
411 411 true.executable=cat
412 412 # hg update -C 1
413 413 $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/missingpythonscript.py:mergefn"
414 414 merging f
415 415 abort: loading python merge script failed: $TESTTMP/missingpythonscript.py
416 416 [255]
417 417 $ aftermerge
418 418 # cat f
419 419 revision 1
420 420 space
421 421 # hg stat
422 422 ? f.orig
423 423 # hg resolve --list
424 424 U f
425 425
426 426 executable set to python script but callable function is missing:
427 427
428 428 $ beforemerge
429 429 [merge-tools]
430 430 false.whatever=
431 431 true.priority=1
432 432 true.executable=cat
433 433 # hg update -C 1
434 434 $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/myworkingmerge.py"
435 435 abort: invalid 'python:' syntax: python:$TESTTMP/myworkingmerge.py
436 436 [255]
437 437 $ aftermerge
438 438 # cat f
439 439 revision 1
440 440 space
441 441 # hg stat
442 442 # hg resolve --list
443 443 U f
444 444
445 445 executable set to python script but callable function is empty string:
446 446
447 447 $ beforemerge
448 448 [merge-tools]
449 449 false.whatever=
450 450 true.priority=1
451 451 true.executable=cat
452 452 # hg update -C 1
453 453 $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/myworkingmerge.py:"
454 454 abort: invalid 'python:' syntax: python:$TESTTMP/myworkingmerge.py:
455 455 [255]
456 456 $ aftermerge
457 457 # cat f
458 458 revision 1
459 459 space
460 460 # hg stat
461 461 # hg resolve --list
462 462 U f
463 463
464 464 executable set to python script but callable function is missing and path contains colon:
465 465
466 466 $ beforemerge
467 467 [merge-tools]
468 468 false.whatever=
469 469 true.priority=1
470 470 true.executable=cat
471 471 # hg update -C 1
472 472 $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/some:dir/myworkingmerge.py"
473 473 abort: invalid 'python:' syntax: python:$TESTTMP/some:dir/myworkingmerge.py
474 474 [255]
475 475 $ aftermerge
476 476 # cat f
477 477 revision 1
478 478 space
479 479 # hg stat
480 480 # hg resolve --list
481 481 U f
482 482
483 483 executable set to python script filename that contains spaces:
484 484
485 485 $ mkdir -p "$TESTTMP/my path"
486 486 $ cat > "$TESTTMP/my path/my working merge with spaces in filename.py" <<EOF
487 487 > def myworkingmergefn(ui, repo, args, **kwargs):
488 488 > return False
489 489 > EOF
490 490 $ beforemerge
491 491 [merge-tools]
492 492 false.whatever=
493 493 true.priority=1
494 494 true.executable=cat
495 495 # hg update -C 1
496 496 $ hg merge -r 2 --config "merge-tools.true.executable=python:$TESTTMP/my path/my working merge with spaces in filename.py:myworkingmergefn"
497 497 merging f
498 498 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
499 499 (branch merge, don't forget to commit)
500 500 $ aftermerge
501 501 # cat f
502 502 revision 1
503 503 space
504 504 # hg stat
505 505 M f
506 506 # hg resolve --list
507 507 R f
508 508
509 509 #if unix-permissions
510 510
511 511 environment variables in true.executable are handled:
512 512
513 513 $ echo 'echo "custom merge tool"' > .hg/merge.sh
514 514 $ beforemerge
515 515 [merge-tools]
516 516 false.whatever=
517 517 true.priority=1
518 518 true.executable=cat
519 519 # hg update -C 1
520 520 $ hg --config merge-tools.true.executable='sh' \
521 521 > --config merge-tools.true.args=.hg/merge.sh \
522 522 > merge -r 2
523 523 merging f
524 524 custom merge tool
525 525 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
526 526 (branch merge, don't forget to commit)
527 527 $ aftermerge
528 528 # cat f
529 529 revision 1
530 530 space
531 531 # hg stat
532 532 M f
533 533 # hg resolve --list
534 534 R f
535 535
536 536 #endif
537 537
538 538 Tool selection and merge-patterns
539 539
540 540 merge-patterns specifies new tool false:
541 541
542 542 $ beforemerge
543 543 [merge-tools]
544 544 false.whatever=
545 545 true.priority=1
546 546 true.executable=cat
547 547 # hg update -C 1
548 548 $ hg merge -r 2 --config merge-patterns.f=false
549 549 merging f
550 550 merging f failed!
551 551 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
552 552 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
553 553 [1]
554 554 $ aftermerge
555 555 # cat f
556 556 revision 1
557 557 space
558 558 # hg stat
559 559 M f
560 560 ? f.orig
561 561 # hg resolve --list
562 562 U f
563 563
564 564 merge-patterns specifies executable not found in PATH and gets warning:
565 565
566 566 $ beforemerge
567 567 [merge-tools]
568 568 false.whatever=
569 569 true.priority=1
570 570 true.executable=cat
571 571 # hg update -C 1
572 572 $ hg merge -r 2 --config merge-patterns.f=true --config merge-tools.true.executable=nonexistentmergetool
573 573 couldn't find merge tool true (for pattern f)
574 574 merging f
575 575 couldn't find merge tool true (for pattern f)
576 576 merging f failed!
577 577 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
578 578 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
579 579 [1]
580 580 $ aftermerge
581 581 # cat f
582 582 revision 1
583 583 space
584 584 # hg stat
585 585 M f
586 586 ? f.orig
587 587 # hg resolve --list
588 588 U f
589 589
590 590 merge-patterns specifies executable with bogus path and gets warning:
591 591
592 592 $ beforemerge
593 593 [merge-tools]
594 594 false.whatever=
595 595 true.priority=1
596 596 true.executable=cat
597 597 # hg update -C 1
598 598 $ hg merge -r 2 --config merge-patterns.f=true --config merge-tools.true.executable=/nonexistent/mergetool
599 599 couldn't find merge tool true (for pattern f)
600 600 merging f
601 601 couldn't find merge tool true (for pattern f)
602 602 merging f failed!
603 603 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
604 604 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
605 605 [1]
606 606 $ aftermerge
607 607 # cat f
608 608 revision 1
609 609 space
610 610 # hg stat
611 611 M f
612 612 ? f.orig
613 613 # hg resolve --list
614 614 U f
615 615
616 616 ui.merge overrules priority
617 617
618 618 ui.merge specifies false:
619 619
620 620 $ beforemerge
621 621 [merge-tools]
622 622 false.whatever=
623 623 true.priority=1
624 624 true.executable=cat
625 625 # hg update -C 1
626 626 $ hg merge -r 2 --config ui.merge=false
627 627 merging f
628 628 merging f failed!
629 629 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
630 630 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
631 631 [1]
632 632 $ aftermerge
633 633 # cat f
634 634 revision 1
635 635 space
636 636 # hg stat
637 637 M f
638 638 ? f.orig
639 639 # hg resolve --list
640 640 U f
641 641
642 642 ui.merge specifies internal:fail:
643 643
644 644 $ beforemerge
645 645 [merge-tools]
646 646 false.whatever=
647 647 true.priority=1
648 648 true.executable=cat
649 649 # hg update -C 1
650 650 $ hg merge -r 2 --config ui.merge=internal:fail
651 651 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
652 652 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
653 653 [1]
654 654 $ aftermerge
655 655 # cat f
656 656 revision 1
657 657 space
658 658 # hg stat
659 659 M f
660 660 # hg resolve --list
661 661 U f
662 662
663 663 ui.merge specifies :local (without internal prefix):
664 664
665 665 $ beforemerge
666 666 [merge-tools]
667 667 false.whatever=
668 668 true.priority=1
669 669 true.executable=cat
670 670 # hg update -C 1
671 671 $ hg merge -r 2 --config ui.merge=:local
672 672 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
673 673 (branch merge, don't forget to commit)
674 674 $ aftermerge
675 675 # cat f
676 676 revision 1
677 677 space
678 678 # hg stat
679 679 M f
680 680 # hg resolve --list
681 681 R f
682 682
683 683 ui.merge specifies internal:other:
684 684
685 685 $ beforemerge
686 686 [merge-tools]
687 687 false.whatever=
688 688 true.priority=1
689 689 true.executable=cat
690 690 # hg update -C 1
691 691 $ hg merge -r 2 --config ui.merge=internal:other
692 692 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
693 693 (branch merge, don't forget to commit)
694 694 $ aftermerge
695 695 # cat f
696 696 revision 2
697 697 space
698 698 # hg stat
699 699 M f
700 700 # hg resolve --list
701 701 R f
702 702
703 703 ui.merge specifies internal:prompt:
704 704
705 705 $ beforemerge
706 706 [merge-tools]
707 707 false.whatever=
708 708 true.priority=1
709 709 true.executable=cat
710 710 # hg update -C 1
711 711 $ hg merge -r 2 --config ui.merge=internal:prompt
712 712 keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved for f? u
713 713 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
714 714 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
715 715 [1]
716 716 $ aftermerge
717 717 # cat f
718 718 revision 1
719 719 space
720 720 # hg stat
721 721 M f
722 722 # hg resolve --list
723 723 U f
724 724
725 725 ui.merge specifies :prompt, with 'leave unresolved' chosen
726 726
727 727 $ beforemerge
728 728 [merge-tools]
729 729 false.whatever=
730 730 true.priority=1
731 731 true.executable=cat
732 732 # hg update -C 1
733 733 $ hg merge -r 2 --config ui.merge=:prompt --config ui.interactive=True << EOF
734 734 > u
735 735 > EOF
736 736 keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved for f? u
737 737 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
738 738 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
739 739 [1]
740 740 $ aftermerge
741 741 # cat f
742 742 revision 1
743 743 space
744 744 # hg stat
745 745 M f
746 746 # hg resolve --list
747 747 U f
748 748
749 749 prompt with EOF
750 750
751 751 $ beforemerge
752 752 [merge-tools]
753 753 false.whatever=
754 754 true.priority=1
755 755 true.executable=cat
756 756 # hg update -C 1
757 757 $ hg merge -r 2 --config ui.merge=internal:prompt --config ui.interactive=true
758 758 keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved for f?
759 759 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
760 760 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
761 761 [1]
762 762 $ aftermerge
763 763 # cat f
764 764 revision 1
765 765 space
766 766 # hg stat
767 767 M f
768 768 # hg resolve --list
769 769 U f
770 770 $ hg resolve --all --config ui.merge=internal:prompt --config ui.interactive=true
771 771 keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved for f?
772 772 [1]
773 773 $ aftermerge
774 774 # cat f
775 775 revision 1
776 776 space
777 777 # hg stat
778 778 M f
779 779 ? f.orig
780 780 # hg resolve --list
781 781 U f
782 782 $ rm f
783 783 $ hg resolve --all --config ui.merge=internal:prompt --config ui.interactive=true
784 784 keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved for f?
785 785 [1]
786 786 $ aftermerge
787 787 # cat f
788 788 revision 1
789 789 space
790 790 # hg stat
791 791 M f
792 792 # hg resolve --list
793 793 U f
794 794 $ hg resolve --all --config ui.merge=internal:prompt
795 795 keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved for f? u
796 796 [1]
797 797 $ aftermerge
798 798 # cat f
799 799 revision 1
800 800 space
801 801 # hg stat
802 802 M f
803 803 ? f.orig
804 804 # hg resolve --list
805 805 U f
806 806
807 807 ui.merge specifies internal:dump:
808 808
809 809 $ beforemerge
810 810 [merge-tools]
811 811 false.whatever=
812 812 true.priority=1
813 813 true.executable=cat
814 814 # hg update -C 1
815 815 $ hg merge -r 2 --config ui.merge=internal:dump
816 816 merging f
817 817 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
818 818 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
819 819 [1]
820 820 $ aftermerge
821 821 # cat f
822 822 revision 1
823 823 space
824 824 # hg stat
825 825 M f
826 826 ? f.base
827 827 ? f.local
828 828 ? f.orig
829 829 ? f.other
830 830 # hg resolve --list
831 831 U f
832 832
833 833 f.base:
834 834
835 835 $ cat f.base
836 836 revision 0
837 837 space
838 838
839 839 f.local:
840 840
841 841 $ cat f.local
842 842 revision 1
843 843 space
844 844
845 845 f.other:
846 846
847 847 $ cat f.other
848 848 revision 2
849 849 space
850 850 $ rm f.base f.local f.other
851 851
852 852 check that internal:dump doesn't dump files if premerge runs
853 853 successfully
854 854
855 855 $ beforemerge
856 856 [merge-tools]
857 857 false.whatever=
858 858 true.priority=1
859 859 true.executable=cat
860 860 # hg update -C 1
861 861 $ hg merge -r 3 --config ui.merge=internal:dump
862 862 merging f
863 863 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
864 864 (branch merge, don't forget to commit)
865 865
866 866 $ aftermerge
867 867 # cat f
868 868 revision 1
869 869 space
870 870 revision 3
871 871 # hg stat
872 872 M f
873 873 # hg resolve --list
874 874 R f
875 875
876 876 check that internal:forcedump dumps files, even if local and other can
877 877 be merged easily
878 878
879 879 $ beforemerge
880 880 [merge-tools]
881 881 false.whatever=
882 882 true.priority=1
883 883 true.executable=cat
884 884 # hg update -C 1
885 885 $ hg merge -r 3 --config ui.merge=internal:forcedump
886 886 merging f
887 887 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
888 888 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
889 889 [1]
890 890 $ aftermerge
891 891 # cat f
892 892 revision 1
893 893 space
894 894 # hg stat
895 895 M f
896 896 ? f.base
897 897 ? f.local
898 898 ? f.orig
899 899 ? f.other
900 900 # hg resolve --list
901 901 U f
902 902
903 903 $ cat f.base
904 904 revision 0
905 905 space
906 906
907 907 $ cat f.local
908 908 revision 1
909 909 space
910 910
911 911 $ cat f.other
912 912 revision 0
913 913 space
914 914 revision 3
915 915
916 916 $ rm -f f.base f.local f.other
917 917
918 918 ui.merge specifies internal:other but is overruled by pattern for false:
919 919
920 920 $ beforemerge
921 921 [merge-tools]
922 922 false.whatever=
923 923 true.priority=1
924 924 true.executable=cat
925 925 # hg update -C 1
926 926 $ hg merge -r 2 --config ui.merge=internal:other --config merge-patterns.f=false
927 927 merging f
928 928 merging f failed!
929 929 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
930 930 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
931 931 [1]
932 932 $ aftermerge
933 933 # cat f
934 934 revision 1
935 935 space
936 936 # hg stat
937 937 M f
938 938 ? f.orig
939 939 # hg resolve --list
940 940 U f
941 941
942 942 Premerge
943 943
944 944 ui.merge specifies internal:other but is overruled by --tool=false
945 945
946 946 $ beforemerge
947 947 [merge-tools]
948 948 false.whatever=
949 949 true.priority=1
950 950 true.executable=cat
951 951 # hg update -C 1
952 952 $ hg merge -r 2 --config ui.merge=internal:other --tool=false
953 953 merging f
954 954 merging f failed!
955 955 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
956 956 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
957 957 [1]
958 958 $ aftermerge
959 959 # cat f
960 960 revision 1
961 961 space
962 962 # hg stat
963 963 M f
964 964 ? f.orig
965 965 # hg resolve --list
966 966 U f
967 967
968 968 HGMERGE specifies internal:other but is overruled by --tool=false
969 969
970 970 $ HGMERGE=internal:other ; export HGMERGE
971 971 $ beforemerge
972 972 [merge-tools]
973 973 false.whatever=
974 974 true.priority=1
975 975 true.executable=cat
976 976 # hg update -C 1
977 977 $ hg merge -r 2 --tool=false
978 978 merging f
979 979 merging f failed!
980 980 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
981 981 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
982 982 [1]
983 983 $ aftermerge
984 984 # cat f
985 985 revision 1
986 986 space
987 987 # hg stat
988 988 M f
989 989 ? f.orig
990 990 # hg resolve --list
991 991 U f
992 992
993 993 $ unset HGMERGE # make sure HGMERGE doesn't interfere with remaining tests
994 994
995 995 update is a merge ...
996 996
997 997 (this also tests that files reverted with '--rev REV' are treated as
998 998 "modified", even if none of mode, size and timestamp of them isn't
999 999 changed on the filesystem (see also issue4583))
1000 1000
1001 1001 $ cat >> $HGRCPATH <<EOF
1002 1002 > [fakedirstatewritetime]
1003 1003 > # emulate invoking dirstate.write() via repo.status()
1004 1004 > # at 2000-01-01 00:00
1005 1005 > fakenow = 200001010000
1006 1006 > EOF
1007 1007
1008 1008 $ beforemerge
1009 1009 [merge-tools]
1010 1010 false.whatever=
1011 1011 true.priority=1
1012 1012 true.executable=cat
1013 1013 # hg update -C 1
1014 1014 $ hg update -q 0
1015 1015 $ f -s f
1016 1016 f: size=17
1017 1017 $ touch -t 200001010000 f
1018 1018 $ hg debugrebuildstate
1019 1019 $ cat >> $HGRCPATH <<EOF
1020 1020 > [extensions]
1021 1021 > fakedirstatewritetime = $TESTDIR/fakedirstatewritetime.py
1022 1022 > EOF
1023 1023 $ hg revert -q -r 1 .
1024 1024 $ cat >> $HGRCPATH <<EOF
1025 1025 > [extensions]
1026 1026 > fakedirstatewritetime = !
1027 1027 > EOF
1028 1028 $ f -s f
1029 1029 f: size=17
1030 1030 $ touch -t 200001010000 f
1031 1031 $ hg status f
1032 1032 M f
1033 1033 $ hg update -r 2
1034 1034 merging f
1035 1035 revision 1
1036 1036 space
1037 1037 revision 0
1038 1038 space
1039 1039 revision 2
1040 1040 space
1041 1041 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1042 1042 $ aftermerge
1043 1043 # cat f
1044 1044 revision 1
1045 1045 space
1046 1046 # hg stat
1047 1047 M f
1048 1048 # hg resolve --list
1049 1049 R f
1050 1050
1051 1051 update should also have --tool
1052 1052
1053 1053 $ beforemerge
1054 1054 [merge-tools]
1055 1055 false.whatever=
1056 1056 true.priority=1
1057 1057 true.executable=cat
1058 1058 # hg update -C 1
1059 1059 $ hg update -q 0
1060 1060 $ f -s f
1061 1061 f: size=17
1062 1062 $ touch -t 200001010000 f
1063 1063 $ hg debugrebuildstate
1064 1064 $ cat >> $HGRCPATH <<EOF
1065 1065 > [extensions]
1066 1066 > fakedirstatewritetime = $TESTDIR/fakedirstatewritetime.py
1067 1067 > EOF
1068 1068 $ hg revert -q -r 1 .
1069 1069 $ cat >> $HGRCPATH <<EOF
1070 1070 > [extensions]
1071 1071 > fakedirstatewritetime = !
1072 1072 > EOF
1073 1073 $ f -s f
1074 1074 f: size=17
1075 1075 $ touch -t 200001010000 f
1076 1076 $ hg status f
1077 1077 M f
1078 1078 $ hg update -r 2 --tool false
1079 1079 merging f
1080 1080 merging f failed!
1081 1081 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
1082 1082 use 'hg resolve' to retry unresolved file merges
1083 1083 [1]
1084 1084 $ aftermerge
1085 1085 # cat f
1086 1086 revision 1
1087 1087 space
1088 1088 # hg stat
1089 1089 M f
1090 1090 ? f.orig
1091 1091 # hg resolve --list
1092 1092 U f
1093 1093
1094 1094 Default is silent simplemerge:
1095 1095
1096 1096 $ beforemerge
1097 1097 [merge-tools]
1098 1098 false.whatever=
1099 1099 true.priority=1
1100 1100 true.executable=cat
1101 1101 # hg update -C 1
1102 1102 $ hg merge -r 3
1103 1103 merging f
1104 1104 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1105 1105 (branch merge, don't forget to commit)
1106 1106 $ aftermerge
1107 1107 # cat f
1108 1108 revision 1
1109 1109 space
1110 1110 revision 3
1111 1111 # hg stat
1112 1112 M f
1113 1113 # hg resolve --list
1114 1114 R f
1115 1115
1116 1116 .premerge=True is same:
1117 1117
1118 1118 $ beforemerge
1119 1119 [merge-tools]
1120 1120 false.whatever=
1121 1121 true.priority=1
1122 1122 true.executable=cat
1123 1123 # hg update -C 1
1124 1124 $ hg merge -r 3 --config merge-tools.true.premerge=True
1125 1125 merging f
1126 1126 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1127 1127 (branch merge, don't forget to commit)
1128 1128 $ aftermerge
1129 1129 # cat f
1130 1130 revision 1
1131 1131 space
1132 1132 revision 3
1133 1133 # hg stat
1134 1134 M f
1135 1135 # hg resolve --list
1136 1136 R f
1137 1137
1138 1138 .premerge=False executes merge-tool:
1139 1139
1140 1140 $ beforemerge
1141 1141 [merge-tools]
1142 1142 false.whatever=
1143 1143 true.priority=1
1144 1144 true.executable=cat
1145 1145 # hg update -C 1
1146 1146 $ hg merge -r 3 --config merge-tools.true.premerge=False
1147 1147 merging f
1148 1148 revision 1
1149 1149 space
1150 1150 revision 0
1151 1151 space
1152 1152 revision 0
1153 1153 space
1154 1154 revision 3
1155 1155 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1156 1156 (branch merge, don't forget to commit)
1157 1157 $ aftermerge
1158 1158 # cat f
1159 1159 revision 1
1160 1160 space
1161 1161 # hg stat
1162 1162 M f
1163 1163 # hg resolve --list
1164 1164 R f
1165 1165
1166 1166 premerge=keep keeps conflict markers in:
1167 1167
1168 1168 $ beforemerge
1169 1169 [merge-tools]
1170 1170 false.whatever=
1171 1171 true.priority=1
1172 1172 true.executable=cat
1173 1173 # hg update -C 1
1174 1174 $ hg merge -r 4 --config merge-tools.true.premerge=keep
1175 1175 merging f
1176 1176 <<<<<<< working copy: ef83787e2614 - test: revision 1
1177 1177 revision 1
1178 1178 space
1179 1179 =======
1180 1180 revision 4
1181 1181 >>>>>>> merge rev: 81448d39c9a0 - test: revision 4
1182 1182 revision 0
1183 1183 space
1184 1184 revision 4
1185 1185 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1186 1186 (branch merge, don't forget to commit)
1187 1187 $ aftermerge
1188 1188 # cat f
1189 1189 <<<<<<< working copy: ef83787e2614 - test: revision 1
1190 1190 revision 1
1191 1191 space
1192 1192 =======
1193 1193 revision 4
1194 1194 >>>>>>> merge rev: 81448d39c9a0 - test: revision 4
1195 1195 # hg stat
1196 1196 M f
1197 1197 # hg resolve --list
1198 1198 R f
1199 1199
1200 1200 premerge=keep-merge3 keeps conflict markers with base content:
1201 1201
1202 1202 $ beforemerge
1203 1203 [merge-tools]
1204 1204 false.whatever=
1205 1205 true.priority=1
1206 1206 true.executable=cat
1207 1207 # hg update -C 1
1208 1208 $ hg merge -r 4 --config merge-tools.true.premerge=keep-merge3
1209 1209 merging f
1210 1210 <<<<<<< working copy: ef83787e2614 - test: revision 1
1211 1211 revision 1
1212 1212 space
1213 1213 ||||||| base
1214 1214 revision 0
1215 1215 space
1216 1216 =======
1217 1217 revision 4
1218 1218 >>>>>>> merge rev: 81448d39c9a0 - test: revision 4
1219 1219 revision 0
1220 1220 space
1221 1221 revision 4
1222 1222 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1223 1223 (branch merge, don't forget to commit)
1224 1224 $ aftermerge
1225 1225 # cat f
1226 1226 <<<<<<< working copy: ef83787e2614 - test: revision 1
1227 1227 revision 1
1228 1228 space
1229 1229 ||||||| base
1230 1230 revision 0
1231 1231 space
1232 1232 =======
1233 1233 revision 4
1234 1234 >>>>>>> merge rev: 81448d39c9a0 - test: revision 4
1235 1235 # hg stat
1236 1236 M f
1237 1237 # hg resolve --list
1238 1238 R f
1239 1239
1240 1240 premerge=keep respects ui.mergemarkers=basic:
1241 1241
1242 1242 $ beforemerge
1243 1243 [merge-tools]
1244 1244 false.whatever=
1245 1245 true.priority=1
1246 1246 true.executable=cat
1247 1247 # hg update -C 1
1248 1248 $ hg merge -r 4 --config merge-tools.true.premerge=keep --config ui.mergemarkers=basic
1249 1249 merging f
1250 1250 <<<<<<< working copy
1251 1251 revision 1
1252 1252 space
1253 1253 =======
1254 1254 revision 4
1255 1255 >>>>>>> merge rev
1256 1256 revision 0
1257 1257 space
1258 1258 revision 4
1259 1259 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1260 1260 (branch merge, don't forget to commit)
1261 1261 $ aftermerge
1262 1262 # cat f
1263 1263 <<<<<<< working copy
1264 1264 revision 1
1265 1265 space
1266 1266 =======
1267 1267 revision 4
1268 1268 >>>>>>> merge rev
1269 1269 # hg stat
1270 1270 M f
1271 1271 # hg resolve --list
1272 1272 R f
1273 1273
1274 1274 premerge=keep ignores ui.mergemarkers=basic if true.mergemarkers=detailed:
1275 1275
1276 1276 $ beforemerge
1277 1277 [merge-tools]
1278 1278 false.whatever=
1279 1279 true.priority=1
1280 1280 true.executable=cat
1281 1281 # hg update -C 1
1282 1282 $ hg merge -r 4 --config merge-tools.true.premerge=keep \
1283 1283 > --config ui.mergemarkers=basic \
1284 1284 > --config merge-tools.true.mergemarkers=detailed
1285 1285 merging f
1286 1286 <<<<<<< working copy: ef83787e2614 - test: revision 1
1287 1287 revision 1
1288 1288 space
1289 1289 =======
1290 1290 revision 4
1291 1291 >>>>>>> merge rev: 81448d39c9a0 - test: revision 4
1292 1292 revision 0
1293 1293 space
1294 1294 revision 4
1295 1295 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1296 1296 (branch merge, don't forget to commit)
1297 1297 $ aftermerge
1298 1298 # cat f
1299 1299 <<<<<<< working copy: ef83787e2614 - test: revision 1
1300 1300 revision 1
1301 1301 space
1302 1302 =======
1303 1303 revision 4
1304 1304 >>>>>>> merge rev: 81448d39c9a0 - test: revision 4
1305 1305 # hg stat
1306 1306 M f
1307 1307 # hg resolve --list
1308 1308 R f
1309 1309
1310 1310 premerge=keep respects ui.mergemarkertemplate instead of
1311 1311 true.mergemarkertemplate if true.mergemarkers=basic:
1312 1312
1313 1313 $ beforemerge
1314 1314 [merge-tools]
1315 1315 false.whatever=
1316 1316 true.priority=1
1317 1317 true.executable=cat
1318 1318 # hg update -C 1
1319 1319 $ hg merge -r 4 --config merge-tools.true.premerge=keep \
1320 1320 > --config ui.mergemarkertemplate='uitmpl {rev}' \
1321 1321 > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}'
1322 1322 merging f
1323 1323 <<<<<<< working copy: uitmpl 1
1324 1324 revision 1
1325 1325 space
1326 1326 =======
1327 1327 revision 4
1328 1328 >>>>>>> merge rev: uitmpl 4
1329 1329 revision 0
1330 1330 space
1331 1331 revision 4
1332 1332 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1333 1333 (branch merge, don't forget to commit)
1334 1334 $ aftermerge
1335 1335 # cat f
1336 1336 <<<<<<< working copy: uitmpl 1
1337 1337 revision 1
1338 1338 space
1339 1339 =======
1340 1340 revision 4
1341 1341 >>>>>>> merge rev: uitmpl 4
1342 1342 # hg stat
1343 1343 M f
1344 1344 # hg resolve --list
1345 1345 R f
1346 1346
1347 1347 premerge=keep respects true.mergemarkertemplate instead of
1348 1348 true.mergemarkertemplate if true.mergemarkers=detailed:
1349 1349
1350 1350 $ beforemerge
1351 1351 [merge-tools]
1352 1352 false.whatever=
1353 1353 true.priority=1
1354 1354 true.executable=cat
1355 1355 # hg update -C 1
1356 1356 $ hg merge -r 4 --config merge-tools.true.premerge=keep \
1357 1357 > --config ui.mergemarkertemplate='uitmpl {rev}' \
1358 1358 > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \
1359 1359 > --config merge-tools.true.mergemarkers=detailed
1360 1360 merging f
1361 1361 <<<<<<< working copy: tooltmpl ef83787e2614
1362 1362 revision 1
1363 1363 space
1364 1364 =======
1365 1365 revision 4
1366 1366 >>>>>>> merge rev: tooltmpl 81448d39c9a0
1367 1367 revision 0
1368 1368 space
1369 1369 revision 4
1370 1370 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1371 1371 (branch merge, don't forget to commit)
1372 1372 $ aftermerge
1373 1373 # cat f
1374 1374 <<<<<<< working copy: tooltmpl ef83787e2614
1375 1375 revision 1
1376 1376 space
1377 1377 =======
1378 1378 revision 4
1379 1379 >>>>>>> merge rev: tooltmpl 81448d39c9a0
1380 1380 # hg stat
1381 1381 M f
1382 1382 # hg resolve --list
1383 1383 R f
1384 1384
1385 1385 Tool execution
1386 1386
1387 1387 set tools.args explicit to include $base $local $other $output:
1388 1388
1389 1389 $ beforemerge
1390 1390 [merge-tools]
1391 1391 false.whatever=
1392 1392 true.priority=1
1393 1393 true.executable=cat
1394 1394 # hg update -C 1
1395 1395 $ hg merge -r 2 --config merge-tools.true.executable=head --config merge-tools.true.args='$base $local $other $output' \
1396 1396 > | sed 's,==> .* <==,==> ... <==,g'
1397 1397 merging f
1398 1398 ==> ... <==
1399 1399 revision 0
1400 1400 space
1401 1401
1402 1402 ==> ... <==
1403 1403 revision 1
1404 1404 space
1405 1405
1406 1406 ==> ... <==
1407 1407 revision 2
1408 1408 space
1409 1409
1410 1410 ==> ... <==
1411 1411 revision 1
1412 1412 space
1413 1413 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1414 1414 (branch merge, don't forget to commit)
1415 1415 $ aftermerge
1416 1416 # cat f
1417 1417 revision 1
1418 1418 space
1419 1419 # hg stat
1420 1420 M f
1421 1421 # hg resolve --list
1422 1422 R f
1423 1423
1424 1424 Merge with "echo mergeresult > $local":
1425 1425
1426 1426 $ beforemerge
1427 1427 [merge-tools]
1428 1428 false.whatever=
1429 1429 true.priority=1
1430 1430 true.executable=cat
1431 1431 # hg update -C 1
1432 1432 $ hg merge -r 2 --config merge-tools.true.executable=echo --config merge-tools.true.args='mergeresult > $local'
1433 1433 merging f
1434 1434 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1435 1435 (branch merge, don't forget to commit)
1436 1436 $ aftermerge
1437 1437 # cat f
1438 1438 mergeresult
1439 1439 # hg stat
1440 1440 M f
1441 1441 # hg resolve --list
1442 1442 R f
1443 1443
1444 1444 - and $local is the file f:
1445 1445
1446 1446 $ beforemerge
1447 1447 [merge-tools]
1448 1448 false.whatever=
1449 1449 true.priority=1
1450 1450 true.executable=cat
1451 1451 # hg update -C 1
1452 1452 $ hg merge -r 2 --config merge-tools.true.executable=echo --config merge-tools.true.args='mergeresult > f'
1453 1453 merging f
1454 1454 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1455 1455 (branch merge, don't forget to commit)
1456 1456 $ aftermerge
1457 1457 # cat f
1458 1458 mergeresult
1459 1459 # hg stat
1460 1460 M f
1461 1461 # hg resolve --list
1462 1462 R f
1463 1463
1464 1464 Merge with "echo mergeresult > $output" - the variable is a bit magic:
1465 1465
1466 1466 $ beforemerge
1467 1467 [merge-tools]
1468 1468 false.whatever=
1469 1469 true.priority=1
1470 1470 true.executable=cat
1471 1471 # hg update -C 1
1472 1472 $ hg merge -r 2 --config merge-tools.true.executable=echo --config merge-tools.true.args='mergeresult > $output'
1473 1473 merging f
1474 1474 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1475 1475 (branch merge, don't forget to commit)
1476 1476 $ aftermerge
1477 1477 # cat f
1478 1478 mergeresult
1479 1479 # hg stat
1480 1480 M f
1481 1481 # hg resolve --list
1482 1482 R f
1483 1483
1484 1484 Merge using tool with a path that must be quoted:
1485 1485
1486 1486 $ beforemerge
1487 1487 [merge-tools]
1488 1488 false.whatever=
1489 1489 true.priority=1
1490 1490 true.executable=cat
1491 1491 # hg update -C 1
1492 1492 $ cat <<EOF > 'my merge tool'
1493 1493 > cat "\$1" "\$2" "\$3" > "\$4"
1494 1494 > EOF
1495 1495 $ hg --config merge-tools.true.executable='sh' \
1496 1496 > --config merge-tools.true.args='"./my merge tool" $base $local $other $output' \
1497 1497 > merge -r 2
1498 1498 merging f
1499 1499 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1500 1500 (branch merge, don't forget to commit)
1501 1501 $ rm -f 'my merge tool'
1502 1502 $ aftermerge
1503 1503 # cat f
1504 1504 revision 0
1505 1505 space
1506 1506 revision 1
1507 1507 space
1508 1508 revision 2
1509 1509 space
1510 1510 # hg stat
1511 1511 M f
1512 1512 # hg resolve --list
1513 1513 R f
1514 1514
1515 1515 Merge using a tool that supports labellocal, labelother, and labelbase, checking
1516 1516 that they're quoted properly as well. This is using the default 'basic'
1517 1517 mergemarkers even though ui.mergemarkers is 'detailed', so it's ignoring both
1518 1518 mergemarkertemplate settings:
1519 1519
1520 1520 $ beforemerge
1521 1521 [merge-tools]
1522 1522 false.whatever=
1523 1523 true.priority=1
1524 1524 true.executable=cat
1525 1525 # hg update -C 1
1526 1526 $ cat <<EOF > printargs_merge_tool
1527 1527 > while test \$# -gt 0; do echo arg: \"\$1\"; shift; done
1528 1528 > EOF
1529 1529 $ hg --config merge-tools.true.executable='sh' \
1530 1530 > --config merge-tools.true.args='./printargs_merge_tool ll:$labellocal lo: $labelother lb:$labelbase": "$base' \
1531 1531 > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \
1532 1532 > --config ui.mergemarkertemplate='uitmpl {rev}' \
1533 1533 > --config ui.mergemarkers=detailed \
1534 1534 > merge -r 2
1535 1535 merging f
1536 1536 arg: "ll:working copy"
1537 1537 arg: "lo:"
1538 1538 arg: "merge rev"
1539 1539 arg: "lb:base: */f~base.*" (glob)
1540 1540 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1541 1541 (branch merge, don't forget to commit)
1542 1542 $ rm -f 'printargs_merge_tool'
1543 1543
1544 1544 Same test with experimental.mergetempdirprefix set:
1545 1545
1546 1546 $ beforemerge
1547 1547 [merge-tools]
1548 1548 false.whatever=
1549 1549 true.priority=1
1550 1550 true.executable=cat
1551 1551 # hg update -C 1
1552 1552 $ cat <<EOF > printargs_merge_tool
1553 1553 > while test \$# -gt 0; do echo arg: \"\$1\"; shift; done
1554 1554 > EOF
1555 1555 $ hg --config experimental.mergetempdirprefix=$TESTTMP/hgmerge. \
1556 1556 > --config merge-tools.true.executable='sh' \
1557 1557 > --config merge-tools.true.args='./printargs_merge_tool ll:$labellocal lo: $labelother lb:$labelbase": "$base' \
1558 1558 > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \
1559 1559 > --config ui.mergemarkertemplate='uitmpl {rev}' \
1560 1560 > --config ui.mergemarkers=detailed \
1561 1561 > merge -r 2
1562 1562 merging f
1563 1563 arg: "ll:working copy"
1564 1564 arg: "lo:"
1565 1565 arg: "merge rev"
1566 1566 arg: "lb:base: */hgmerge.*/f~base" (glob)
1567 1567 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1568 1568 (branch merge, don't forget to commit)
1569 1569 $ rm -f 'printargs_merge_tool'
1570 1570
1571 1571 Merge using a tool that supports labellocal, labelother, and labelbase, checking
1572 1572 that they're quoted properly as well. This is using 'detailed' mergemarkers,
1573 1573 even though ui.mergemarkers is 'basic', and using the tool's
1574 1574 mergemarkertemplate:
1575 1575
1576 1576 $ beforemerge
1577 1577 [merge-tools]
1578 1578 false.whatever=
1579 1579 true.priority=1
1580 1580 true.executable=cat
1581 1581 # hg update -C 1
1582 1582 $ cat <<EOF > printargs_merge_tool
1583 1583 > while test \$# -gt 0; do echo arg: \"\$1\"; shift; done
1584 1584 > EOF
1585 1585 $ hg --config merge-tools.true.executable='sh' \
1586 1586 > --config merge-tools.true.args='./printargs_merge_tool ll:$labellocal lo: $labelother lb:$labelbase": "$base' \
1587 1587 > --config merge-tools.true.mergemarkers=detailed \
1588 1588 > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \
1589 1589 > --config ui.mergemarkertemplate='uitmpl {rev}' \
1590 1590 > --config ui.mergemarkers=basic \
1591 1591 > merge -r 2
1592 1592 merging f
1593 1593 arg: "ll:working copy: tooltmpl ef83787e2614"
1594 1594 arg: "lo:"
1595 1595 arg: "merge rev: tooltmpl 0185f4e0cf02"
1596 1596 arg: "lb:base: */f~base.*" (glob)
1597 1597 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1598 1598 (branch merge, don't forget to commit)
1599 1599 $ rm -f 'printargs_merge_tool'
1600 1600
1601 1601 The merge tool still gets labellocal and labelother as 'basic' even when
1602 1602 premerge=keep is used and has 'detailed' markers:
1603 1603
1604 1604 $ beforemerge
1605 1605 [merge-tools]
1606 1606 false.whatever=
1607 1607 true.priority=1
1608 1608 true.executable=cat
1609 1609 # hg update -C 1
1610 1610 $ cat <<EOF > mytool
1611 1611 > echo labellocal: \"\$1\"
1612 1612 > echo labelother: \"\$2\"
1613 1613 > echo "output (arg)": \"\$3\"
1614 1614 > echo "output (contents)":
1615 1615 > cat "\$3"
1616 1616 > EOF
1617 1617 $ hg --config merge-tools.true.executable='sh' \
1618 1618 > --config merge-tools.true.args='mytool $labellocal $labelother $output' \
1619 1619 > --config merge-tools.true.premerge=keep \
1620 1620 > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \
1621 1621 > --config ui.mergemarkertemplate='uitmpl {rev}' \
1622 1622 > --config ui.mergemarkers=detailed \
1623 1623 > merge -r 2
1624 1624 merging f
1625 1625 labellocal: "working copy"
1626 1626 labelother: "merge rev"
1627 1627 output (arg): "$TESTTMP/repo/f"
1628 1628 output (contents):
1629 1629 <<<<<<< working copy: uitmpl 1
1630 1630 revision 1
1631 1631 =======
1632 1632 revision 2
1633 1633 >>>>>>> merge rev: uitmpl 2
1634 1634 space
1635 1635 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1636 1636 (branch merge, don't forget to commit)
1637 1637 $ rm -f 'mytool'
1638 1638
1639 1639 premerge=keep uses the *tool's* mergemarkertemplate if tool's
1640 1640 mergemarkers=detailed; labellocal and labelother also use the tool's template
1641 1641
1642 1642 $ beforemerge
1643 1643 [merge-tools]
1644 1644 false.whatever=
1645 1645 true.priority=1
1646 1646 true.executable=cat
1647 1647 # hg update -C 1
1648 1648 $ cat <<EOF > mytool
1649 1649 > echo labellocal: \"\$1\"
1650 1650 > echo labelother: \"\$2\"
1651 1651 > echo "output (arg)": \"\$3\"
1652 1652 > echo "output (contents)":
1653 1653 > cat "\$3"
1654 1654 > EOF
1655 1655 $ hg --config merge-tools.true.executable='sh' \
1656 1656 > --config merge-tools.true.args='mytool $labellocal $labelother $output' \
1657 1657 > --config merge-tools.true.premerge=keep \
1658 1658 > --config merge-tools.true.mergemarkers=detailed \
1659 1659 > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \
1660 1660 > --config ui.mergemarkertemplate='uitmpl {rev}' \
1661 1661 > --config ui.mergemarkers=detailed \
1662 1662 > merge -r 2
1663 1663 merging f
1664 1664 labellocal: "working copy: tooltmpl ef83787e2614"
1665 1665 labelother: "merge rev: tooltmpl 0185f4e0cf02"
1666 1666 output (arg): "$TESTTMP/repo/f"
1667 1667 output (contents):
1668 1668 <<<<<<< working copy: tooltmpl ef83787e2614
1669 1669 revision 1
1670 1670 =======
1671 1671 revision 2
1672 1672 >>>>>>> merge rev: tooltmpl 0185f4e0cf02
1673 1673 space
1674 1674 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1675 1675 (branch merge, don't forget to commit)
1676 1676 $ rm -f 'mytool'
1677 1677
1678 1678 Issue3581: Merging a filename that needs to be quoted
1679 1679 (This test doesn't work on Windows filesystems even on Linux, so check
1680 1680 for Unix-like permission)
1681 1681
1682 1682 #if unix-permissions
1683 1683 $ beforemerge
1684 1684 [merge-tools]
1685 1685 false.whatever=
1686 1686 true.priority=1
1687 1687 true.executable=cat
1688 1688 # hg update -C 1
1689 1689 $ echo "revision 5" > '"; exit 1; echo "'
1690 1690 $ hg commit -Am "revision 5"
1691 1691 adding "; exit 1; echo "
1692 1692 warning: filename contains '"', which is reserved on Windows: '"; exit 1; echo "'
1693 1693 $ hg update -C 1 > /dev/null
1694 1694 $ echo "revision 6" > '"; exit 1; echo "'
1695 1695 $ hg commit -Am "revision 6"
1696 1696 adding "; exit 1; echo "
1697 1697 warning: filename contains '"', which is reserved on Windows: '"; exit 1; echo "'
1698 1698 created new head
1699 1699 $ hg merge --config merge-tools.true.executable="true" -r 5
1700 1700 merging "; exit 1; echo "
1701 1701 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1702 1702 (branch merge, don't forget to commit)
1703 1703 $ hg update -C 1 > /dev/null
1704 1704
1705 1705 #else
1706 1706
1707 1707 Match the non-portable filename commits above for test stability
1708 1708
1709 1709 $ hg import --bypass -q - << EOF
1710 1710 > # HG changeset patch
1711 1711 > revision 5
1712 1712 >
1713 1713 > diff --git a/"; exit 1; echo " b/"; exit 1; echo "
1714 1714 > new file mode 100644
1715 1715 > --- /dev/null
1716 1716 > +++ b/"; exit 1; echo "
1717 1717 > @@ -0,0 +1,1 @@
1718 1718 > +revision 5
1719 1719 > EOF
1720 1720
1721 1721 $ hg import --bypass -q - << EOF
1722 1722 > # HG changeset patch
1723 1723 > revision 6
1724 1724 >
1725 1725 > diff --git a/"; exit 1; echo " b/"; exit 1; echo "
1726 1726 > new file mode 100644
1727 1727 > --- /dev/null
1728 1728 > +++ b/"; exit 1; echo "
1729 1729 > @@ -0,0 +1,1 @@
1730 1730 > +revision 6
1731 1731 > EOF
1732 1732
1733 1733 #endif
1734 1734
1735 1735 Merge post-processing
1736 1736
1737 1737 cat is a bad merge-tool and doesn't change:
1738 1738
1739 1739 $ beforemerge
1740 1740 [merge-tools]
1741 1741 false.whatever=
1742 1742 true.priority=1
1743 1743 true.executable=cat
1744 1744 # hg update -C 1
1745 1745 $ hg merge -y -r 2 --config merge-tools.true.checkchanged=1
1746 1746 merging f
1747 1747 revision 1
1748 1748 space
1749 1749 revision 0
1750 1750 space
1751 1751 revision 2
1752 1752 space
1753 1753 output file f appears unchanged
1754 1754 was merge successful (yn)? n
1755 1755 merging f failed!
1756 1756 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
1757 1757 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
1758 1758 [1]
1759 1759 $ aftermerge
1760 1760 # cat f
1761 1761 revision 1
1762 1762 space
1763 1763 # hg stat
1764 1764 M f
1765 1765 ? f.orig
1766 1766 # hg resolve --list
1767 1767 U f
1768 1768
1769 1769 missingbinary is a merge-tool that doesn't exist:
1770 1770
1771 1771 $ echo "missingbinary.executable=doesnotexist" >> .hg/hgrc
1772 1772 $ beforemerge
1773 1773 [merge-tools]
1774 1774 false.whatever=
1775 1775 true.priority=1
1776 1776 true.executable=cat
1777 1777 missingbinary.executable=doesnotexist
1778 1778 # hg update -C 1
1779 1779 $ hg merge -y -r 2 --config ui.merge=missingbinary
1780 1780 couldn't find merge tool missingbinary (for pattern f)
1781 1781 merging f
1782 1782 couldn't find merge tool missingbinary (for pattern f)
1783 1783 revision 1
1784 1784 space
1785 1785 revision 0
1786 1786 space
1787 1787 revision 2
1788 1788 space
1789 1789 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1790 1790 (branch merge, don't forget to commit)
1791 1791
1792 1792 $ hg update -q -C 1
1793 1793 $ rm f
1794 1794
1795 1795 internal merge cannot handle symlinks and shouldn't try:
1796 1796
1797 1797 #if symlink
1798 1798
1799 1799 $ ln -s symlink f
1800 1800 $ hg commit -qm 'f is symlink'
1801 1801
1802 1802 #else
1803 1803
1804 1804 $ hg import --bypass -q - << EOF
1805 1805 > # HG changeset patch
1806 1806 > f is symlink
1807 1807 >
1808 1808 > diff --git a/f b/f
1809 1809 > old mode 100644
1810 1810 > new mode 120000
1811 1811 > --- a/f
1812 1812 > +++ b/f
1813 1813 > @@ -1,2 +1,1 @@
1814 1814 > -revision 1
1815 1815 > -space
1816 1816 > +symlink
1817 1817 > \ No newline at end of file
1818 1818 > EOF
1819 1819
1820 1820 Resolve 'other [destination] changed f which local [working copy] deleted' prompt
1821 1821 $ hg up -q -C --config ui.interactive=True << EOF
1822 1822 > c
1823 1823 > EOF
1824 1824
1825 1825 #endif
1826 1826
1827 1827 $ hg merge -r 2 --tool internal:merge
1828 1828 merging f
1829 1829 warning: internal :merge cannot merge symlinks for f
1830 1830 warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
1831 1831 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
1832 1832 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
1833 1833 [1]
1834 1834
1835 1835 Verify naming of temporary files and that extension is preserved:
1836 1836
1837 1837 $ hg update -q -C 1
1838 1838 $ hg mv f f.txt
1839 1839 $ hg ci -qm "f.txt"
1840 1840 $ hg update -q -C 2
1841 1841 $ hg merge -y -r tip --tool echo --config merge-tools.echo.args='$base $local $other $output'
1842 1842 merging f and f.txt to f.txt
1843 1843 */f~base.* */f~local.*.txt */f~other.*.txt $TESTTMP/repo/f.txt (glob)
1844 1844 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1845 1845 (branch merge, don't forget to commit)
1846 1846
1847 1847 Verify naming of temporary files and that extension is preserved
1848 1848 (experimental.mergetempdirprefix version):
1849 1849
1850 1850 $ hg update -q -C 1
1851 1851 $ hg mv f f.txt
1852 1852 $ hg ci -qm "f.txt"
1853 1853 $ hg update -q -C 2
1854 1854 $ hg merge -y -r tip --tool echo \
1855 1855 > --config merge-tools.echo.args='$base $local $other $output' \
1856 1856 > --config experimental.mergetempdirprefix=$TESTTMP/hgmerge.
1857 1857 merging f and f.txt to f.txt
1858 1858 $TESTTMP/hgmerge.*/f~base $TESTTMP/hgmerge.*/f~local.txt $TESTTMP/hgmerge.*/f~other.txt $TESTTMP/repo/f.txt (glob)
1859 1859 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1860 1860 (branch merge, don't forget to commit)
1861 1861
1862 1862 Binary files capability checking
1863 1863
1864 1864 $ hg update -q -C 0
1865 1865 $ python <<EOF
1866 1866 > with open('b', 'wb') as fp:
1867 1867 > fp.write(b'\x00\x01\x02\x03')
1868 1868 > EOF
1869 1869 $ hg add b
1870 1870 $ hg commit -qm "add binary file (#1)"
1871 1871
1872 1872 $ hg update -q -C 0
1873 1873 $ python <<EOF
1874 1874 > with open('b', 'wb') as fp:
1875 1875 > fp.write(b'\x03\x02\x01\x00')
1876 1876 > EOF
1877 1877 $ hg add b
1878 1878 $ hg commit -qm "add binary file (#2)"
1879 1879
1880 1880 By default, binary files capability of internal merge tools is not
1881 1881 checked strictly.
1882 1882
1883 1883 (for merge-patterns, chosen unintentionally)
1884 1884
1885 1885 $ hg merge 9 \
1886 1886 > --config merge-patterns.b=:merge-other \
1887 1887 > --config merge-patterns.re:[a-z]=:other
1888 1888 warning: check merge-patterns configurations, if ':merge-other' for binary file 'b' is unintentional
1889 1889 (see 'hg help merge-tools' for binary files capability)
1890 1890 merging b
1891 1891 warning: b looks like a binary file.
1892 1892 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
1893 1893 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
1894 1894 [1]
1895 1895 $ hg merge --abort -q
1896 1896
1897 1897 (for ui.merge, ignored unintentionally)
1898 1898
1899 1899 $ hg merge 9 \
1900 > --config merge-tools.:other.binary=true \
1900 1901 > --config ui.merge=:other
1901 1902 tool :other (for pattern b) can't handle binary
1902 1903 tool true can't handle binary
1904 tool :other can't handle binary
1903 1905 tool false can't handle binary
1904 1906 no tool found to merge b
1905 1907 keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved for b? u
1906 1908 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
1907 1909 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
1908 1910 [1]
1909 1911 $ hg merge --abort -q
1910 1912
1911 1913 With merge.strict-capability-check=true, binary files capability of
1912 1914 internal merge tools is checked strictly.
1913 1915
1914 1916 $ f --hexdump b
1915 1917 b:
1916 1918 0000: 03 02 01 00 |....|
1917 1919
1918 1920 (for merge-patterns)
1919 1921
1920 1922 $ hg merge 9 --config merge.strict-capability-check=true \
1923 > --config merge-tools.:merge-other.binary=true \
1921 1924 > --config merge-patterns.b=:merge-other \
1922 1925 > --config merge-patterns.re:[a-z]=:other
1923 1926 tool :merge-other (for pattern b) can't handle binary
1924 1927 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1925 1928 (branch merge, don't forget to commit)
1926 1929 $ f --hexdump b
1927 1930 b:
1928 1931 0000: 00 01 02 03 |....|
1929 1932 $ hg merge --abort -q
1930 1933
1931 1934 (for ui.merge)
1932 1935
1933 1936 $ hg merge 9 --config merge.strict-capability-check=true \
1934 1937 > --config ui.merge=:other
1935 1938 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1936 1939 (branch merge, don't forget to commit)
1937 1940 $ f --hexdump b
1938 1941 b:
1939 1942 0000: 00 01 02 03 |....|
1940 1943 $ hg merge --abort -q
1941 1944
1942 1945 Check that debugpicktool examines which merge tool is chosen for
1943 1946 specified file as expected
1944 1947
1945 1948 $ beforemerge
1946 1949 [merge-tools]
1947 1950 false.whatever=
1948 1951 true.priority=1
1949 1952 true.executable=cat
1950 1953 missingbinary.executable=doesnotexist
1951 1954 # hg update -C 1
1952 1955
1953 1956 (default behavior: checking files in the working parent context)
1954 1957
1955 1958 $ hg manifest
1956 1959 f
1957 1960 $ hg debugpickmergetool
1958 1961 f = true
1959 1962
1960 1963 (-X/-I and file patterns limmit examination targets)
1961 1964
1962 1965 $ hg debugpickmergetool -X f
1963 1966 $ hg debugpickmergetool unknown
1964 1967 unknown: no such file in rev ef83787e2614
1965 1968
1966 1969 (--changedelete emulates merging change and delete)
1967 1970
1968 1971 $ hg debugpickmergetool --changedelete
1969 1972 f = :prompt
1970 1973
1971 1974 (-r REV causes checking files in specified revision)
1972 1975
1973 1976 $ hg manifest -r 8
1974 1977 f.txt
1975 1978 $ hg debugpickmergetool -r 8
1976 1979 f.txt = true
1977 1980
1978 1981 #if symlink
1979 1982
1980 1983 (symlink causes chosing :prompt)
1981 1984
1982 1985 $ hg debugpickmergetool -r 6d00b3726f6e
1983 1986 f = :prompt
1984 1987
1985 1988 (by default, it is assumed that no internal merge tools has symlinks
1986 1989 capability)
1987 1990
1988 1991 $ hg debugpickmergetool \
1989 1992 > -r 6d00b3726f6e \
1993 > --config merge-tools.:merge-other.symlink=true \
1990 1994 > --config merge-patterns.f=:merge-other \
1991 1995 > --config merge-patterns.re:[f]=:merge-local \
1992 1996 > --config merge-patterns.re:[a-z]=:other
1993 1997 f = :prompt
1994 1998
1995 1999 $ hg debugpickmergetool \
1996 2000 > -r 6d00b3726f6e \
2001 > --config merge-tools.:other.symlink=true \
1997 2002 > --config ui.merge=:other
1998 2003 f = :prompt
1999 2004
2000 2005 (with strict-capability-check=true, actual symlink capabilities are
2001 2006 checked striclty)
2002 2007
2003 2008 $ hg debugpickmergetool --config merge.strict-capability-check=true \
2004 2009 > -r 6d00b3726f6e \
2010 > --config merge-tools.:merge-other.symlink=true \
2005 2011 > --config merge-patterns.f=:merge-other \
2006 2012 > --config merge-patterns.re:[f]=:merge-local \
2007 2013 > --config merge-patterns.re:[a-z]=:other
2008 2014 f = :other
2009 2015
2010 2016 $ hg debugpickmergetool --config merge.strict-capability-check=true \
2011 2017 > -r 6d00b3726f6e \
2012 2018 > --config ui.merge=:other
2013 2019 f = :other
2014 2020
2021 $ hg debugpickmergetool --config merge.strict-capability-check=true \
2022 > -r 6d00b3726f6e \
2023 > --config merge-tools.:merge-other.symlink=true \
2024 > --config ui.merge=:merge-other
2025 f = :prompt
2026
2015 2027 #endif
2016 2028
2017 2029 (--verbose shows some configurations)
2018 2030
2019 2031 $ hg debugpickmergetool --tool foobar -v
2020 2032 with --tool 'foobar'
2021 2033 f = foobar
2022 2034
2023 2035 $ HGMERGE=false hg debugpickmergetool -v
2024 2036 with HGMERGE='false'
2025 2037 f = false
2026 2038
2027 2039 $ hg debugpickmergetool --config ui.merge=false -v
2028 2040 with ui.merge='false'
2029 2041 f = false
2030 2042
2031 2043 (--debug shows errors detected intermediately)
2032 2044
2033 2045 $ hg debugpickmergetool --config merge-patterns.f=true --config merge-tools.true.executable=nonexistentmergetool --debug f
2034 2046 couldn't find merge tool true (for pattern f)
2035 2047 couldn't find merge tool true
2036 2048 f = false
2037 2049
2038 2050 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now