diff --git a/dvc/output/base.py b/dvc/output/base.py index 8727bb328a..fef7e592cd 100644 --- a/dvc/output/base.py +++ b/dvc/output/base.py @@ -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) diff --git a/tests/func/test_add.py b/tests/func/test_add.py index 11879f4109..85e652db11 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -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):