mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 23:09:35 +01:00
dvc: don't track files that are already tracked by git
Fixes #371 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
@@ -51,6 +51,9 @@ class Base(object):
|
||||
def untracked_files(self):
|
||||
pass
|
||||
|
||||
def is_tracked(self, path):
|
||||
pass
|
||||
|
||||
|
||||
class Git(Base):
|
||||
GITIGNORE = '.gitignore'
|
||||
@@ -108,6 +111,9 @@ class Git(Base):
|
||||
def untracked_files(self):
|
||||
return self.repo.untracked_files
|
||||
|
||||
def is_tracked(self, path):
|
||||
return len(self.repo.git.ls_files(path)) != 0
|
||||
|
||||
|
||||
def SCM(root_dir=os.curdir):
|
||||
if Git.is_repo(root_dir):
|
||||
|
||||
@@ -33,6 +33,11 @@ class OutputIsNotFileError(OutputError):
|
||||
super(OutputIsNotFileError, self).__init__(path, 'not a file')
|
||||
|
||||
|
||||
class OutputAlreadyTrackedError(OutputError):
|
||||
def __init__(self, path):
|
||||
super(OutputAlreadyTrackedError, self).__init__(path, 'already tracked by scm(e.g. git)')
|
||||
|
||||
|
||||
class Output(object):
|
||||
PARAM_PATH = 'path'
|
||||
PARAM_MD5 = 'md5'
|
||||
@@ -133,6 +138,9 @@ class Output(object):
|
||||
if not self.use_cache:
|
||||
return
|
||||
|
||||
if self.project.scm.is_tracked(self.path):
|
||||
raise OutputAlreadyTrackedError(self.path)
|
||||
|
||||
self.project.scm.ignore(self.path)
|
||||
self.link()
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import filecmp
|
||||
from dvc.data_cloud import file_md5
|
||||
from dvc.stage import Stage, OutputNoCacheError, OutputOutsideOfRepoError
|
||||
from dvc.stage import OutputDoesNotExistError, OutputIsNotFileError
|
||||
from dvc.stage import OutputAlreadyTrackedError
|
||||
from dvc.project import StageNotFoundError
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
@@ -43,3 +44,14 @@ class TestAddDirectory(TestDvc):
|
||||
os.mkdir(dname)
|
||||
with self.assertRaises(OutputIsNotFileError) as cx:
|
||||
self.dvc.add(dname)
|
||||
|
||||
|
||||
class TestAddTrackedFile(TestDvc):
|
||||
def test(self):
|
||||
fname = 'tracked_file'
|
||||
self.create(fname, 'tracked file contents')
|
||||
self.dvc.scm.add([fname])
|
||||
self.dvc.scm.commit('add {}'.format(fname))
|
||||
|
||||
with self.assertRaises(OutputAlreadyTrackedError) as cx:
|
||||
self.dvc.add(fname)
|
||||
|
||||
Reference in New Issue
Block a user