aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-05-10 10:05:52 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-05-10 10:05:52 +0200
commitfa32d6d240de24e11aa0239d240e136ae8876341 (patch)
tree41f04277c6d2129ba80f732ce4ca00099687c2ea
parent0dea838318458eac5a8d2ccc3292288347b78043 (diff)
Generate .gitignore in .bpkg/ to prevent accidentally committing it
-rw-r--r--bpkg/cfg-create.cxx22
1 files changed, 21 insertions, 1 deletions
diff --git a/bpkg/cfg-create.cxx b/bpkg/cfg-create.cxx
index 355690a..f3ca80d 100644
--- a/bpkg/cfg-create.cxx
+++ b/bpkg/cfg-create.cxx
@@ -118,9 +118,29 @@ namespace bpkg
// Create .bpkg/ and its subdirectories.
//
{
- mk (c / bpkg_dir);
+ dir_path d (c / bpkg_dir);
+
+ mk (d);
mk (c / certs_dir);
mk (c / repos_dir);
+
+ // Create the .gitignore file that ignores everything under .bpkg/
+ // effectively making git ignore it (this prevents people from
+ // accidentally adding this directory to a git repository).
+ //
+ path f (d / ".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;
+ }
}
// Initialize tmp directory.