-
Notifications
You must be signed in to change notification settings - Fork 1.2k
commands/update: add --rev option #2993
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
Changes from all commits
b285780
95db0ea
beab3d5
9d68c8a
386b25e
32494bb
a9fa797
9a04fbd
f9e5cc9
1562ca4
8400eb3
4fe900f
5f61f0c
f3eb2cd
2abf41c
d2072b9
f56efc6
e6a56f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,9 @@ def download(self, to): | |
| self.def_path, self.def_repo[self.PARAM_URL] | ||
| ) | ||
|
|
||
| def update(self): | ||
| with self._make_repo(rev_lock=None) as repo: | ||
| def update(self, rev=None): | ||
| if not rev: | ||
| rev = self.def_repo.get("rev") | ||
|
Comment on lines
+126
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to do that. See |
||
|
|
||
| with self._make_repo(rev=rev, rev_lock=None) as repo: | ||
| self.def_repo[self.PARAM_REV_LOCK] = repo.scm.get_rev() | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -309,3 +309,10 @@ def __init__(self, path, repo): | |||||
| " neighther as an output nor a git-handled file." | ||||||
| ) | ||||||
| super().__init__(msg.format(path, repo)) | ||||||
|
|
||||||
|
|
||||||
| class UpdateWithRevNotPossibleError(DvcException): | ||||||
| def __init__(self): | ||||||
| super(UpdateWithRevNotPossibleError, self).__init__( | ||||||
| "Revision option (`--rev`) is not a feature of non-Git sources." | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually it is easier to read without double negations:
Suggested change
|
||||||
| ) | ||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,10 @@ | ||||||||
| import shutil | ||||||||
| import pytest | ||||||||
|
|
||||||||
| from dvc.stage import Stage | ||||||||
| from dvc.compat import fspath | ||||||||
| from dvc.exceptions import UpdateWithRevNotPossibleError | ||||||||
| from dvc.external_repo import clean_repos | ||||||||
| from dvc.compat import fspath | ||||||||
| from dvc.stage import Stage | ||||||||
|
|
||||||||
|
|
||||||||
| @pytest.mark.parametrize("cached", [True, False]) | ||||||||
|
|
@@ -71,3 +73,33 @@ def test_update_import_url(tmp_dir, dvc, tmp_path_factory): | |||||||
|
|
||||||||
| assert dst.is_file() | ||||||||
| assert dst.read_text() == "updated file content" | ||||||||
|
|
||||||||
|
|
||||||||
| def test_update_rev(tmp_dir, dvc, erepo_dir, monkeypatch): | ||||||||
| with monkeypatch.context() as m: | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ilgooz , if the reason for using
Suggested change
|
||||||||
| m.chdir(fspath(erepo_dir)) | ||||||||
| erepo_dir.scm.checkout("new_branch", create_new=True) | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another useful helper to change to a branch temporarily:
Suggested change
|
||||||||
| erepo_dir.dvc_gen("foo", "foo content", commit="create foo on branch") | ||||||||
| erepo_dir.scm.checkout("master") | ||||||||
| erepo_dir.scm.checkout("new_branch_2", create_new=True) | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here:
Suggested change
|
||||||||
| erepo_dir.dvc_gen( | ||||||||
| "foo", "foo content 2", commit="create foo on branch" | ||||||||
| ) | ||||||||
| erepo_dir.scm.checkout("master") | ||||||||
|
|
||||||||
| stage = dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="new_branch") | ||||||||
| dvc.update(stage.path, rev="new_branch_2") | ||||||||
|
|
||||||||
| assert (tmp_dir / "foo_imported").read_text() == "foo content 2" | ||||||||
|
|
||||||||
|
|
||||||||
| def test_update_rev_non_git_failure(repo_dir, dvc_repo): | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a suggestion, to save you some time: def test_update_rev_non_git_failure(tmp_dir, dvc):
tmp_dir.gen("file", "text")
stage = dvc.imp_url("file", "imported")
with pytest.raises(UpdateWithRevNotPossibleError):
dvc_repo.update(stage.path, rev="dev")Looks neat) |
||||||||
| src = "file" | ||||||||
| dst = src + "_imported" | ||||||||
|
|
||||||||
| shutil.copyfile(repo_dir.FOO, src) | ||||||||
|
|
||||||||
| stage = dvc_repo.imp_url(src, dst) | ||||||||
|
|
||||||||
| with pytest.raises(UpdateWithRevNotPossibleError): | ||||||||
| dvc_repo.update(stage.path, rev="dev") | ||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilgooz , why removing the examples? Not everyone is familiar with the term revision)