diff options
author | Mike Frysinger <vapier@google.com> | 2019-07-10 15:42:30 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2019-07-11 01:30:18 +0000 |
commit | ca540aed19bb89a4cd71de83ba123338e1e721f6 (patch) | |
tree | b0a368eb98116602d239778d68e16256782524a8 | |
parent | f88b2fe5699ed224ad693e22a4c26fb76b8befc8 (diff) | |
download | git-repo-ca540aed19bb89a4cd71de83ba123338e1e721f6.tar.gz |
git_command: drop custom version helper
Since ParseGitVersion can call `git --version` automatically, we don't
need this duplicate version() helper anymore. The only other user is
the `repo version` code, so convert that to version_tuple().full.
Bug: https://crbug.com/gerrit/11144
Change-Id: I9d77822fc39f4ba28884d9183359169cabf5f17d
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/231055
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
-rw-r--r-- | git_command.py | 14 | ||||
-rw-r--r-- | subcmds/version.py | 2 | ||||
-rw-r--r-- | tests/test_git_command.py | 45 |
3 files changed, 48 insertions, 13 deletions
diff --git a/git_command.py b/git_command.py index 1807b55e..54db4d16 100644 --- a/git_command.py +++ b/git_command.py | |||
@@ -80,22 +80,12 @@ def terminate_ssh_clients(): | |||
80 | _git_version = None | 80 | _git_version = None |
81 | 81 | ||
82 | class _GitCall(object): | 82 | class _GitCall(object): |
83 | def version(self): | ||
84 | p = GitCommand(None, ['--version'], capture_stdout=True) | ||
85 | if p.Wait() == 0: | ||
86 | if hasattr(p.stdout, 'decode'): | ||
87 | return p.stdout.decode('utf-8') | ||
88 | else: | ||
89 | return p.stdout | ||
90 | return None | ||
91 | |||
92 | def version_tuple(self): | 83 | def version_tuple(self): |
93 | global _git_version | 84 | global _git_version |
94 | if _git_version is None: | 85 | if _git_version is None: |
95 | ver_str = git.version() | 86 | _git_version = Wrapper().ParseGitVersion() |
96 | _git_version = Wrapper().ParseGitVersion(ver_str) | ||
97 | if _git_version is None: | 87 | if _git_version is None: |
98 | print('fatal: "%s" unsupported' % ver_str, file=sys.stderr) | 88 | print('fatal: unable to detect git version', file=sys.stderr) |
99 | sys.exit(1) | 89 | sys.exit(1) |
100 | return _git_version | 90 | return _git_version |
101 | 91 | ||
diff --git a/subcmds/version.py b/subcmds/version.py index 8b48bcfb..9fb694df 100644 --- a/subcmds/version.py +++ b/subcmds/version.py | |||
@@ -41,5 +41,5 @@ class Version(Command, MirrorSafeCommand): | |||
41 | print('repo launcher version %s' % Version.wrapper_version) | 41 | print('repo launcher version %s' % Version.wrapper_version) |
42 | print(' (from %s)' % Version.wrapper_path) | 42 | print(' (from %s)' % Version.wrapper_path) |
43 | 43 | ||
44 | print(git.version().strip()) | 44 | print('git %s' % git.version_tuple().full) |
45 | print('Python %s' % sys.version) | 45 | print('Python %s' % sys.version) |
diff --git a/tests/test_git_command.py b/tests/test_git_command.py new file mode 100644 index 00000000..2ed84969 --- /dev/null +++ b/tests/test_git_command.py | |||
@@ -0,0 +1,45 @@ | |||
1 | # -*- coding:utf-8 -*- | ||
2 | # | ||
3 | # Copyright 2019 The Android Open Source Project | ||
4 | # | ||
5 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | # you may not use this file except in compliance with the License. | ||
7 | # You may obtain a copy of the License at | ||
8 | # | ||
9 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | # | ||
11 | # Unless required by applicable law or agreed to in writing, software | ||
12 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | # See the License for the specific language governing permissions and | ||
15 | # limitations under the License. | ||
16 | |||
17 | import unittest | ||
18 | |||
19 | import git_command | ||
20 | |||
21 | |||
22 | class GitCallUnitTest(unittest.TestCase): | ||
23 | """Tests the _GitCall class (via git_command.git).""" | ||
24 | |||
25 | def test_version_tuple(self): | ||
26 | """Check git.version_tuple() handling.""" | ||
27 | ver = git_command.git.version_tuple() | ||
28 | self.assertIsNotNone(ver) | ||
29 | |||
30 | # We don't dive too deep into the values here to avoid having to update | ||
31 | # whenever git versions change. We do check relative to this min version | ||
32 | # as this is what `repo` itself requires via MIN_GIT_VERSION. | ||
33 | MIN_GIT_VERSION = (1, 7, 2) | ||
34 | self.assertTrue(isinstance(ver.major, int)) | ||
35 | self.assertTrue(isinstance(ver.minor, int)) | ||
36 | self.assertTrue(isinstance(ver.micro, int)) | ||
37 | |||
38 | self.assertGreater(ver.major, MIN_GIT_VERSION[0] - 1) | ||
39 | self.assertGreaterEqual(ver.micro, 0) | ||
40 | self.assertGreaterEqual(ver.major, 0) | ||
41 | |||
42 | self.assertGreaterEqual(ver, MIN_GIT_VERSION) | ||
43 | self.assertLess(ver, (9999, 9999, 9999)) | ||
44 | |||
45 | self.assertNotEqual('', ver.full) | ||