summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/hil/test/test_ci_select.py23
-rwxr-xr-xtools/get_deps.py7
2 files changed, 27 insertions, 3 deletions
diff --git a/test/hil/test/test_ci_select.py b/test/hil/test/test_ci_select.py
index 22fbde17b..a43348edc 100644
--- a/test/hil/test/test_ci_select.py
+++ b/test/hil/test/test_ci_select.py
@@ -2598,5 +2598,28 @@ class TestGetDepsExampleShim(unittest.TestCase):
self.assertEqual(r.returncode, 0, r.stderr)
+class TestGetDepsExistingDirectory(unittest.TestCase):
+ def test_directory_without_git_metadata_is_initialized(self):
+ from tempfile import TemporaryDirectory
+ from unittest import mock
+ import get_deps
+
+ with TemporaryDirectory() as top:
+ dep = pathlib.Path(top, 'lib', 'dep')
+ dep.mkdir(parents=True)
+ result = subprocess.CompletedProcess([], 0, stdout=b'parent-head\n')
+ with mock.patch.object(get_deps, 'TOP', pathlib.Path(top)), \
+ mock.patch.dict(get_deps.deps_all,
+ {'lib/dep': ['https://example.invalid/dep.git',
+ '0123456789abcdef', 'test']},
+ clear=True), \
+ mock.patch.object(get_deps, 'run_cmd', return_value=result) as run:
+ self.assertEqual(get_deps.get_a_dep('lib/dep'), 0)
+
+ commands = [call.args[0] for call in run.call_args_list]
+ self.assertTrue(commands[0].endswith(' init'), commands)
+ self.assertFalse(any(' reset --hard' in command for command in commands), commands)
+
+
if __name__ == '__main__':
unittest.main(verbosity=1)
diff --git a/tools/get_deps.py b/tools/get_deps.py
index 12bec4861..4668dac3b 100755
--- a/tools/get_deps.py
+++ b/tools/get_deps.py
@@ -342,9 +342,10 @@ def get_a_dep(d):
p = Path(TOP / d)
git_cmd = f"git -C {p}"
- # Init git deps if not existed
- if not p.exists():
- p.mkdir(parents=True)
+ # Init git deps if not initialized. Checking only p.exists() lets git -C walk
+ # up to TinyUSB's repository when an empty dependency directory is present.
+ if not (p / '.git').exists():
+ p.mkdir(parents=True, exist_ok=True)
run_cmd(f"{git_cmd} init")
run_cmd(f"{git_cmd} remote add origin {url}")
head = None