diff --git a/dvc/git_wrapper.py b/dvc/git_wrapper.py index ff3a41341..e142bc8b6 100644 --- a/dvc/git_wrapper.py +++ b/dvc/git_wrapper.py @@ -96,6 +96,17 @@ class GitWrapperI(object): def commit_all_changes_and_log_status(self, message): pass + @staticmethod + def _file_contains(fname, s): + if not os.path.isfile(fname): + return False + + with open(fname, 'r') as fd: + if s in fd.read(): + return True + + return False + @staticmethod def modify_gitignore(flist): for fname in flist: @@ -104,8 +115,13 @@ class GitWrapperI(object): # git and we will not have any problems with --porcelain output for # specific changed files. gitignore = os.path.join(os.path.dirname(fname), '.gitignore') + entry = os.path.basename(fname) + + if GitWrapperI._file_contains(gitignore, entry + '\n'): + return + with open(gitignore, 'a') as fd: - fd.write('\n' + os.path.basename(fname)) + fd.write('\n' + entry) class GitWrapper(GitWrapperI):