Mercurial > hg > hg-git
changeset 988: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 | 4006f2a59058 |
children | 49e363aebdd0 |
files | hggit/git_handler.py tests/test-illegal-contents.t |
diffstat | 2 files changed, 38 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -1456,6 +1456,7 @@ gitlinks[oldfile] = None continue if newfile is not None: + self.audit_hg_path(newfile) # new = file files[newfile] = False, newmode, newsha if renames is not None and newfile != oldfile: @@ -1538,6 +1539,18 @@ if names: return names[0] + def audit_hg_path(self, path): + if '.hg' in path.split(os.path.sep): + if self.ui.configbool('git', 'blockdothg', True): + raise hgutil.Abort( + ('Refusing to import problematic path %r' % path), + hint=("Mercurial cannot check out paths inside nested " + + "repositories; if you need to continue, then set " + + "'[git] blockdothg = false' in your hgrc.")) + self.ui.warn(('warning: path %r is within a nested repository, ' + + 'which Mercurial cannot check out.\n') + % path) + # Stolen from hgsubversion def swap_out_encoding(self, new_encoding='UTF-8'): try:
--- a/tests/test-illegal-contents.t +++ b/tests/test-illegal-contents.t @@ -90,3 +90,28 @@ (If you need to continue, read about CVE-2014-9390 and then set '[git] blockdotgit = false' in your hgrc.) [255] $ cd .. + +Now check a Git repository containing a Mercurial repository, which +you can't check out. + + $ rm -rf hg git nested + $ git init -q git + $ hg init nested + $ mv nested git + $ cd git + $ git add nested + $ fn_git_commit -m 'add a Mercurial repository' + $ cd .. + $ hg clone git hg + importing git objects into hg + abort: Refusing to import problematic path 'nested/.hg/00changelog.i' + (Mercurial cannot check out paths inside nested repositories; if you need to continue, then set '[git] blockdothg = false' in your hgrc.) + [255] + $ hg clone --config git.blockdothg=false git hg + importing git objects into hg + warning: path 'nested/.hg/00changelog.i' is within a nested repository, which Mercurial cannot check out. + warning: path 'nested/.hg/requires' is within a nested repository, which Mercurial cannot check out. + updating to branch default + abort: path 'nested/.hg/00changelog.i' is inside nested repo 'nested' + [255] + $ cd ..