fix issue on existing dependency directory without .git

Signed-off-by: HiFiPHile <admin@hifiphile.com>
diff --git a/test/hil/test/test_ci_select.py b/test/hil/test/test_ci_select.py
index 22fbde1..a43348e 100644
--- a/test/hil/test/test_ci_select.py
+++ b/test/hil/test/test_ci_select.py
@@ -2598,5 +2598,28 @@
         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 12bec48..4668dac 100755
--- a/tools/get_deps.py
+++ b/tools/get_deps.py
@@ -342,9 +342,10 @@
     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