mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[scm] Handle empty .gitmodules file
R=yiwzhang@google.com Bug: 372697507 Change-Id: I6ac59b762fedd328d23dcfb4f8ef328f96eb36a7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5923135 Reviewed-by: Yiwei Zhang <yiwzhang@google.com> Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
This commit is contained in:
10
scm.py
10
scm.py
@@ -1113,9 +1113,13 @@ class GIT(object):
|
|||||||
"""
|
"""
|
||||||
if not os.path.exists(os.path.join(repo_root, '.gitmodules')):
|
if not os.path.exists(os.path.join(repo_root, '.gitmodules')):
|
||||||
return []
|
return []
|
||||||
config_output = GIT.Capture(
|
try:
|
||||||
['config', '--file', '.gitmodules', '--get-regexp', 'path'],
|
config_output = GIT.Capture(
|
||||||
cwd=repo_root)
|
['config', '--file', '.gitmodules', '--get-regexp', 'path'],
|
||||||
|
cwd=repo_root)
|
||||||
|
except subprocess2.CalledProcessError:
|
||||||
|
# Git exits with 1 if no config matches are found.
|
||||||
|
return []
|
||||||
assert isinstance(config_output, str)
|
assert isinstance(config_output, str)
|
||||||
return [
|
return [
|
||||||
line.split()[-1].replace('/', os.path.sep)
|
line.split()[-1].replace('/', os.path.sep)
|
||||||
|
|||||||
@@ -149,6 +149,15 @@ class GitWrapperTestCase(unittest.TestCase):
|
|||||||
def testListSubmodules_missing(self):
|
def testListSubmodules_missing(self):
|
||||||
self.assertEqual(scm.GIT.ListSubmodules('root'), [])
|
self.assertEqual(scm.GIT.ListSubmodules('root'), [])
|
||||||
|
|
||||||
|
@mock.patch('os.path.exists', return_value=True)
|
||||||
|
@mock.patch('scm.GIT.Capture')
|
||||||
|
def testListSubmodules_empty(self, mockCapture, *_mock):
|
||||||
|
mockCapture.side_effect = [
|
||||||
|
subprocess2.CalledProcessError(1, '', '', '', ''),
|
||||||
|
]
|
||||||
|
self.assertEqual(scm.GIT.ListSubmodules('root'), [])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RealGitTest(fake_repos.FakeReposTestBase):
|
class RealGitTest(fake_repos.FakeReposTestBase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user