Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default to "HEAD" revision #287

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/interfaces/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
```

Expand Down
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="")

assert "HEAD" == source.rev

def test_init_name_as_path(self, tmp_path):
"""Verify the name can be a path."""
Expand Down
22 changes: 13 additions & 9 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import inspect
import os
import shutil
import sys
from contextlib import suppress
from pathlib import Path

import log
import pytest
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down