Skip to content

Commit 3c8d777

Browse files
committed
default to "HEAD" revision
not every repo has a main or master, but they all have a HEAD make sure that every Source has a rev
1 parent ba1bf35 commit 3c8d777

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

gitman/models/source.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Source:
2424
| --- | ------- | -------- | ------- |
2525
| `repo` | URL of the repository | Yes |
2626
| `name` | Directory for checkout | Yes | (inferred) |
27-
| `rev` | SHA, tag, or branch to checkout | Yes | `"main"`|
27+
| `rev` | SHA, tag, or branch to checkout | Yes | `"HEAD"`|
2828
| `type` | `"git"` or `"git-svn"` | No | `"git"` |
2929
| `params` | Additional arguments for `clone` | No | `null` |
3030
| `sparse_paths` | Controls partial checkout | No | `[]` |
@@ -66,7 +66,7 @@ class Source:
6666

6767
repo: str = ""
6868
name: Optional[str] = None
69-
rev: str = "main"
69+
rev: str = "HEAD"
7070

7171
type: str = "git"
7272
params: Optional[str] = None
@@ -84,6 +84,8 @@ def __post_init__(self):
8484
else:
8585
self.name = str(self.name)
8686
self.type = self.type or "git"
87+
if not self.rev:
88+
self.rev = "HEAD"
8789

8890
def __repr__(self):
8991
return f"<source {self}>"

gitman/tests/test_models_source.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ def test_init_defaults(self):
2020

2121
assert "http://example.com/foo/bar.git" == source.repo
2222
assert "bar" == source.name
23-
assert "main" == source.rev
23+
assert "HEAD" == source.rev
24+
25+
def test_init_invalid_rev_default_gets_corrected(self):
26+
source = Source(type="git", repo="http://example.com/foo/bar.git", rev=None)
27+
28+
assert "HEAD" == source.rev
2429

2530
def test_init_name_as_path(self, tmp_path):
2631
"""Verify the name can be a path."""

0 commit comments

Comments
 (0)