diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-05-10 09:48:41 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-05-10 10:04:46 +0200 |
commit | 49fe24ef1af838494da646b5ee9ab056fed78e0e (patch) | |
tree | f672673cca4eed9300320f261b895536528a00a4 /bdep/init.cxx | |
parent | 22417a44283c9a0768c99eaa8fc83ebaae95f359 (diff) |
Generate .gitignore in .bdep/ to prevent accidentally committing it
Diffstat (limited to 'bdep/init.cxx')
-rw-r--r-- | bdep/init.cxx | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/bdep/init.cxx b/bdep/init.cxx index dbb85cb..a3f0859 100644 --- a/bdep/init.cxx +++ b/bdep/init.cxx @@ -15,6 +15,35 @@ using namespace std; namespace bdep { + void + mk_bdep_dir (const dir_path& d) + { + dir_path sd (d / bdep_dir); + + if (!exists (sd)) + { + mk (sd); + + // Create the .gitignore file that ignores everything under .bdep/ + // effectively making git ignore it (this prevents people from + // accidentally adding this directory to a git repository). + // + path f (sd / ".gitignore"); + try + { + ofdstream os (f); + os << "# This directory should not be version-controlled." << '\n' + << "#" << '\n' + << "*" << '\n'; + os.close (); + } + catch (const io_error& e) + { + fail << "unable to write to " << f << ": " << e; + } + } + } + shared_ptr<configuration> cmd_init_config (const configuration_name_options& o, const configuration_add_options& ao, @@ -192,12 +221,7 @@ namespace bdep // Create .bdep/. // - { - dir_path d (prj / bdep_dir); - - if (!exists (d)) - mk (prj / bdep_dir); - } + mk_bdep_dir (prj); // Open the database creating it if necessary. // |