diff --git a/hggit/compat.py b/hggit/compat.py index 55c96cb6bb678339f680be86402859a653078fe1_aGdnaXQvY29tcGF0LnB5..4bde7dfac09c6f96afbcb7aaa658ad5830176fc3_aGdnaXQvY29tcGF0LnB5 100644 --- a/hggit/compat.py +++ b/hggit/compat.py @@ -78,7 +78,8 @@ CONFIG_DEFAULTS = { b'git': { b'authors': None, - b'blockdotgit': True, + b'dropdotgit': True, + b'blockdotgit': False, b'blockdothg': True, b'branch_bookmark_suffix': None, b'debugextrainmessage': False, # test only -- do not document this! diff --git a/hggit/hg2git.py b/hggit/hg2git.py index 55c96cb6bb678339f680be86402859a653078fe1_aGdnaXQvaGcyZ2l0LnB5..4bde7dfac09c6f96afbcb7aaa658ad5830176fc3_aGdnaXQvaGcyZ2l0LnB5 100644 --- a/hggit/hg2git.py +++ b/hggit/hg2git.py @@ -125,9 +125,12 @@ If ``git.blockdotgit`` is set, insecure paths raise an exception. - Otherwise, a warning may be printed, but the return value is - ``True``, indicating that all paths should be retained - regardless of any problems they may cause. + Otherwise, if ``ui.dropdotgit`` is set, the return value is + ``False`` to indicate that they are insecure. + + If neither is set, a warning may be printed, but the return + value is ``True``, indicating that all paths should be + retained regardless of any problems they may cause. """ ui = self._hg.ui @@ -152,10 +155,22 @@ b"set '[git] blockdotgit = false' in your hgrc" ), ) - ui.warn(b"warning: path '%s' contains a potentially dangerous path " - b'component, which git cannot check out and most ' - b'git servers reject\n' - % path) + elif compat.config(ui, b'bool', b'git', b'dropdotgit'): + ui.warn( + b"warning: skipping potentially dangerous path '%s'\n" + % path, + ) + return False + else: + ui.warn( + b"warning: path '%s' contains a potentially " + b'dangerous path component, which git cannot check ' + b'out and most git servers reject\n' + % path, + ) + return True + else: + return True def audit_paths(self, paths): """Handle insecure paths""" @@ -159,9 +174,7 @@ def audit_paths(self, paths): """Handle insecure paths""" - for path in paths: - self._audit_one_path(path) - return paths + return [path for path in paths if self._audit_one_path(path)] def update_changeset(self, newctx): """Set the tree to track a new Mercurial changeset. diff --git a/tests/test-illegal-contents.t b/tests/test-illegal-contents.t index 55c96cb6bb678339f680be86402859a653078fe1_dGVzdHMvdGVzdC1pbGxlZ2FsLWNvbnRlbnRzLnQ=..4bde7dfac09c6f96afbcb7aaa658ad5830176fc3_dGVzdHMvdGVzdC1pbGxlZ2FsLWNvbnRlbnRzLnQ= 100644 --- a/tests/test-illegal-contents.t +++ b/tests/test-illegal-contents.t @@ -26,10 +26,14 @@ $ hg ci -m "we should refuse to export this" $ hg book master $ hg gexport - abort: likely-dangerous path '.git/hooks/post-update' rejected by configuration - (to continue, read about CVE-2014-9390 and then set '[git] blockdotgit = false' in your hgrc) - [255] - $ hg gexport --config git.blockdotgit=no + warning: skipping potentially dangerous path '.git/hooks/post-update' + warning: skipping potentially dangerous path 'bar/.gi\xe2\x80\x8ct/wut' (esc) + warning: skipping potentially dangerous path 'foo/git~100/wat' + $ GIT_DIR=.hg/git git ls-tree -r --name-only master + this/is/safe + $ hg gclear + clearing out the git cache data + $ hg gexport --config git.dropdotgit=no warning: path '.git/hooks/post-update' contains a potentially dangerous path component, which git cannot check out and most git servers reject warning: path 'bar/.gi\xe2\x80\x8ct/wut' contains a potentially dangerous path component, which git cannot check out and most git servers reject (esc) warning: path 'foo/git~100/wat' contains a potentially dangerous path component, which git cannot check out and most git servers reject @@ -54,6 +58,16 @@ $ hg ci -m "also refuse to export this" $ hg book master $ hg gexport + warning: skipping potentially dangerous path 'nested/.git/hooks/post-update' + $ git clone .hg/git git + Cloning into 'git'... + done. + $ rm -rf git + +We can trigger an error: + + $ hg -q gclear + $ hg --config git.blockdotgit=true gexport abort: likely-dangerous path 'nested/.git/hooks/post-update' rejected by configuration (to continue, read about CVE-2014-9390 and then set '[git] blockdotgit = false' in your hgrc) [255] @@ -57,4 +71,5 @@ abort: likely-dangerous path 'nested/.git/hooks/post-update' rejected by configuration (to continue, read about CVE-2014-9390 and then set '[git] blockdotgit = false' in your hgrc) [255] + We can override if needed: @@ -60,5 +75,6 @@ We can override if needed: - $ hg --config git.blockdotgit=false gexport + + $ hg --config git.dropdotgit=false gexport warning: path 'nested/.git/hooks/post-update' contains a potentially dangerous path component, which git cannot check out and most git servers reject $ cd .. $ # different git versions give different return codes @@ -108,9 +124,7 @@ $ hg ci -m "also refuse to export this" $ hg book master $ hg gexport - abort: likely-dangerous path 'GIT~1/hooks/post-checkout' rejected by configuration - (to continue, read about CVE-2014-9390 and then set '[git] blockdotgit = false' in your hgrc) - [255] + warning: skipping potentially dangerous path 'GIT~1/hooks/post-checkout' $ cd .. Now check a Git repository containing a Mercurial repository, which