Skip to content

Commit

Permalink
default to "HEAD" revision
Browse files Browse the repository at this point in the history
not every repo has a main or master, but they all have a HEAD
make sure that every Source has a rev
  • Loading branch information
djeebus committed Sep 9, 2022
1 parent ba1bf35 commit 3c8d777
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions gitman/models/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 | `[]` |
Expand Down Expand Up @@ -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
Expand All @@ -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"<source {self}>"
Expand Down
7 changes: 6 additions & 1 deletion gitman/tests/test_models_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=None)

assert "HEAD" == source.rev

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

0 comments on commit 3c8d777

Please sign in to comment.