dvc: fix gitignore bug

Fixes #375

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-01-14 18:48:48 +02:00
parent cf7bafad4d
commit 266a908169
2 changed files with 20 additions and 7 deletions
+3 -2
View File
@@ -80,11 +80,12 @@ class Git(Base):
ignore_list = []
if os.path.exists(gitignore):
ignore_list = open(gitignore, 'r').readlines()
if entry in ignore_list:
filtered = list(filter(lambda x: x.strip() == entry.strip(), ignore_list))
if len(filtered) != 0:
return
content = entry
if ignore_list:
if len(ignore_list) > 0:
content = '\n' + content
open(gitignore, 'a').write(content)
+17 -5
View File
@@ -20,13 +20,25 @@ class TestSCMGit(TestGit):
def test_is_repo(self):
self.assertTrue(Git.is_repo(os.curdir))
def test_ignore(self):
Git(self._root_dir).ignore('foo')
self.assertTrue(os.path.isfile(Git.GITIGNORE))
self.assertTrue('foo' in open(Git.GITIGNORE, 'r').readlines())
def test_commit(self):
G = Git(self._root_dir)
G.add(['foo'])
G.commit('add')
self.assertTrue('foo' in self.git.git.ls_files())
class TestIgnore(TestGit):
def _count_gitignore(self):
with open(Git.GITIGNORE, 'r') as fd:
lines = fd.readlines()
return len(list(filter(lambda x: x.strip() == 'foo', lines)))
def test(self):
git = Git(self._root_dir)
git.ignore('foo')
self.assertTrue(os.path.isfile(Git.GITIGNORE))
self.assertEqual(self._count_gitignore(), 1)
git.ignore('foo')
self.assertEqual(self._count_gitignore(), 1)