From 2007491be919d35c924d858ed84098628486b1e2 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 27 Oct 2018 14:20:33 +0300 Subject: [PATCH] Don't override existing ".gitignore" file --- platformio/commands/init.py | 31 +++++++++++------------------- platformio/ide/projectgenerator.py | 20 ++----------------- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/platformio/commands/init.py b/platformio/commands/init.py index 8b8c7f80..376a9b1e 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -100,6 +100,9 @@ def cli( pg = ProjectGenerator(project_dir, ide, env_name) pg.generate() + init_ci_conf(project_dir) + init_cvs_ignore(project_dir) + if silent: return @@ -148,9 +151,6 @@ def init_base_project(project_dir): join(util.get_source_dir(), "projectconftpl.ini"), join(project_dir, "platformio.ini")) - init_ci_conf(project_dir) - init_cvs_ignore(project_dir) - with util.cd(project_dir): dir_to_readme = [ (util.get_projectsrc_dir(), None), @@ -278,7 +278,10 @@ More information about PIO Unit Testing: def init_ci_conf(project_dir): - with open(join(project_dir, ".travis.yml"), "w") as f: + conf_path = join(project_dir, ".travis.yml") + if isfile(conf_path): + return + with open(conf_path, "w") as f: f.write("""# Continuous Integration (CI) is the practice, in software # engineering, of merging all developer working copies with a shared mainline # several times a day < https://docs.platformio.org/page/ci/index.html > @@ -350,23 +353,11 @@ def init_ci_conf(project_dir): def init_cvs_ignore(project_dir): - ignore_path = join(project_dir, ".gitignore") - default = [".pioenvs\n", ".piolibdeps\n"] - current = [] - modified = False - if isfile(ignore_path): - with open(ignore_path) as fp: - current = fp.readlines() - if current and not current[-1].endswith("\n"): - current[-1] += "\n" - for d in default: - if d not in current: - modified = True - current.append(d) - if not modified: + conf_path = join(project_dir, ".gitignore") + if isfile(conf_path): return - with open(ignore_path, "w") as fp: - fp.writelines(current) + with open(conf_path, "w") as fp: + fp.writelines([".pio\n", ".pioenvs\n", ".piolibdeps\n"]) def fill_project_envs(ctx, project_dir, board_ids, project_option, env_prefix, diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index da3faab0..efec49ad 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -127,24 +127,8 @@ class ProjectGenerator(object): @staticmethod def _merge_contents(dst_path, contents): - file_name = basename(dst_path) - - # merge .gitignore - if file_name == ".gitignore": - if not isfile(dst_path): - return - modified = False - 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: - modified = True - current.append(d) - if not modified: - return - contents = "\n".join(current) + "\n" - + if basename(dst_path) == ".gitignore" and isfile(dst_path): + return with open(dst_path, "w") as f: f.write(contents)