feat: add git pull subcommand
This commit is contained in:
parent
4746e3b3b1
commit
9dd2405c47
10 changed files with 101 additions and 15 deletions
|
|
@ -8,7 +8,7 @@ from halig.settings import Settings
|
|||
|
||||
@pytest.fixture
|
||||
def command(settings: Settings):
|
||||
return GitCommitCommand(settings)
|
||||
return GitCommitCommand(settings=settings)
|
||||
|
||||
|
||||
def test_repo_is_not_initialized(settings):
|
||||
|
|
@ -16,7 +16,7 @@ def test_repo_is_not_initialized(settings):
|
|||
initializes the repo upon instantiation"""
|
||||
|
||||
assert not (settings.notebooks_root_path / ".git").is_dir()
|
||||
GitCommitCommand(settings)
|
||||
GitCommitCommand(settings=settings)
|
||||
assert (settings.notebooks_root_path / ".git").is_dir()
|
||||
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ def test_repo_is_initialized(settings):
|
|||
p = subprocess.Popen(["git", "init"], cwd=settings.notebooks_root_path)
|
||||
p.wait()
|
||||
assert (settings.notebooks_root_path / ".git").is_dir()
|
||||
GitCommitCommand(settings)
|
||||
GitCommitCommand(settings=settings)
|
||||
assert (settings.notebooks_root_path / ".git").is_dir()
|
||||
|
||||
|
||||
|
|
|
|||
37
tests/commands/test_git/test_pull.py
Normal file
37
tests/commands/test_git/test_pull.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import shutil
|
||||
|
||||
import pytest
|
||||
from git import Repo
|
||||
|
||||
from halig.commands.git.pull import GitPullCommand
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def command(settings, faker):
|
||||
"""Configure a local remote for testing located at settings.notebooks_root_path/../remote, push some .age files to
|
||||
that remote
|
||||
"""
|
||||
command = GitPullCommand(settings=settings)
|
||||
|
||||
new_path = shutil.copytree(settings.notebooks_root_path, settings.notebooks_root_path / "../remote")
|
||||
new_path = new_path.resolve()
|
||||
|
||||
command.repo.create_remote("origin", str(new_path))
|
||||
|
||||
remote_repo = Repo(new_path)
|
||||
for _ in range(10):
|
||||
random_age_file = new_path / f"{faker.word()}.age"
|
||||
random_age_file.touch()
|
||||
remote_repo.index.add([str(random_age_file)])
|
||||
remote_repo.index.commit("Update notebooks")
|
||||
|
||||
return command
|
||||
|
||||
def test_pull_from_origin(command):
|
||||
command.run()
|
||||
|
||||
def test_pull_from_custom_origin(settings, command):
|
||||
remote_path = settings.notebooks_root_path / "../remote"
|
||||
command.repo.create_remote("custom", str(remote_path.resolve()))
|
||||
command.remotes = ["custom"]
|
||||
command.run()
|
||||
|
|
@ -9,29 +9,30 @@ from halig.commands.git.push import GitPushCommand
|
|||
@pytest.fixture
|
||||
def command(settings, faker):
|
||||
"""Configure a local remote for testing"""
|
||||
commit_command = GitCommitCommand(settings)
|
||||
new_path = shutil.copytree(settings.notebooks_root_path , settings.notebooks_root_path / "../remote")
|
||||
commit_command = GitCommitCommand(settings=settings)
|
||||
new_path = shutil.copytree(settings.notebooks_root_path, settings.notebooks_root_path / "../remote")
|
||||
new_path = new_path.resolve()
|
||||
for _ in range(10):
|
||||
random_age_file = settings.notebooks_root_path / f"{faker.word()}.age"
|
||||
random_age_file.touch()
|
||||
commit_command.run()
|
||||
|
||||
push_command = GitPushCommand(settings)
|
||||
push_command = GitPushCommand(settings=settings)
|
||||
|
||||
push_command.repo.create_remote("origin", str(new_path))
|
||||
|
||||
return push_command
|
||||
|
||||
|
||||
def test_push_to_origin(settings, command):
|
||||
def test_push_to_origin(command):
|
||||
"""Test that the command pushes to the origin remote"""
|
||||
command.run()
|
||||
|
||||
|
||||
def test_push_to_custom_remote(settings, command):
|
||||
"""Test that the command pushes to a custom remote"""
|
||||
|
||||
remote_path = settings.notebooks_root_path / "../remote"
|
||||
command.repo.create_remote("custom", str(remote_path.resolve()))
|
||||
|
||||
command.run(remotes=["custom"])
|
||||
command.remotes = ["custom"]
|
||||
command.run()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue