commands/update: add --rev option#2993
Conversation
to update with a specific git revision
|
@ilgooz looks like you need to install the pre-commit hook that takes care of the code style - please, take a look at the contributing guide. |
Thanks Ivan, I'll do that and also some fixes, and add some tests! |
done by 95db0ea |
|
Hi guys, big thanks for your encouraging collaboration, I'll do the requested changes. Can you please participate to the discussion at the following link as well? #2849 (comment) |
Co-Authored-By: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> Co-Authored-By: Ruslan Kuprieiev <kupruser@gmail.com>
* small refactoring on the related test to use new testing util.
|
Any ideas of how to get Travis check back? Should I split the string into two lines? https://travis-ci.com/iterative/dvc/jobs/272434824 |
|
@ilgooz Yes, please split it somehow. |
|
cc @Suor up for reviews! |
Co-Authored-By: Ruslan Kuprieiev <kupruser@gmail.com>
|
Tests won't pass again, I'll check this tomorrow! |
|
LGTM, but |
| if not rev: | ||
| rev = self.def_repo.get("rev") |
There was a problem hiding this comment.
No need to do that. See _make_rev, where it will merge your args with def_repo anyways.
| ) | ||
| import_parser.add_argument( | ||
| "--rev", nargs="?", help="Git revision (e.g. branch, tag, SHA)" | ||
| "--rev", nargs="?", help="Git revision in repository to update from." |
There was a problem hiding this comment.
@ilgooz , why removing the examples? Not everyone is familiar with the term revision)
| 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.
Usually it is easier to read without double negations:
not a feature of non-Git sources -> only a feature of Git sources
| "Revision option (`--rev`) is not a feature of non-Git sources." | |
| "Revision option (`--rev`) is supported only for Git sources." |
|
|
||
|
|
||
| def test_update_rev(tmp_dir, dvc, erepo_dir, monkeypatch): | ||
| with monkeypatch.context() as m: |
There was a problem hiding this comment.
@ilgooz , if the reason for using monkeypatch is to chdir to erepo_dir, you can use instead:
| with monkeypatch.context() as m: | |
| with erepo_dir.chdir(): |
| def test_update_rev(tmp_dir, dvc, erepo_dir, monkeypatch): | ||
| with monkeypatch.context() as m: | ||
| m.chdir(fspath(erepo_dir)) | ||
| erepo_dir.scm.checkout("new_branch", create_new=True) |
There was a problem hiding this comment.
Another useful helper to change to a branch temporarily:
| erepo_dir.scm.checkout("new_branch", create_new=True) | |
| with erepo_dir.branch("new_branch", new=True): | |
| # ... |
| erepo_dir.scm.checkout("new_branch", create_new=True) | ||
| 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.
Same here:
| erepo_dir.scm.checkout("new_branch_2", create_new=True) | |
| with erepo_dir.branch("new_branch_2", new=True): |
| 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.
We are not using repo_dir and dvc_repo anymore, instead, we use tmp_dir or dvc.
This is not crucial, but it would be nice if you could read the docstring from tests/dir_helpers.py.
Sorry for the extra work, @ilgooz 😞
There was a problem hiding this comment.
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)
|
Test changes are caused by this PR existing through the period of us refactoring our test suite 🙂Sorry for the inconvenience. |
|
Closing as stale. |
to update with a specific git revision.
please see updates on the docs treeverse/dvc.org#890.
resolves #2849.
--
❗ Have you followed the guidelines in the Contributing to DVC list?
📖 Check this box if this PR does not require documentation updates, or if it does and you have created a separate PR in dvc.org with such updates (or at least opened an issue about it in that repo). Please link below to your PR (or issue) in the dvc.org repo.
❌ Have you checked DeepSource, CodeClimate, and other sanity checks below? We consider their findings recommendatory and don't expect everything to be addressed. Please review them carefully and fix those that actually improve code or fix bugs.
Thank you for the contribution - we'll try to review it as soon as possible. 🙏