From a31ac0774f6c1691f2ffa28f0db1bcebcd9ffeb6 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Wed, 28 May 2025 16:28:01 +0200 Subject: [PATCH] Support environment variable GIT_CLONE_DEPTH. This is used for setting a default git depth for all checkouts. Useful for CI. A specific setting in a repo section still wins. --- CHANGES.md | 3 +++ README.md | 7 +++++++ src/mxdev/vcs/git.py | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 257a43b..e22b687 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,9 @@ ## 4.0.4 (unreleased) +- Support environment variable `GIT_CLONE_DEPTH` for setting a default git depth for all checkouts. Useful for CI. + [maurits] + - Fix #47: Do not add packages with capital names uncommented at the bottom ignore list when checked out. [petschki] diff --git a/README.md b/README.md index 42da887..81f5a45 100644 --- a/README.md +++ b/README.md @@ -254,6 +254,13 @@ True by default, unless `default-use` in the general settings is false. When false, the source is not checked out, and the version for this package is not overridden. +#### `depth` + +For `git` only. +This is used to set the git clone depth. +This is not set by default: you get a full clone. +You can set environment variable `GIT_CLONE_DEPTH=1` to set a default git depth for all checkouts. This is useful for CI. + #### `submodules` There are 3 different options: diff --git a/src/mxdev/vcs/git.py b/src/mxdev/vcs/git.py index 24e9c14..8a2fc97 100644 --- a/src/mxdev/vcs/git.py +++ b/src/mxdev/vcs/git.py @@ -9,6 +9,7 @@ logger = common.logger +GIT_CLONE_DEPTH = os.getenv("GIT_CLONE_DEPTH") class GitError(common.WCError): @@ -151,8 +152,8 @@ def git_checkout(self, **kwargs) -> typing.Union[str, None]: update_git_submodules = self.source.get("submodules", kwargs["submodules"]) if update_git_submodules == "recursive": args.append("--recurse-submodules") - if "depth" in self.source: - args.extend(["--depth", self.source["depth"]]) + if "depth" in self.source or GIT_CLONE_DEPTH: + args.extend(["--depth", self.source.get("depth", GIT_CLONE_DEPTH)]) if "branch" in self.source: args.extend(["-b", self.source["branch"]]) args.extend([url, path])