comparison hggit/git_handler.py @ 987:be0d1413a06f

git_handler: detect and reject nested Mercurial repositories The ReviewBoard repository contains a Mercurial repository within its Git repository; if you just convert that into Mercurial, you can't check it out. We handle this similar to invalid Git paths: by default, refuse the conversion, but with a configuration knob to force it through with a warning. See also: https://github.com/reviewboard/reviewboard/ https://reviewboard.org/bugs/3190
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Thu, 04 Feb 2016 13:33:32 +0100
parents 296349f421c8
children 05c8aa7d3edc
comparison
equal deleted inserted replaced
986:4006f2a59058 987:be0d1413a06f
1454 if oldmode == 0160000 and newmode != 0160000: 1454 if oldmode == 0160000 and newmode != 0160000:
1455 # gitlink -> no/file (gitlink -> gitlink is covered above) 1455 # gitlink -> no/file (gitlink -> gitlink is covered above)
1456 gitlinks[oldfile] = None 1456 gitlinks[oldfile] = None
1457 continue 1457 continue
1458 if newfile is not None: 1458 if newfile is not None:
1459 self.audit_hg_path(newfile)
1459 # new = file 1460 # new = file
1460 files[newfile] = False, newmode, newsha 1461 files[newfile] = False, newmode, newsha
1461 if renames is not None and newfile != oldfile: 1462 if renames is not None and newfile != oldfile:
1462 renames[newfile] = oldfile 1463 renames[newfile] = oldfile
1463 renamed_out.add(oldfile) 1464 renamed_out.add(oldfile)
1536 def remote_name(self, remote): 1537 def remote_name(self, remote):
1537 names = [name for name, path in self.paths if path == remote] 1538 names = [name for name, path in self.paths if path == remote]
1538 if names: 1539 if names:
1539 return names[0] 1540 return names[0]
1540 1541
1542 def audit_hg_path(self, path):
1543 if '.hg' in path.split(os.path.sep):
1544 if self.ui.configbool('git', 'blockdothg', True):
1545 raise hgutil.Abort(
1546 ('Refusing to import problematic path %r' % path),
1547 hint=("Mercurial cannot check out paths inside nested " +
1548 "repositories; if you need to continue, then set " +
1549 "'[git] blockdothg = false' in your hgrc."))
1550 self.ui.warn(('warning: path %r is within a nested repository, ' +
1551 'which Mercurial cannot check out.\n')
1552 % path)
1553
1541 # Stolen from hgsubversion 1554 # Stolen from hgsubversion
1542 def swap_out_encoding(self, new_encoding='UTF-8'): 1555 def swap_out_encoding(self, new_encoding='UTF-8'):
1543 try: 1556 try:
1544 from mercurial import encoding 1557 from mercurial import encoding
1545 old = encoding.encoding 1558 old = encoding.encoding