summaryrefslogtreecommitdiff
path: root/mesonbuild/utils/universal.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-04-23 12:18:59 -0700
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-06-04 15:16:06 +0300
commit4779abbf3eaf41c2893ef74c4d79f5e894af64d7 (patch)
tree795571046f2e9ca710c57aff88052c2711bbb54a /mesonbuild/utils/universal.py
parent555502761e5bb78b0a5431f9c46987f0413fbe44 (diff)
downloadmeson-4779abbf3eaf41c2893ef74c4d79f5e894af64d7.tar.gz
utils: Support VCSs that can have file repodirs
When git is used with worktrees, `.git` will be a file containing a link to the original repo. Currently, we say that this is not git because `.git` isn't a directory.
Diffstat (limited to 'mesonbuild/utils/universal.py')
-rw-r--r--mesonbuild/utils/universal.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py
index f3b4355bf..e89887631 100644
--- a/mesonbuild/utils/universal.py
+++ b/mesonbuild/utils/universal.py
@@ -757,6 +757,20 @@ class VcsData:
rev_regex: str
dep: str
wc_dir: T.Optional[str] = None
+ repo_can_be_file: bool = False
+
+ def repo_exists(self, curdir: Path) -> bool:
+ if not shutil.which(self.cmd):
+ return False
+
+ repo = curdir / self.repo_dir
+ if repo.is_dir():
+ return True
+ if repo.is_file() and self.repo_can_be_file:
+ return True
+
+ return False
+
def detect_vcs(source_dir: T.Union[str, Path]) -> T.Optional[VcsData]:
vcs_systems = [
@@ -767,6 +781,7 @@ def detect_vcs(source_dir: T.Union[str, Path]) -> T.Optional[VcsData]:
get_rev = ['git', 'describe', '--dirty=+', '--always'],
rev_regex = '(.*)',
dep = '.git/logs/HEAD',
+ repo_can_be_file=True,
),
VcsData(
name = 'mercurial',
@@ -802,9 +817,7 @@ def detect_vcs(source_dir: T.Union[str, Path]) -> T.Optional[VcsData]:
parent_paths_and_self.appendleft(source_dir)
for curdir in parent_paths_and_self:
for vcs in vcs_systems:
- repodir = vcs.repo_dir
- cmd = vcs.cmd
- if curdir.joinpath(repodir).is_dir() and shutil.which(cmd):
+ if vcs.repo_exists(curdir):
vcs.wc_dir = str(curdir)
return vcs
return None