Repository: openSUSE/osc

Issue:
osc doesn't work with git-driven development repo
**Describe the bug**
```
mitmanek:lua-rpm-macros (main) $ git remote -v
myrepo	https://src.opensuse.org/lua/lua-rpm-macros.git (fetch)
myrepo	gitea@src.opensuse.org:lua/lua-rpm-macros.git (push)
mitmanek:lua-rpm-macros (main) $ cd ..
mitmanek:lua_devel (master) $ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
mitmanek:lua_devel (master) $ git remote -v
origin	https://src.opensuse.org/lua/_ObsPrj.git (fetch)
origin	https://src.opensuse.org/lua/_ObsPrj.git (push)
mitmanek:lua_devel (master) $ cd lua-rpm-macros
mitmanek:lua-rpm-macros (main) $ osc build
Directory '/home/matej/build/lua_devel/lua-rpm-macros' is not a working copy
mitmanek:lua-rpm-macros (main) $ 
```


**Versions**
- Operating system: MicroOS/Tumbleweed packages
- Packages: `osc_wrapper.py` from master branch

**To Reproduce**
Steps to reproduce the behavior:
1. git clone https://src.opensuse.org/lua/_ObsPrj.git
2. mv _ObsPrj.git dev_lua && cd dev_lua
3. git submodule update --init
4. osc build

**Expected behavior**
should just make the work I ask it to do

**Screenshots, console outputs**
see above

**Additional context**
Add any other context about the problem here.

Discussion:
@dmach: Ok, found it.
The code expects `.git` to be a directory, while it's a file when using git submodules.

Solution patch:
diff --git a/osc/git_scm/store.py b/osc/git_scm/store.py
index b2b74635..364b0cc0 100644
--- a/osc/git_scm/store.py
+++ b/osc/git_scm/store.py
@@ -110,7 +110,7 @@ class GitStore:
 
             path, _ = os.path.split(path)
 
-            if os.path.isdir(os.path.join(path, ".git")):
+            if os.path.exists(os.path.join(path, ".git")):
                 break
 
         config_path = os.path.join(path, "_config")
@@ -164,7 +164,7 @@ class GitStore:
         self.is_project = False
         self.is_package = False
 
-        if os.path.isdir(os.path.join(self.abspath, ".git")):
+        if os.path.exists(os.path.join(self.abspath, ".git")):
             # NOTE: we have only one store in project-git for all packages
             config_path = os.path.join(self.abspath, "_config")
             pbuild_path = os.path.join(self.abspath, "_pbuild")


Test patch:
diff --git a/tests/test_git_scm_store.py b/tests/test_git_scm_store.py
index 8a9d8155..0fc12f58 100644
--- a/tests/test_git_scm_store.py
+++ b/tests/test_git_scm_store.py
@@ -92,9 +92,12 @@ class TestGitStoreProject(unittest.TestCase):
         except OSError:
             pass
 
-    def _git_init(self, path):
+    def _git_init(self, path, separate_git_dir=None):
         os.makedirs(path, exist_ok=True)
-        subprocess.check_output(["git", "init", "-q"], cwd=path)
+        git_init_cmd = ["git", "init", "-q"]
+        if separate_git_dir:
+            git_init_cmd += ["--separate-git-dir", separate_git_dir]
+        subprocess.check_output(git_init_cmd, cwd=path)
         subprocess.check_output(["git", "checkout", "-b", "factory", "-q"], cwd=path)
         subprocess.check_output(["git", "remote", "add", "origin", "https://example.com/packages/my-package.git"], cwd=path)
 
@@ -143,6 +146,20 @@ class TestGitStoreProject(unittest.TestCase):
         self.assertEqual(store.project, "PROJ")
         self.assertEqual(store.package, "my-package")
 
+    def test_pkg_separate_git_dir_git_project(self):
+        prj_path = os.path.join(self.tmpdir, "project")
+        self._git_init(prj_path)
+        self._write(os.path.join(prj_path, "_config"))
+        self._write(os.path.join(prj_path, "project.build"), "PROJ")
+
+        # .git is not a directory, it's a file that contains "gitdir: <path>"
+        pkg_path = os.path.join(prj_path, "package")
+        self._git_init(pkg_path, separate_git_dir="../package-git-dir")
+
+        store = GitStore(pkg_path)
+        self.assertEqual(store.project, "PROJ")
+        self.assertEqual(store.package, "my-package")
+
     def test_pkg_git_with_no_project(self):
         prj_path = os.path.join(self.tmpdir, "project")
         self._git_init(prj_path)