(OutputAlreadyTrackedError): Add git suggestions to stop tracking files (#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]>
This commit is contained in:
Puneetha Pai
2020-05-21 15:17:42 +03:00
committed by GitHub
co-authored by Puneetha Pai
parent 75e795c491
commit 040458a726
2 changed files with 14 additions and 4 deletions
+5 -1
View File
@@ -31,7 +31,11 @@ class OutputIsNotFileOrDirError(DvcException):
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)
+9 -3
View File
@@ -124,10 +124,16 @@ class TestAddDirectoryWithForwardSlash(TestDvc):
def test_add_tracked_file(tmp_dir, scm, dvc):
tmp_dir.scm_gen("tracked_file", "...", commit="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):
dvc.add("tracked_file")
with pytest.raises(OutputAlreadyTrackedError, match=msg):
dvc.add(path)
class TestAddDirWithExistingCache(TestDvc):