Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/subrepo.py @ 27935:594bdc380aa2 stable
subrepo: better error messages in _ensuregit
This patch improves the error messages raised when an OSError occurs, since
simply re-raising the exception can be both confusing and misleading. For
example, if "hg identify" is run inside a repository that contains a Git
subrepository and the git binary could not be found, it'll exit with the message
"abort: No such file or directory". That implies "identify" has a problem
reading the repository itself. There's no way for the user to know what the
real problem is unless they dive into the Mercurial source, which is what I
ended up doing after spending hours debugging errors while provisioning a VM
with Ansible (turns out I forgot to install Git on it).
Descriptive errors are especially important on Windows, since it's common for
Windows users to forget to set the "Path" system variable after installing Git.
author | Mason Malone <mason.malone@gmail.com> |
---|---|
date | Sun, 17 Jan 2016 22:53:57 -0500 |
parents | 469b86c49503 |
children | d3f1b7ee5e70 7dab4caf11bc |
comparison
equal
deleted
inserted
replaced
27934:1779ff7426c9 | 27935:594bdc380aa2 |
---|---|
1292 def _ensuregit(self): | 1292 def _ensuregit(self): |
1293 try: | 1293 try: |
1294 self._gitexecutable = 'git' | 1294 self._gitexecutable = 'git' |
1295 out, err = self._gitnodir(['--version']) | 1295 out, err = self._gitnodir(['--version']) |
1296 except OSError as e: | 1296 except OSError as e: |
1297 if e.errno != 2 or os.name != 'nt': | 1297 genericerror = _("error executing git for subrepo '%s': %s") |
1298 raise | 1298 notfoundhint = _("check git is installed and in your PATH") |
1299 self._gitexecutable = 'git.cmd' | 1299 if e.errno != errno.ENOENT: |
1300 out, err = self._gitnodir(['--version']) | 1300 raise error.Abort(genericerror % (self._path, e.strerror)) |
1301 elif os.name == 'nt': | |
1302 try: | |
1303 self._gitexecutable = 'git.cmd' | |
1304 out, err = self._gitnodir(['--version']) | |
1305 except OSError as e2: | |
1306 if e2.errno == errno.ENOENT: | |
1307 raise error.Abort(_("couldn't find 'git' or 'git.cmd'" | |
1308 " for subrepo '%s'") % self._path, | |
1309 hint=notfoundhint) | |
1310 else: | |
1311 raise error.Abort(genericerror % (self._path, | |
1312 e2.strerror)) | |
1313 else: | |
1314 raise error.Abort(_("couldn't find git for subrepo '%s'") | |
1315 % self._path, hint=notfoundhint) | |
1301 versionstatus = self._checkversion(out) | 1316 versionstatus = self._checkversion(out) |
1302 if versionstatus == 'unknown': | 1317 if versionstatus == 'unknown': |
1303 self.ui.warn(_('cannot retrieve git version\n')) | 1318 self.ui.warn(_('cannot retrieve git version\n')) |
1304 elif versionstatus == 'abort': | 1319 elif versionstatus == 'abort': |
1305 raise error.Abort(_('git subrepo requires at least 1.6.0 or later')) | 1320 raise error.Abort(_('git subrepo requires at least 1.6.0 or later')) |