mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-27 07:18:28 +01:00
experiments: add dvc exp push/pull/list (#5042)
* git: add support for on_diverged in push_refspec * experiments: update executor for push-refspec changes * experiments: implement push() * tests: add tests for experiments.push * git: add iter_remote_refs * roughly equivalent to `git ls-remote --refs` * experiments: add experiments.list for listing local and remote experiments * refactor git upstream/downstream in tests * experiments: add experiments.pull * experiments: add CLI commands for push/pull/list * exp list: drop short options * experiments: s/list/ls/ * dulwich: catch not repo errors when creating remote client * fix remote rev resolution for list * fix command test * add tests for push/pull with ambiguous experiment names
This commit is contained in:
@@ -6,6 +6,9 @@ from dvc.command.experiments import (
|
||||
CmdExperimentsBranch,
|
||||
CmdExperimentsDiff,
|
||||
CmdExperimentsGC,
|
||||
CmdExperimentsList,
|
||||
CmdExperimentsPull,
|
||||
CmdExperimentsPush,
|
||||
CmdExperimentsRun,
|
||||
CmdExperimentsShow,
|
||||
)
|
||||
@@ -150,3 +153,47 @@ def test_experiments_branch(dvc, scm, mocker):
|
||||
assert cmd.run() == 0
|
||||
|
||||
m.assert_called_once_with(cmd.repo, "expname", "branchname")
|
||||
|
||||
|
||||
def test_experiments_list(dvc, scm, mocker):
|
||||
cli_args = parse_args(
|
||||
["experiments", "list", "origin", "--rev", "foo", "--all"]
|
||||
)
|
||||
assert cli_args.func == CmdExperimentsList
|
||||
|
||||
cmd = cli_args.func(cli_args)
|
||||
m = mocker.patch("dvc.repo.experiments.ls.ls", return_value={})
|
||||
|
||||
assert cmd.run() == 0
|
||||
|
||||
m.assert_called_once_with(
|
||||
cmd.repo, git_remote="origin", rev="foo", all_=True
|
||||
)
|
||||
|
||||
|
||||
def test_experiments_push(dvc, scm, mocker):
|
||||
cli_args = parse_args(
|
||||
["experiments", "push", "origin", "experiment", "--force"]
|
||||
)
|
||||
assert cli_args.func == CmdExperimentsPush
|
||||
|
||||
cmd = cli_args.func(cli_args)
|
||||
m = mocker.patch("dvc.repo.experiments.push.push", return_value={})
|
||||
|
||||
assert cmd.run() == 0
|
||||
|
||||
m.assert_called_once_with(cmd.repo, "origin", "experiment", force=True)
|
||||
|
||||
|
||||
def test_experiments_pull(dvc, scm, mocker):
|
||||
cli_args = parse_args(
|
||||
["experiments", "pull", "origin", "experiment", "--force"]
|
||||
)
|
||||
assert cli_args.func == CmdExperimentsPull
|
||||
|
||||
cmd = cli_args.func(cli_args)
|
||||
m = mocker.patch("dvc.repo.experiments.pull.pull", return_value={})
|
||||
|
||||
assert cmd.run() == 0
|
||||
|
||||
m.assert_called_once_with(cmd.repo, "origin", "experiment", force=True)
|
||||
|
||||
@@ -211,7 +211,8 @@ def test_refs_containing(tmp_dir, scm):
|
||||
assert expected == set(scm.get_refs_containing(init_rev))
|
||||
|
||||
|
||||
def test_push_refspec(tmp_dir, scm, make_tmp_dir):
|
||||
@pytest.mark.parametrize("use_url", [True, False])
|
||||
def test_push_refspec(tmp_dir, scm, make_tmp_dir, use_url):
|
||||
tmp_dir.scm_gen({"file": "0"}, commit="init")
|
||||
init_rev = scm.get_rev()
|
||||
tmp_dir.gen(
|
||||
@@ -222,18 +223,23 @@ def test_push_refspec(tmp_dir, scm, make_tmp_dir):
|
||||
)
|
||||
remote_dir = make_tmp_dir("git-remote", scm=True)
|
||||
url = "file://{}".format(remote_dir.resolve().as_posix())
|
||||
scm.gitpython.repo.create_remote("origin", url)
|
||||
|
||||
scm.push_refspec(url, "refs/foo/bar", "refs/foo/bar")
|
||||
with pytest.raises(SCMError):
|
||||
scm.push_refspec("bad-remote", "refs/foo/bar", "refs/foo/bar")
|
||||
|
||||
remote = url if use_url else "origin"
|
||||
scm.push_refspec(remote, "refs/foo/bar", "refs/foo/bar")
|
||||
assert init_rev == remote_dir.scm.get_ref("refs/foo/bar")
|
||||
|
||||
remote_dir.scm.checkout("refs/foo/bar")
|
||||
assert init_rev == remote_dir.scm.get_rev()
|
||||
assert "0" == (remote_dir / "file").read_text()
|
||||
|
||||
scm.push_refspec(url, "refs/foo/", "refs/foo/")
|
||||
scm.push_refspec(remote, "refs/foo/", "refs/foo/")
|
||||
assert init_rev == remote_dir.scm.get_ref("refs/foo/baz")
|
||||
|
||||
scm.push_refspec(url, None, "refs/foo/baz")
|
||||
scm.push_refspec(remote, None, "refs/foo/baz")
|
||||
assert remote_dir.scm.get_ref("refs/foo/baz") is None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user