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) {