mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-21 15:28:29 +01:00
(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:
co-authored by
Puneetha Pai
parent
75e795c491
commit
040458a726
+5
-1
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user