From 040458a726c5be01c360015ac1a38aa2a0c2f631 Mon Sep 17 00:00:00 2001 From: Puneetha Pai Date: Thu, 21 May 2020 17:47:42 +0530 Subject: [PATCH] (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 --- dvc/output/base.py | 6 +++++- tests/func/test_add.py | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dvc/output/base.py b/dvc/output/base.py index 8727bb328..fef7e592c 100644 --- a/dvc/output/base.py +++ b/dvc/output/base.py @@ -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) diff --git a/tests/func/test_add.py b/tests/func/test_add.py index 11879f410..85e652db1 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -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):