diff --git a/source/app.d b/source/app.d index 6633a1e..4b40f32 100644 --- a/source/app.d +++ b/source/app.d @@ -15,7 +15,12 @@ int main(string[] args) } auto argumets = new Program(programName, snagVersion) - .add(new Command("init", "Initializing the repository for storing snapshots")) + .add(new Command("init", "Initializing the repository for storing snapshots") + .add(new Flag("f", "force", "Initializing a repository with overwriting the existing one") + .name("force") + .optional + ) + ) .add(new Command("status", "Checking the status of tracked files")) .add(new Command("diff", "Show changed data")) .add(new Command("import", "Import snapshot from a tar.gz archive") @@ -117,7 +122,7 @@ int main(string[] args) try { argumets .on("init", init => - snag.initialize() + snag.initialize(init.flag("force")) ) .on("diff", diff => snag.diff() diff --git a/source/snag/core/core.d b/source/snag/core/core.d index 34e75ae..e70ce62 100644 --- a/source/snag/core/core.d +++ b/source/snag/core/core.d @@ -44,13 +44,18 @@ class Snag { return result; } - void initialize() { + void initialize(bool force) { auto result = execute(_baseCommand ~ ["rev-parse", "--git-dir"]); - !result.status && + !force && !result.status && throw new SnagException( "The Git repository has already been initialized: " ~ result.output.strip('\n') ); + + force && _config.git.exists + && _config.git.isDir + && _config.git.rmdirRecurse; + git( ["init", "--initial-branch=default"], "A Git repository initialization error occurred"