From 6ec17e86616aa6f329ef0abe8c907a3d20427b9c Mon Sep 17 00:00:00 2001 From: Puneetha Pai Date: Sun, 17 May 2020 09:58:38 +0530 Subject: [PATCH] (OutputAlreadyTrackedError): Add git suggestions to stop tracking files 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. --- dvc/output/base.py | 6 +++++- tests/func/test_add.py | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/dvc/output/base.py b/dvc/output/base.py index 7b083432ed..b51e40a1ae 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):