Dvc: checkout: throw a warning if user is trying to do `dvc checkout <branch>`

Created on 31 Jan 2019  Â·  4Comments  Â·  Source: iterative/dvc

Requested by Al on discord. Currently if a user accidentally runs dvc checkout <branch> he gets:

(3.7.0-dvc) ➜  myrepo git:(ololo) ✗ dvc checkout master                                 
Error: unexpected error - 'master' does not exist.                                      

Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help! 

Let's add a static warning that says something like "Do you mean git checkout <branch>?`".

enhancement good first issue help wanted

Most helpful comment

I can have a look at that one

All 4 comments

I can have a look at that one

That would be amazing @tdeboissiere ! Thank you! :slightly_smiling_face: Please let us know if you need anything.

Sure thing !

The error message occurs during a Stage.load call. Stage.load is also called by unrelated dvc commands, such as dvc remove. This means I need a way to identify what dvc command led to the Stage.load call, in order to display the warning message only if that dvc command was a checkout

The most straightforward way would be to add a keyword argument such as from_checkout=False if True, we can then change the error message to suggest git checkout.

While that would work, it is not particularly elegant. Thoughts ?

Edit

Would it make sense to implement a mechanism to easily find out which dvc command has been launched ?
Maybe something like:

  • Call dvc checkout
  • Get the CmdCheckout instance --> set self.project.current_cmd = checkout
  • Then this current_cmd field can be used to fill the debug messages

@tdeboissiere How about we raise a special exception when dvc file doesn't exist and then would catch it either in dvc/project.py:Project.checkout() or in dvc/command/checkout.py?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

analystanand picture analystanand  Â·  3Comments

dmpetrov picture dmpetrov  Â·  3Comments

ghost picture ghost  Â·  3Comments

siddygups picture siddygups  Â·  3Comments

tc-ying picture tc-ying  Â·  3Comments