From 22a272061fe1164b7afcedb6ba3966d6aa13c54e Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 7 Dec 2016 00:14:47 +0200 Subject: [PATCH] Fix merging of ".gitignore" files when re-initialize project // Resolve #848 --- HISTORY.rst | 2 ++ platformio/ide/projectgenerator.py | 14 +++++++------- platformio/ide/tpls/atom/.gitignore.tpl | 1 + platformio/ide/tpls/clion/.gitignore.tpl | 1 + platformio/ide/tpls/emacs/.gitignore.tpl | 1 + 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 0b590869..410cf047 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -56,6 +56,8 @@ PlatformIO 3.0 (`issue #838 `_) * Fixed unable to include SSH user in ``lib_deps`` repository url (`issue #830 `_) +* Fixed merging of ".gitignore" files when re-initialize project + (`issue #848 `_) * Fixed issue with ``PATH`` auto-configuring for upload tools * Fixed ``99-platformio-udev.rules`` checker for Linux OS diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index ef5721a6..aee32748 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -127,13 +127,13 @@ class ProjectGenerator(object): # merge .gitignore if file_name == ".gitignore" and isfile(dst_path): - contents = [l.strip() for l in contents.split("\n") if l.strip()] - with open(dst_path) as f: - for line in f.readlines(): - line = line.strip() - if line and line not in contents: - contents.append(line) - contents = "\n".join(contents) + default = [l.strip() for l in contents.split("\n")] + with open(dst_path) as fp: + current = [l.strip() for l in fp.readlines()] + for d in default: + if d and d not in current: + current.append(d) + contents = "\n".join(current) + "\n" with open(dst_path, "w") as f: f.write(contents) diff --git a/platformio/ide/tpls/atom/.gitignore.tpl b/platformio/ide/tpls/atom/.gitignore.tpl index 5402c188..5dac9f52 100644 --- a/platformio/ide/tpls/atom/.gitignore.tpl +++ b/platformio/ide/tpls/atom/.gitignore.tpl @@ -1,3 +1,4 @@ .pioenvs +.piolibdeps .clang_complete .gcc-flags.json diff --git a/platformio/ide/tpls/clion/.gitignore.tpl b/platformio/ide/tpls/clion/.gitignore.tpl index a9fe6864..081bde01 100644 --- a/platformio/ide/tpls/clion/.gitignore.tpl +++ b/platformio/ide/tpls/clion/.gitignore.tpl @@ -1,2 +1,3 @@ .pioenvs +.piolibdeps CMakeListsPrivate.txt diff --git a/platformio/ide/tpls/emacs/.gitignore.tpl b/platformio/ide/tpls/emacs/.gitignore.tpl index 9984610a..18d8a15b 100644 --- a/platformio/ide/tpls/emacs/.gitignore.tpl +++ b/platformio/ide/tpls/emacs/.gitignore.tpl @@ -1,2 +1,3 @@ .pioenvs +.piolibdeps .clang_complete