summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-02-09 15:00:25 -0500
committerMike Frysinger <vapier@google.com>2020-02-12 20:54:50 +0000
commit8ddff5c74f533f4f125c957d7bd063452c59f0db (patch)
tree43122badb2576ba8b81b431bd6da4761879d6cc9
parent8409410aa294cad68bf93679726e0a4465e1fe2b (diff)
downloadgit-repo-8ddff5c74f533f4f125c957d7bd063452c59f0db.tar.gz
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>
-rwxr-xr-xrepo16
-rw-r--r--tests/test_wrapper.py18
-rw-r--r--tox.ini5
3 files changed, 38 insertions, 1 deletions
diff --git a/repo b/repo
index 6ecf3921..86d0ec21 100755
--- a/repo
+++ b/repo
@@ -819,6 +819,7 @@ def _FindRepo():
819 819
820class _Options(object): 820class _Options(object):
821 help = False 821 help = False
822 version = False
822 823
823 824
824def _ParseArguments(args): 825def _ParseArguments(args):
@@ -830,7 +831,8 @@ def _ParseArguments(args):
830 a = args[i] 831 a = args[i]
831 if a == '-h' or a == '--help': 832 if a == '-h' or a == '--help':
832 opt.help = True 833 opt.help = True
833 834 elif a == '--version':
835 opt.version = True
834 elif not a.startswith('-'): 836 elif not a.startswith('-'):
835 cmd = a 837 cmd = a
836 arg = args[i + 1:] 838 arg = args[i + 1:]
@@ -877,6 +879,16 @@ def _Help(args):
877 sys.exit(1) 879 sys.exit(1)
878 880
879 881
882def _Version():
883 """Show version information."""
884 print('<repo not installed>')
885 print('repo launcher version %s' % ('.'.join(str(x) for x in VERSION),))
886 print(' (from %s)' % (__file__,))
887 print('git %s' % (ParseGitVersion().full,))
888 print('Python %s' % sys.version)
889 sys.exit(0)
890
891
880def _NotInstalled(): 892def _NotInstalled():
881 print('error: repo is not installed. Use "repo init" to install it here.', 893 print('error: repo is not installed. Use "repo init" to install it here.',
882 file=sys.stderr) 894 file=sys.stderr)
@@ -953,6 +965,8 @@ def main(orig_args):
953 _Usage() 965 _Usage()
954 if cmd == 'help': 966 if cmd == 'help':
955 _Help(args) 967 _Help(args)
968 if opt.version or cmd == 'version':
969 _Version()
956 if not cmd: 970 if not cmd:
957 _NotInstalled() 971 _NotInstalled()
958 if cmd == 'init' or cmd == 'gitc-init': 972 if cmd == 'init' or cmd == 'gitc-init':
diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py
index e574946b..61636b26 100644
--- a/tests/test_wrapper.py
+++ b/tests/test_wrapper.py
@@ -26,6 +26,14 @@ from pyversion import is_python3
26import wrapper 26import wrapper
27 27
28 28
29if is_python3():
30 from unittest import mock
31 from io import StringIO
32else:
33 import mock
34 from StringIO import StringIO
35
36
29def fixture(*paths): 37def fixture(*paths):
30 """Return a path relative to tests/fixtures. 38 """Return a path relative to tests/fixtures.
31 """ 39 """
@@ -48,6 +56,16 @@ class RepoWrapperUnitTest(RepoWrapperTestCase):
48 """Tests helper functions in the repo wrapper 56 """Tests helper functions in the repo wrapper
49 """ 57 """
50 58
59 def test_version(self):
60 """Make sure _Version works."""
61 with self.assertRaises(SystemExit) as e:
62 with mock.patch('sys.stdout', new_callable=StringIO) as stdout:
63 with mock.patch('sys.stderr', new_callable=StringIO) as stderr:
64 self.wrapper._Version()
65 self.assertEqual(0, e.exception.code)
66 self.assertEqual('', stderr.getvalue())
67 self.assertIn('repo launcher version', stdout.getvalue())
68
51 def test_get_gitc_manifest_dir_no_gitc(self): 69 def test_get_gitc_manifest_dir_no_gitc(self):
52 """ 70 """
53 Test reading a missing gitc config file 71 Test reading a missing gitc config file
diff --git a/tox.ini b/tox.ini
index 02c5647d..bd1e18cc 100644
--- a/tox.ini
+++ b/tox.ini
@@ -20,3 +20,8 @@ envlist = py27, py36, py37, py38
20[testenv] 20[testenv]
21deps = pytest 21deps = pytest
22commands = {toxinidir}/run_tests 22commands = {toxinidir}/run_tests
23
24[testenv:py27]
25deps =
26 mock
27 pytest