aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bdep/init.cxx36
-rw-r--r--bdep/init.hxx6
-rw-r--r--bdep/new.cxx2
3 files changed, 37 insertions, 7 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.
//
diff --git a/bdep/init.hxx b/bdep/init.hxx
index 475c87e..6a2afd2 100644
--- a/bdep/init.hxx
+++ b/bdep/init.hxx
@@ -49,6 +49,12 @@ namespace bdep
cmd_init_options
merge_options (const default_options<cmd_init_options>&,
const cmd_init_options&);
+
+ // Create the .bdep/ subdirectory in the specified directory if it does not
+ // already exist.
+ //
+ void
+ mk_bdep_dir (const dir_path&);
}
#endif // BDEP_INIT_HXX
diff --git a/bdep/new.cxx b/bdep/new.cxx
index 51a5308..aac8221 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -3123,7 +3123,7 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args)
// Create .bdep/.
//
- mk (prj / bdep_dir);
+ mk_bdep_dir (prj);
// Initialize tmp directory.
//