chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import random
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
BASE_DIR = "/tmp/test-git"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_sandbox(sandbox_factory):
|
||||
return sandbox_factory(timeout=10)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_author():
|
||||
return "Sandbox Bot", "sandbox@example.com"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_credentials():
|
||||
return "git", "token", "example.com", "https"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_base_dir(git_sandbox):
|
||||
base_dir = f"{BASE_DIR}/{uuid4().hex}"
|
||||
git_sandbox.commands.run(f'rm -rf "{base_dir}" && mkdir -p "{base_dir}"')
|
||||
yield base_dir
|
||||
git_sandbox.commands.run(f'rm -rf "{base_dir}"')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_repo(git_sandbox, git_base_dir, git_author):
|
||||
repo_path = f"{git_base_dir}/repo"
|
||||
git_sandbox.git.init(repo_path, initial_branch="main")
|
||||
author_name, author_email = git_author
|
||||
git_sandbox.git.configure_user(author_name, author_email)
|
||||
return repo_path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_repo_with_commit(git_sandbox, git_repo, git_author):
|
||||
author_name, author_email = git_author
|
||||
git_sandbox.files.write(f"{git_repo}/README.md", "hello\n")
|
||||
git_sandbox.git.add(git_repo, all=True)
|
||||
git_sandbox.git.commit(
|
||||
git_repo,
|
||||
message="Initial commit",
|
||||
author_name=author_name,
|
||||
author_email=author_email,
|
||||
)
|
||||
return git_repo
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_daemon(git_sandbox, git_base_dir):
|
||||
remote_path = f"{git_base_dir}/remote.git"
|
||||
git_sandbox.commands.run(f'git init --bare --initial-branch=main "{remote_path}"')
|
||||
port = 9418 + random.randint(0, 1000)
|
||||
cmd = (
|
||||
f'git daemon --reuseaddr --base-path="{git_base_dir}" --export-all '
|
||||
f"--enable=receive-pack --informative-errors --listen=127.0.0.1 --port={port}"
|
||||
)
|
||||
handle = git_sandbox.commands.run(cmd, background=True)
|
||||
git_sandbox.commands.run("sleep 1")
|
||||
try:
|
||||
yield {
|
||||
"remote_path": remote_path,
|
||||
"remote_url": f"git://127.0.0.1:{port}/remote.git",
|
||||
"port": port,
|
||||
"base_dir": git_base_dir,
|
||||
}
|
||||
finally:
|
||||
handle.kill()
|
||||
@@ -0,0 +1,16 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_add_stages_files(git_sandbox, git_repo):
|
||||
git_sandbox.files.write(f"{git_repo}/README.md", "hello\n")
|
||||
|
||||
git_sandbox.git.add(git_repo, all=True)
|
||||
|
||||
status = git_sandbox.git.status(git_repo)
|
||||
entry = next(
|
||||
(item for item in status.file_status if item.name == "README.md"), None
|
||||
)
|
||||
assert entry is not None
|
||||
assert entry.status == "added"
|
||||
assert entry.staged is True
|
||||
@@ -0,0 +1,31 @@
|
||||
import pytest
|
||||
|
||||
from e2b.exceptions import InvalidArgumentException
|
||||
from e2b.sandbox._git import (
|
||||
build_remote_add_args,
|
||||
build_remote_get_command,
|
||||
build_reset_args,
|
||||
)
|
||||
|
||||
|
||||
def test_build_reset_args_rejects_invalid_mode():
|
||||
with pytest.raises(InvalidArgumentException) as exc:
|
||||
build_reset_args("bogus", None, None)
|
||||
# Order must match the JS SDK exactly.
|
||||
assert "Reset mode must be one of soft, mixed, hard, merge, keep." in str(exc.value)
|
||||
|
||||
|
||||
def test_build_reset_args_accepts_valid_mode():
|
||||
assert build_reset_args("hard", "HEAD", None) == ["reset", "--hard", "HEAD"]
|
||||
|
||||
|
||||
def test_build_remote_add_args_requires_name_and_url():
|
||||
with pytest.raises(InvalidArgumentException):
|
||||
build_remote_add_args("", "https://example.com", False)
|
||||
with pytest.raises(InvalidArgumentException):
|
||||
build_remote_add_args("origin", "", False)
|
||||
|
||||
|
||||
def test_build_remote_get_command_requires_name():
|
||||
with pytest.raises(InvalidArgumentException):
|
||||
build_remote_get_command("/repo", "")
|
||||
@@ -0,0 +1,52 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_branches_lists_current_and_feature(git_sandbox, git_repo_with_commit):
|
||||
repo_path = git_repo_with_commit
|
||||
|
||||
git_sandbox.commands.run(f'git -C "{repo_path}" branch feature')
|
||||
|
||||
branches = git_sandbox.git.branches(repo_path)
|
||||
assert branches.current_branch == "main"
|
||||
assert "main" in branches.branches
|
||||
assert "feature" in branches.branches
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_checkout_branch_switches_branch(git_sandbox, git_repo_with_commit):
|
||||
repo_path = git_repo_with_commit
|
||||
|
||||
git_sandbox.commands.run(f'git -C "{repo_path}" branch feature')
|
||||
git_sandbox.git.checkout_branch(repo_path, "feature")
|
||||
|
||||
head = git_sandbox.commands.run(
|
||||
f'git -C "{repo_path}" rev-parse --abbrev-ref HEAD'
|
||||
).stdout.strip()
|
||||
assert head == "feature"
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_create_branch_creates_branch(git_sandbox, git_repo_with_commit):
|
||||
repo_path = git_repo_with_commit
|
||||
|
||||
git_sandbox.git.create_branch(repo_path, "feature")
|
||||
|
||||
branches = git_sandbox.git.branches(repo_path)
|
||||
assert "feature" in branches.branches
|
||||
assert branches.current_branch == "feature"
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_delete_branch_removes_branch(git_sandbox, git_repo_with_commit):
|
||||
repo_path = git_repo_with_commit
|
||||
|
||||
git_sandbox.commands.run(f'git -C "{repo_path}" branch feature')
|
||||
git_sandbox.git.delete_branch(repo_path, "feature")
|
||||
|
||||
branch = git_sandbox.commands.run(
|
||||
f'git -C "{repo_path}" branch --list feature'
|
||||
).stdout.strip()
|
||||
branches = git_sandbox.git.branches(repo_path)
|
||||
assert branch == ""
|
||||
assert "feature" not in branches.branches
|
||||
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_clone_fetches_repo(
|
||||
git_sandbox, git_repo_with_commit, git_daemon, git_base_dir
|
||||
):
|
||||
repo_path = git_repo_with_commit
|
||||
remote_url = git_daemon["remote_url"]
|
||||
clone_path = f"{git_base_dir}/clone"
|
||||
|
||||
git_sandbox.git.remote_add(repo_path, "origin", remote_url)
|
||||
git_sandbox.git.push(
|
||||
repo_path,
|
||||
remote="origin",
|
||||
branch="main",
|
||||
set_upstream=True,
|
||||
)
|
||||
|
||||
git_sandbox.git.clone(remote_url, clone_path)
|
||||
contents = git_sandbox.files.read(f"{clone_path}/README.md")
|
||||
assert "hello" in contents
|
||||
@@ -0,0 +1,46 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_commit_creates_commit(git_sandbox, git_repo, git_author):
|
||||
git_sandbox.set_timeout(20)
|
||||
|
||||
author_name, author_email = git_author
|
||||
|
||||
git_sandbox.files.write(f"{git_repo}/README.md", "hello\n")
|
||||
git_sandbox.git.add(git_repo, all=True)
|
||||
git_sandbox.git.commit(
|
||||
git_repo,
|
||||
message="Initial commit",
|
||||
author_name=author_name,
|
||||
author_email=author_email,
|
||||
)
|
||||
|
||||
message = git_sandbox.commands.run(
|
||||
f'git -C "{git_repo}" log -1 --pretty=%B'
|
||||
).stdout.strip()
|
||||
assert message == "Initial commit"
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_commit_uses_config_for_missing_author(git_sandbox, git_repo, git_author):
|
||||
_, expected_email = git_author
|
||||
|
||||
git_sandbox.files.write(f"{git_repo}/README.md", "hello\n")
|
||||
git_sandbox.git.add(git_repo, all=True)
|
||||
override_name = "Override Bot"
|
||||
git_sandbox.git.commit(
|
||||
git_repo,
|
||||
message="Partial author commit",
|
||||
author_name=override_name,
|
||||
)
|
||||
|
||||
author_name = git_sandbox.commands.run(
|
||||
f'git -C "{git_repo}" log -1 --pretty=%an'
|
||||
).stdout.strip()
|
||||
logged_email = git_sandbox.commands.run(
|
||||
f'git -C "{git_repo}" log -1 --pretty=%ae'
|
||||
).stdout.strip()
|
||||
|
||||
assert author_name == override_name
|
||||
assert logged_email == expected_email
|
||||
@@ -0,0 +1,52 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_get_config_reads_local_config(git_sandbox, git_repo):
|
||||
git_sandbox.commands.run(f'git -C "{git_repo}" config --local pull.rebase true')
|
||||
|
||||
value = git_sandbox.git.get_config("pull.rebase", scope="local", path=git_repo)
|
||||
command_value = git_sandbox.commands.run(
|
||||
f'git -C "{git_repo}" config --local --get pull.rebase'
|
||||
).stdout.strip()
|
||||
assert value == "true"
|
||||
assert command_value == "true"
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_set_config_updates_local_config(git_sandbox, git_repo):
|
||||
git_sandbox.git.set_config(
|
||||
"pull.rebase",
|
||||
"true",
|
||||
scope="local",
|
||||
path=git_repo,
|
||||
)
|
||||
|
||||
value = git_sandbox.commands.run(
|
||||
f'git -C "{git_repo}" config --local --get pull.rebase'
|
||||
).stdout.strip()
|
||||
configured_value = git_sandbox.git.get_config(
|
||||
"pull.rebase", scope="local", path=git_repo
|
||||
)
|
||||
assert value == "true"
|
||||
assert configured_value == "true"
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_configure_user_sets_global_config(git_sandbox, git_author):
|
||||
author_name, author_email = git_author
|
||||
|
||||
git_sandbox.git.configure_user(author_name, author_email)
|
||||
|
||||
name = git_sandbox.commands.run(
|
||||
"git config --global --get user.name"
|
||||
).stdout.strip()
|
||||
email = git_sandbox.commands.run(
|
||||
"git config --global --get user.email"
|
||||
).stdout.strip()
|
||||
configured_name = git_sandbox.git.get_config("user.name", scope="global")
|
||||
configured_email = git_sandbox.git.get_config("user.email", scope="global")
|
||||
assert name == author_name
|
||||
assert email == author_email
|
||||
assert configured_name == author_name
|
||||
assert configured_email == author_email
|
||||
@@ -0,0 +1,20 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_dangerously_authenticate_sets_helper(git_sandbox, git_credentials):
|
||||
username, password, host, protocol = git_credentials
|
||||
|
||||
git_sandbox.git.dangerously_authenticate(
|
||||
username,
|
||||
password,
|
||||
host=host,
|
||||
protocol=protocol,
|
||||
)
|
||||
|
||||
helper = git_sandbox.commands.run(
|
||||
"git config --global --get credential.helper"
|
||||
).stdout.strip()
|
||||
configured_helper = git_sandbox.git.get_config("credential.helper", scope="global")
|
||||
assert helper == "store"
|
||||
assert configured_helper == "store"
|
||||
@@ -0,0 +1,14 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_init_creates_repo(git_sandbox, git_base_dir):
|
||||
repo_path = f"{git_base_dir}/repo"
|
||||
|
||||
git_sandbox.git.init(repo_path, initial_branch="main")
|
||||
|
||||
assert git_sandbox.files.exists(f"{repo_path}/.git")
|
||||
head = git_sandbox.commands.run(
|
||||
f'git -C "{repo_path}" symbolic-ref --short HEAD'
|
||||
).stdout.strip()
|
||||
assert head == "main"
|
||||
@@ -0,0 +1,33 @@
|
||||
import inspect
|
||||
|
||||
from e2b.sandbox_async.git import Git as AsyncGit
|
||||
from e2b.sandbox_sync.git import Git as SyncGit
|
||||
|
||||
|
||||
def _public_methods(cls):
|
||||
return {
|
||||
name: getattr(cls, name)
|
||||
for name in sorted(dir(cls))
|
||||
if not name.startswith("_") and callable(getattr(cls, name))
|
||||
}
|
||||
|
||||
|
||||
def test_identical_method_signatures():
|
||||
sync = _public_methods(SyncGit)
|
||||
async_ = _public_methods(AsyncGit)
|
||||
|
||||
assert set(sync) == set(async_), (
|
||||
f"missing from async: {set(sync) - set(async_)}, "
|
||||
f"missing from sync: {set(async_) - set(sync)}"
|
||||
)
|
||||
|
||||
for name in sync:
|
||||
assert inspect.signature(sync[name]) == inspect.signature(async_[name]), (
|
||||
f"{name}: sync{inspect.signature(sync[name])} "
|
||||
f"!= async{inspect.signature(async_[name])}"
|
||||
)
|
||||
|
||||
|
||||
def test_async_methods_are_coroutines():
|
||||
for name, method in _public_methods(AsyncGit).items():
|
||||
assert inspect.iscoroutinefunction(method), f"AsyncGit.{name} is not async"
|
||||
@@ -0,0 +1,44 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_remote_get_returns_none_for_missing_remote(git_sandbox, git_repo):
|
||||
repo_path = git_repo
|
||||
missing_url = git_sandbox.git.remote_get(repo_path, "origin")
|
||||
assert missing_url is None
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_remote_add_adds_remote(git_sandbox, git_repo, git_daemon):
|
||||
repo_path = git_repo
|
||||
remote_url = git_daemon["remote_url"]
|
||||
|
||||
git_sandbox.git.remote_add(repo_path, "origin", remote_url)
|
||||
current_url = git_sandbox.git.remote_get(repo_path, "origin")
|
||||
assert current_url == remote_url
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_remote_add_overwrites_existing_remote(git_sandbox, git_repo, git_daemon):
|
||||
repo_path = git_repo
|
||||
remote_url = git_daemon["remote_url"]
|
||||
|
||||
git_sandbox.git.remote_add(repo_path, "origin", remote_url)
|
||||
current_url = git_sandbox.commands.run(
|
||||
f'git -C "{repo_path}" remote get-url origin'
|
||||
).stdout.strip()
|
||||
current_remote = git_sandbox.git.remote_get(repo_path, "origin")
|
||||
assert current_url == remote_url
|
||||
assert current_remote == remote_url
|
||||
|
||||
second_path = f"{git_daemon['base_dir']}/remote-2.git"
|
||||
git_sandbox.commands.run(f'git init --bare --initial-branch=main "{second_path}"')
|
||||
second_url = f"git://127.0.0.1:{git_daemon['port']}/remote-2.git"
|
||||
git_sandbox.git.remote_add(repo_path, "origin", second_url, overwrite=True)
|
||||
|
||||
updated_url = git_sandbox.commands.run(
|
||||
f'git -C "{repo_path}" remote get-url origin'
|
||||
).stdout.strip()
|
||||
updated_remote = git_sandbox.git.remote_get(repo_path, "origin")
|
||||
assert updated_url == second_url
|
||||
assert updated_remote == second_url
|
||||
@@ -0,0 +1,17 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_reset_hard_discards_changes(git_sandbox, git_repo_with_commit):
|
||||
git_sandbox.files.write(f"{git_repo_with_commit}/README.md", "changed\n")
|
||||
|
||||
status = git_sandbox.git.status(git_repo_with_commit)
|
||||
assert status.is_clean is False
|
||||
|
||||
git_sandbox.git.reset(git_repo_with_commit, mode="hard", target="HEAD")
|
||||
|
||||
status_after = git_sandbox.git.status(git_repo_with_commit)
|
||||
assert status_after.is_clean is True
|
||||
|
||||
contents = git_sandbox.files.read(f"{git_repo_with_commit}/README.md")
|
||||
assert contents == "hello\n"
|
||||
@@ -0,0 +1,37 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_restore_unstages_changes(git_sandbox, git_repo_with_commit):
|
||||
git_sandbox.files.write(f"{git_repo_with_commit}/README.md", "changed\n")
|
||||
git_sandbox.git.add(git_repo_with_commit, files=["README.md"])
|
||||
|
||||
status = git_sandbox.git.status(git_repo_with_commit)
|
||||
assert status.has_staged is True
|
||||
|
||||
git_sandbox.git.restore(
|
||||
git_repo_with_commit,
|
||||
paths=["README.md"],
|
||||
staged=True,
|
||||
worktree=False,
|
||||
)
|
||||
|
||||
status_after = git_sandbox.git.status(git_repo_with_commit)
|
||||
assert status_after.has_staged is False
|
||||
assert status_after.has_changes is True
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_restore_worktree_discards_changes(git_sandbox, git_repo_with_commit):
|
||||
git_sandbox.files.write(f"{git_repo_with_commit}/README.md", "changed\n")
|
||||
|
||||
status = git_sandbox.git.status(git_repo_with_commit)
|
||||
assert status.is_clean is False
|
||||
|
||||
git_sandbox.git.restore(git_repo_with_commit, paths=["README.md"])
|
||||
|
||||
status_after = git_sandbox.git.status(git_repo_with_commit)
|
||||
assert status_after.is_clean is True
|
||||
|
||||
contents = git_sandbox.files.read(f"{git_repo_with_commit}/README.md")
|
||||
assert contents == "hello\n"
|
||||
@@ -0,0 +1,88 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_status_reports_untracked_file(git_sandbox, git_repo):
|
||||
git_sandbox.files.write(f"{git_repo}/README.md", "hello\n")
|
||||
|
||||
status = git_sandbox.git.status(git_repo)
|
||||
entry = next(
|
||||
(item for item in status.file_status if item.name == "README.md"), None
|
||||
)
|
||||
|
||||
assert entry is not None
|
||||
assert entry.status == "untracked"
|
||||
assert status.is_clean is False
|
||||
assert status.has_changes is True
|
||||
assert status.has_untracked is True
|
||||
assert status.has_staged is False
|
||||
assert status.has_conflicts is False
|
||||
assert status.total_count == 1
|
||||
assert status.staged_count == 0
|
||||
assert status.unstaged_count == 1
|
||||
assert status.untracked_count == 1
|
||||
assert status.conflict_count == 0
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_status_reports_added_modified_deleted_renamed(
|
||||
git_sandbox, git_repo, git_author
|
||||
):
|
||||
author_name, author_email = git_author
|
||||
|
||||
git_sandbox.files.write(f"{git_repo}/README.md", "hello\n")
|
||||
git_sandbox.files.write(f"{git_repo}/DELETE.md", "delete me\n")
|
||||
git_sandbox.files.write(f"{git_repo}/RENAME.md", "rename me\n")
|
||||
git_sandbox.git.add(git_repo, all=True)
|
||||
git_sandbox.git.commit(
|
||||
git_repo,
|
||||
message="Initial commit",
|
||||
author_name=author_name,
|
||||
author_email=author_email,
|
||||
)
|
||||
|
||||
git_sandbox.files.write(f"{git_repo}/README.md", "hello again\n")
|
||||
git_sandbox.files.write(f"{git_repo}/NEW.md", "new file\n")
|
||||
git_sandbox.git.add(git_repo, files=["NEW.md"])
|
||||
git_sandbox.commands.run(f'git -C "{git_repo}" rm DELETE.md')
|
||||
git_sandbox.commands.run(f'git -C "{git_repo}" mv RENAME.md RENAMED.md')
|
||||
|
||||
status = git_sandbox.git.status(git_repo)
|
||||
modified = next(
|
||||
(item for item in status.file_status if item.name == "README.md"), None
|
||||
)
|
||||
added = next((item for item in status.file_status if item.name == "NEW.md"), None)
|
||||
deleted = next(
|
||||
(item for item in status.file_status if item.name == "DELETE.md"), None
|
||||
)
|
||||
renamed = next(
|
||||
(item for item in status.file_status if item.name == "RENAMED.md"),
|
||||
None,
|
||||
)
|
||||
|
||||
assert modified is not None
|
||||
assert modified.status == "modified"
|
||||
assert modified.staged is False
|
||||
|
||||
assert added is not None
|
||||
assert added.status == "added"
|
||||
assert added.staged is True
|
||||
|
||||
assert deleted is not None
|
||||
assert deleted.status == "deleted"
|
||||
assert deleted.staged is True
|
||||
|
||||
assert renamed is not None
|
||||
assert renamed.status == "renamed"
|
||||
assert renamed.staged is True
|
||||
assert renamed.renamed_from == "RENAME.md"
|
||||
|
||||
assert status.has_changes is True
|
||||
assert status.has_staged is True
|
||||
assert status.has_untracked is False
|
||||
assert status.has_conflicts is False
|
||||
assert status.total_count == 4
|
||||
assert status.staged_count == 3
|
||||
assert status.unstaged_count == 1
|
||||
assert status.untracked_count == 0
|
||||
assert status.conflict_count == 0
|
||||
@@ -0,0 +1,81 @@
|
||||
import pytest
|
||||
|
||||
from e2b.exceptions import GitUpstreamException
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_push_updates_remote(git_sandbox, git_repo_with_commit, git_daemon):
|
||||
repo_path = git_repo_with_commit
|
||||
remote_url = git_daemon["remote_url"]
|
||||
|
||||
git_sandbox.git.remote_add(repo_path, "origin", remote_url)
|
||||
git_sandbox.git.push(
|
||||
repo_path,
|
||||
remote="origin",
|
||||
branch="main",
|
||||
set_upstream=True,
|
||||
)
|
||||
|
||||
message = git_sandbox.commands.run(
|
||||
f'git --git-dir="{git_daemon["remote_path"]}" log -1 --pretty=%B'
|
||||
).stdout.strip()
|
||||
assert message == "Initial commit"
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_push_without_upstream_warns(git_sandbox, git_repo_with_commit, git_daemon):
|
||||
repo_path = git_repo_with_commit
|
||||
remote_url = git_daemon["remote_url"]
|
||||
|
||||
git_sandbox.git.remote_add(repo_path, "origin", remote_url)
|
||||
|
||||
with pytest.raises(GitUpstreamException) as exc:
|
||||
git_sandbox.git.push(repo_path, set_upstream=False)
|
||||
|
||||
assert "no upstream branch is configured" in str(exc.value).lower()
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_pull_updates_clone(
|
||||
git_sandbox, git_repo_with_commit, git_daemon, git_base_dir, git_author
|
||||
):
|
||||
repo_path = git_repo_with_commit
|
||||
remote_url = git_daemon["remote_url"]
|
||||
clone_path = f"{git_base_dir}/clone"
|
||||
|
||||
git_sandbox.git.remote_add(repo_path, "origin", remote_url)
|
||||
git_sandbox.git.push(
|
||||
repo_path,
|
||||
remote="origin",
|
||||
branch="main",
|
||||
set_upstream=True,
|
||||
)
|
||||
git_sandbox.git.clone(remote_url, clone_path)
|
||||
|
||||
git_sandbox.files.write(f"{repo_path}/README.md", "hello\nmore\n")
|
||||
author_name, author_email = git_author
|
||||
git_sandbox.git.add(repo_path, all=True)
|
||||
git_sandbox.git.commit(
|
||||
repo_path,
|
||||
message="Update README",
|
||||
author_name=author_name,
|
||||
author_email=author_email,
|
||||
)
|
||||
git_sandbox.git.push(repo_path)
|
||||
|
||||
git_sandbox.git.pull(clone_path)
|
||||
contents = git_sandbox.files.read(f"{clone_path}/README.md")
|
||||
assert "more" in contents
|
||||
|
||||
|
||||
@pytest.mark.skip_debug()
|
||||
def test_pull_without_upstream_warns(git_sandbox, git_repo_with_commit, git_daemon):
|
||||
repo_path = git_repo_with_commit
|
||||
remote_url = git_daemon["remote_url"]
|
||||
|
||||
git_sandbox.git.remote_add(repo_path, "origin", remote_url)
|
||||
|
||||
with pytest.raises(GitUpstreamException) as exc:
|
||||
git_sandbox.git.pull(repo_path)
|
||||
|
||||
assert "no upstream branch is configured" in str(exc.value).lower()
|
||||
Reference in New Issue
Block a user