mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 07:18:31 +01:00
dvc: fix gitignore bug
Fixes #375 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+3
-2
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user