Skip to content
Snippets Groups Projects
Commit be0d1413 authored by Dan Villiom Podlaski Christiansen's avatar Dan Villiom Podlaski Christiansen
Browse files

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
parent 4006f2a5
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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 ..
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment