Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(OutputAlreadyTrackedError): Add git suggestions to stop tracking files #3808

Merged
merged 1 commit into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
PuneethaPai marked this conversation as resolved.
Show resolved Hide resolved
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