Skip to content

Commit

Permalink
(OutputAlreadyTrackedError): Add git suggestions to stop tracking fil…
Browse files Browse the repository at this point in the history
…es (#3808)

Fixes: #3678
When file has been already tracked under git, OutputAlreadyTrackedError gets raised.
This commits add git command suggestions to help user to stop tracking file from git,
so in future commits they can use DVC for the file.

Co-authored-by: Puneetha Pai <[email protected]>
  • Loading branch information
PuneethaPai and PuneethaPai authored May 21, 2020
1 parent 75e795c commit 040458a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion dvc/output/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def __init__(self, path):

class OutputAlreadyTrackedError(DvcException):
def __init__(self, path):
msg = f"output '{path}' is already tracked by SCM (e.g. Git)"
msg = f""" output '{path}' is already tracked by SCM (e.g. Git).
You can remove it from git, then add to DVC.
To stop tracking from git:
git rm -r --cached '{path}'
git commit -m "stop tracking {path}" """
super().__init__(msg)


Expand Down
14 changes: 10 additions & 4 deletions tests/func/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,16 @@ def test(self):


def test_add_tracked_file(tmp_dir, scm, dvc):
tmp_dir.scm_gen("tracked_file", "...", commit="add tracked file")

with pytest.raises(OutputAlreadyTrackedError):
dvc.add("tracked_file")
path = "tracked_file"
tmp_dir.scm_gen(path, "...", commit="add tracked file")
msg = f""" output '{path}' is already tracked by SCM \\(e.g. Git\\).
You can remove it from git, then add to DVC.
To stop tracking from git:
git rm -r --cached '{path}'
git commit -m "stop tracking {path}" """

with pytest.raises(OutputAlreadyTrackedError, match=msg):
dvc.add(path)


class TestAddDirWithExistingCache(TestDvc):
Expand Down

0 comments on commit 040458a

Please sign in to comment.