From db9a6be9f439ee4f41096ba02cbe6d5238e3c7d1 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Tue, 27 May 2025 00:12:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D1=80=D0=B5=D0=BF=D0=BE?= =?UTF-8?q?=D0=B7=D0=B8=D1=82=D0=BE=D1=80=D0=B8=D1=8F=20=D1=81=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C=D1=8E=20?= =?UTF-8?q?=D1=81=D1=83=D1=89=D0=B5=D1=81=D1=82=D0=B2=D1=83=D1=8E=D1=89?= =?UTF-8?q?=D0=B5=D0=B3=D0=BE=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D1=84?= =?UTF-8?q?=D0=BB=D0=B0=D0=B3=20force?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/app.d | 9 +++++++-- source/snag/core/core.d | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) 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"