From fa32d6d240de24e11aa0239d240e136ae8876341 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 10 May 2021 10:05:52 +0200 Subject: Generate .gitignore in .bpkg/ to prevent accidentally committing it --- bpkg/cfg-create.cxx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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. -- cgit v1.1