mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
repo: add --version support to the launcher
We can get version info when in a checkout, but it'd be helpful to show that info at all times. Change-Id: Ieeb44a503c9d7d8c487db4810bdcf3d5f6656c82 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/254712 Reviewed-by: Michael Mortensen <mmortensen@google.com> Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
parent
8409410aa2
commit
8ddff5c74f
16
repo
16
repo
@ -819,6 +819,7 @@ def _FindRepo():
|
||||
|
||||
class _Options(object):
|
||||
help = False
|
||||
version = False
|
||||
|
||||
|
||||
def _ParseArguments(args):
|
||||
@ -830,7 +831,8 @@ def _ParseArguments(args):
|
||||
a = args[i]
|
||||
if a == '-h' or a == '--help':
|
||||
opt.help = True
|
||||
|
||||
elif a == '--version':
|
||||
opt.version = True
|
||||
elif not a.startswith('-'):
|
||||
cmd = a
|
||||
arg = args[i + 1:]
|
||||
@ -877,6 +879,16 @@ def _Help(args):
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _Version():
|
||||
"""Show version information."""
|
||||
print('<repo not installed>')
|
||||
print('repo launcher version %s' % ('.'.join(str(x) for x in VERSION),))
|
||||
print(' (from %s)' % (__file__,))
|
||||
print('git %s' % (ParseGitVersion().full,))
|
||||
print('Python %s' % sys.version)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def _NotInstalled():
|
||||
print('error: repo is not installed. Use "repo init" to install it here.',
|
||||
file=sys.stderr)
|
||||
@ -953,6 +965,8 @@ def main(orig_args):
|
||||
_Usage()
|
||||
if cmd == 'help':
|
||||
_Help(args)
|
||||
if opt.version or cmd == 'version':
|
||||
_Version()
|
||||
if not cmd:
|
||||
_NotInstalled()
|
||||
if cmd == 'init' or cmd == 'gitc-init':
|
||||
|
@ -26,6 +26,14 @@ from pyversion import is_python3
|
||||
import wrapper
|
||||
|
||||
|
||||
if is_python3():
|
||||
from unittest import mock
|
||||
from io import StringIO
|
||||
else:
|
||||
import mock
|
||||
from StringIO import StringIO
|
||||
|
||||
|
||||
def fixture(*paths):
|
||||
"""Return a path relative to tests/fixtures.
|
||||
"""
|
||||
@ -48,6 +56,16 @@ class RepoWrapperUnitTest(RepoWrapperTestCase):
|
||||
"""Tests helper functions in the repo wrapper
|
||||
"""
|
||||
|
||||
def test_version(self):
|
||||
"""Make sure _Version works."""
|
||||
with self.assertRaises(SystemExit) as e:
|
||||
with mock.patch('sys.stdout', new_callable=StringIO) as stdout:
|
||||
with mock.patch('sys.stderr', new_callable=StringIO) as stderr:
|
||||
self.wrapper._Version()
|
||||
self.assertEqual(0, e.exception.code)
|
||||
self.assertEqual('', stderr.getvalue())
|
||||
self.assertIn('repo launcher version', stdout.getvalue())
|
||||
|
||||
def test_get_gitc_manifest_dir_no_gitc(self):
|
||||
"""
|
||||
Test reading a missing gitc config file
|
||||
|
Loading…
Reference in New Issue
Block a user