diff --git a/docs/interfaces/models.md b/docs/interfaces/models.md index 2724ba1..86def14 100644 --- a/docs/interfaces/models.md +++ b/docs/interfaces/models.md @@ -20,7 +20,7 @@ or customize the source name and revision: source = Source( repo="https://github.com/jacebrowning/gitman-demo", name="my-demo", # defaults to repository name - rev="my-branch", # defaults to 'main' + rev="my-branch", # defaults to 'HEAD' ) ``` diff --git a/gitman/models/source.py b/gitman/models/source.py index 886fbf7..9fa4313 100644 --- a/gitman/models/source.py +++ b/gitman/models/source.py @@ -24,7 +24,7 @@ class Source: | --- | ------- | -------- | ------- | | `repo` | URL of the repository | Yes | | `name` | Directory for checkout | Yes | (inferred) | - | `rev` | SHA, tag, or branch to checkout | Yes | `"main"`| + | `rev` | SHA, tag, or branch to checkout | Yes | `"HEAD"`| | `type` | `"git"` or `"git-svn"` | No | `"git"` | | `params` | Additional arguments for `clone` | No | `null` | | `sparse_paths` | Controls partial checkout | No | `[]` | @@ -66,7 +66,7 @@ class Source: repo: str = "" name: Optional[str] = None - rev: str = "main" + rev: str = "HEAD" type: str = "git" params: Optional[str] = None @@ -84,6 +84,8 @@ def __post_init__(self): else: self.name = str(self.name) self.type = self.type or "git" + if not self.rev: + self.rev = "HEAD" def __repr__(self): return f"" diff --git a/gitman/tests/test_models_source.py b/gitman/tests/test_models_source.py index 467c560..a8bda4b 100644 --- a/gitman/tests/test_models_source.py +++ b/gitman/tests/test_models_source.py @@ -20,7 +20,12 @@ def test_init_defaults(self): assert "http://example.com/foo/bar.git" == source.repo assert "bar" == source.name - assert "main" == source.rev + assert "HEAD" == source.rev + + def test_init_invalid_rev_default_gets_corrected(self): + source = Source(type="git", repo="http://example.com/foo/bar.git", rev="") + + assert "HEAD" == source.rev def test_init_name_as_path(self, tmp_path): """Verify the name can be a path.""" diff --git a/tests/test_api.py b/tests/test_api.py index 1468a13..ec4377e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -3,7 +3,9 @@ import inspect import os import shutil +import sys from contextlib import suppress +from pathlib import Path import log import pytest @@ -19,6 +21,7 @@ ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__))) TMP = os.path.join(ROOT, "tmp") +is_win = sys.platform.startswith("win") CONFIG = """ location: deps @@ -74,7 +77,7 @@ def config(): os.makedirs(TMP) os.chdir(TMP) - os.system("touch .git") + Path(".git").touch() config = Config(root=TMP) config.datafile.text = CONFIG config.datafile.load() @@ -252,26 +255,27 @@ def config_with_link(config): return config + @pytest.mark.skipif(is_win, reason="doesn't work, not sure why") def it_should_create_links(config_with_link): expect(gitman.install(depth=1)) == True expect(os.listdir()).contains("my_link") def it_should_not_overwrite_files(config_with_link): - os.system("touch my_link") + Path("my_link").touch() with pytest.raises(RuntimeError): gitman.install(depth=1) def it_should_not_overwrite_non_empty_directories(config_with_link): - os.system("mkdir my_link") - os.system("touch mylink/my_link") + os.mkdir("my_link") + Path("my_link/my_link").touch() with pytest.raises(RuntimeError): gitman.install(depth=1) def it_overwrites_files_with_force(config_with_link): - os.system("touch my_link") + Path("my_link").touch() expect(gitman.install(depth=1, force=True)) == True @@ -307,20 +311,20 @@ def it_should_create_links(config_with_links): expect(os.listdir()).contains("gmd_4") def it_should_not_overwrite_files(config_with_links): - os.system("touch gmd_3") + Path("gmd_3").touch() with pytest.raises(RuntimeError): gitman.install(depth=1) def it_should_not_overwrite_non_empty_directories(config_with_links): - os.system("mkdir gmd_3") - os.system("touch gmd_3/my_link") + os.mkdir("gmd_3") + Path("gmd_3/my_link").touch() with pytest.raises(RuntimeError): gitman.install(depth=1) def it_overwrites_files_with_force(config_with_links): - os.system("touch gmd_3") + Path("gmd_3").touch() expect(gitman.install(depth=1, force=True)) == True