From 50eb0df87a40773a8f0f4379c0490e842c7abd9a Mon Sep 17 00:00:00 2001 From: Muhtasim Munif Fahim Date: Sat, 7 Nov 2026 09:00:29 +0600 Subject: [PATCH 1/2] Default missing/empty rev to main before checkout When `rev` is omitted from `.gitman.yml`, datafiles loads it as an empty string, which bypasses the dataclass default of `"main"` and causes `git checkout --force ""` to fail. Normalize empty/missing rev to `"main"` in `Source.__post_init__`, matching the documented default. Fixes #533 --- gitman/models/source.py | 5 +++++ gitman/tests/test_models_source.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gitman/models/source.py b/gitman/models/source.py index 3376b181..eb94a856 100644 --- a/gitman/models/source.py +++ b/gitman/models/source.py @@ -98,6 +98,11 @@ def __post_init__(self): self.name = self.repo.split("/")[-1].split(".")[0] else: self.name = str(self.name) + # datafiles sets missing YAML keys to "" for nested dataclasses, + # which bypasses the field default of "main" and leads to + # `git checkout --force ""`. Treat empty/missing rev as "main". + if not self.rev: + self.rev = "main" self.type = self.type or "git" def __repr__(self): diff --git a/gitman/tests/test_models_source.py b/gitman/tests/test_models_source.py index 4f0c4582..9bac95de 100644 --- a/gitman/tests/test_models_source.py +++ b/gitman/tests/test_models_source.py @@ -36,6 +36,22 @@ def test_init_rev(self): assert "v1.0" == source.rev + def test_init_empty_rev_defaults_to_main(self): + """Verify an empty rev (as loaded from YAML) defaults to main.""" + source = Source( + type="git", repo="http://example.com/foo/bar.git", name=None, rev="" + ) + + assert "main" == source.rev + + def test_init_none_rev_defaults_to_main(self): + """Verify an explicit None rev defaults to main.""" + source = Source( + type="git", repo="http://example.com/foo/bar.git", name=None, rev=None + ) + + assert "main" == source.rev + def test_repr(self, source): """Verify sources can be represented.""" assert "" == repr(source) From 2d7afdcb2d8a9091f1d9d0caf25ffd64de00fce2 Mon Sep 17 00:00:00 2001 From: Muhtasim Munif Fahim Date: Mon, 9 Nov 2026 08:25:43 +0600 Subject: [PATCH 2/2] test: satisfy mypy when constructing Source with rev=None --- gitman/tests/test_models_source.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gitman/tests/test_models_source.py b/gitman/tests/test_models_source.py index 9bac95de..a0e1cbd1 100644 --- a/gitman/tests/test_models_source.py +++ b/gitman/tests/test_models_source.py @@ -47,7 +47,10 @@ def test_init_empty_rev_defaults_to_main(self): def test_init_none_rev_defaults_to_main(self): """Verify an explicit None rev defaults to main.""" source = Source( - type="git", repo="http://example.com/foo/bar.git", name=None, rev=None + type="git", + repo="http://example.com/foo/bar.git", + name=None, + rev=None, # type: ignore[arg-type] ) assert "main" == source.rev