mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-07 15:28:28 +01:00
dvc: remove .gitignore entries
Fixes #378 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+23
-1
@@ -23,6 +23,9 @@ class Base(object):
|
||||
def ignore(self, path):
|
||||
pass
|
||||
|
||||
def ignore_remove(self, path):
|
||||
pass
|
||||
|
||||
def ignore_file(self):
|
||||
pass
|
||||
|
||||
@@ -68,7 +71,7 @@ class Git(Base):
|
||||
git_dir = os.path.join(root_dir, Git.GIT_DIR)
|
||||
return os.path.isdir(git_dir)
|
||||
|
||||
def ignore(self, path):
|
||||
def _get_gitignore(self, path):
|
||||
entry = os.path.basename(path)
|
||||
gitignore = os.path.join(os.path.abspath(os.path.dirname(path)),
|
||||
self.GITIGNORE)
|
||||
@@ -77,6 +80,11 @@ class Git(Base):
|
||||
if not gitignore.startswith(self.root_dir):
|
||||
raise FileNotInRepoError()
|
||||
|
||||
return entry, gitignore
|
||||
|
||||
def ignore(self, path):
|
||||
entry, gitignore = self._get_gitignore(path)
|
||||
|
||||
ignore_list = []
|
||||
if os.path.exists(gitignore):
|
||||
ignore_list = open(gitignore, 'r').readlines()
|
||||
@@ -90,6 +98,20 @@ class Git(Base):
|
||||
|
||||
open(gitignore, 'a').write(content)
|
||||
|
||||
def ignore_remove(self, path):
|
||||
entry, gitignore = self._get_gitignore(path)
|
||||
|
||||
if not os.path.exists(gitignore):
|
||||
return
|
||||
|
||||
with open(gitignore, 'r') as fd:
|
||||
lines = fd.readlines()
|
||||
|
||||
filtered = list(filter(lambda x: x.strip() != entry.strip(), lines))
|
||||
|
||||
with open(gitignore, 'w') as fd:
|
||||
fd.writelines(filtered)
|
||||
|
||||
def add(self, paths):
|
||||
self.repo.index.add(paths)
|
||||
|
||||
|
||||
@@ -242,6 +242,7 @@ class Output(Dependency):
|
||||
self.project.logger.debug("Removing '{}'".format(self.path))
|
||||
os.chmod(self.path, stat.S_IWUSR)
|
||||
os.unlink(self.path)
|
||||
self.project.scm.ignore_remove(self.path)
|
||||
if os.path.exists(self.cache):
|
||||
os.chmod(self.cache, stat.S_IREAD)
|
||||
|
||||
|
||||
@@ -42,3 +42,6 @@ class TestIgnore(TestGit):
|
||||
|
||||
git.ignore('foo')
|
||||
self.assertEqual(self._count_gitignore(), 1)
|
||||
|
||||
git.ignore_remove('foo')
|
||||
self.assertEqual(self._count_gitignore(), 0)
|
||||
|
||||
Reference in New Issue
Block a user