From a2131ec5742e68abc4b3aedbb1bbf7463ce30011 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Wed, 28 May 2025 02:28:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20pre=20=D0=B8=20post=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/snag/core/core.d | 43 ++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/source/snag/core/core.d b/source/snag/core/core.d index ef51792..7b05b61 100644 --- a/source/snag/core/core.d +++ b/source/snag/core/core.d @@ -61,6 +61,32 @@ class Snag { return formatted && fullStatus.length < 8 ? fullStatus ~ "\t" : fullStatus; } + void executePreSnag() { + _config.presnag().each!((command) { + auto result = executeShell(command); + result.status && throw new SnagException( + "%s:\n\t%s\n\n%s".format( + "An error occurred during presnag-command execution", + command, + result.output + ) + ); + }); + } + + void executePostSnag() { + _config.postsnag().each!((command) { + auto result = executeShell(command); + result.status && throw new SnagException( + "%s:\n\t%s\n\n%s".format( + "An error occurred during postsnag-command execution", + command, + result.output + ) + ); + }); + } + void initialize(bool force) { auto result = execute(_baseCommand ~ ["rev-parse", "--git-dir"]); !force && !result.status && @@ -127,13 +153,18 @@ class Snag { email.length && (environment["GIT_AUTHOR_EMAIL"] = email); string message = comment.length ? comment : "Standard snapshot creation"; + string newSnapshot; result = execute(_baseCommand ~ ["rev-parse", "--short", "HEAD"]); if (result.status == 128) { // Если это самый первый коммит после инициализации репозитория git(["add", "."], "Failed to prepare files for archiving"); - git(["commit", "-m"] ~ message, "Failed to create a backup"); - writeln("Backup was created successfully"); + git(["commit", "-m"] ~ message, "Failed to create a snapshot"); + newSnapshot = git( + ["rev-parse", "--short", "HEAD"], + "Failed to retrieve current snapshot information" + ).output.strip('\n'); + writeln("Snapshot was created successfully: ", newSnapshot); return; } else if (result.status != 0) throw new SnagException( @@ -157,8 +188,6 @@ class Snag { "Failed to get the commit list between HEAD and " ~ currentBranch ); - string newSnapshot; - // Если список существует if (result.output.length) { // Если коммит не является последним, то необходимо ответвление @@ -173,7 +202,7 @@ class Snag { ); git( ["commit", "-m"] ~ message, - "Failed to create a backup" + "Failed to create a snapshot" ); newSnapshot = git( ["rev-parse", "--short", "HEAD"], @@ -187,7 +216,7 @@ class Snag { ); git( ["commit", "-m"] ~ message, - "Failed to create a backup" + "Failed to create a snapshot" ); newSnapshot = git( ["rev-parse", "--short", "HEAD"], @@ -202,7 +231,7 @@ class Snag { "Issue with including the commit into the branch " ~ currentBranch ); } - writeln("Backup was created successfully: ", newSnapshot); + writeln("Snapshot was created successfully: ", newSnapshot); } void list(bool comment, bool author, bool email) {