From 49fe24ef1af838494da646b5ee9ab056fed78e0e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 10 May 2021 09:48:41 +0200 Subject: Generate .gitignore in .bdep/ to prevent accidentally committing it --- bdep/init.cxx | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'bdep/init.cxx') 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 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. // -- cgit v1.1