Avoid using 'which' executable for finding git
Just use 'git --version' to check if the git executable is present Change-Id: Ib5c11060fa7d9b7d9741dd88fc3430237f0bc1a0 Closes-Bug: #1248447
This commit is contained in:
parent
629bbce1c8
commit
5e248c5b2d
@ -226,7 +226,14 @@ def _get_git_directory():
|
||||
|
||||
|
||||
def _git_is_installed():
|
||||
return _run_shell_command(['which', 'git'])
|
||||
try:
|
||||
# We cannot use 'which git' as it may not be available
|
||||
# in some distributions, So just try 'git --version'
|
||||
# to see if we run into trouble
|
||||
_run_shell_command(['git', '--version'])
|
||||
except OSError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_boolean_option(option_dict, option_name, env_name):
|
||||
|
@ -41,7 +41,9 @@
|
||||
import os
|
||||
|
||||
import fixtures
|
||||
import mock
|
||||
|
||||
from pbr import packaging
|
||||
from pbr.tests import base
|
||||
|
||||
|
||||
@ -109,3 +111,18 @@ class TestPackagingInPlainDirectory(base.BaseTestCase):
|
||||
# Not a git repo, no ChangeLog created
|
||||
filename = os.path.join(self.package_dir, 'ChangeLog')
|
||||
self.assertFalse(os.path.exists(filename))
|
||||
|
||||
|
||||
class TestPresenceOfGit(base.BaseTestCase):
|
||||
|
||||
def testGitIsInstalled(self):
|
||||
with mock.patch.object(packaging,
|
||||
'_run_shell_command') as _command:
|
||||
_command.return_value = 'git version 1.8.4.1'
|
||||
self.assertEqual(True, packaging._git_is_installed())
|
||||
|
||||
def testGitIsNotInstalled(self):
|
||||
with mock.patch.object(packaging,
|
||||
'_run_shell_command') as _command:
|
||||
_command.side_effect = OSError
|
||||
self.assertEqual(False, packaging._git_is_installed())
|
||||
|
@ -2,6 +2,7 @@ coverage>=3.6
|
||||
discover
|
||||
fixtures>=0.3.12
|
||||
flake8==2.0
|
||||
mock>=1.0
|
||||
python-subunit
|
||||
sphinx>=1.1.2
|
||||
testrepository>=0.0.17
|
||||
|
Loading…
x
Reference in New Issue
Block a user