Require git to exit successfully in Utils#commit

This commit is contained in:
0x1eef 2024-06-22 02:01:18 -03:00
parent 9b3822bf1e
commit a7e413310c

View file

@ -12,6 +12,10 @@ module Utils
require_relative "utils/erb"
require_relative "utils/opengraph"
##
# Generic error
Error = Class.new(RuntimeError) unless defined?(Error)
##
# @return [Ryo::Object]
# Returns common directory paths as a Ryo object
@ -46,15 +50,17 @@ module Utils
end
##
# @note
# This method returns the website version in
# case git fails or is unavailable
# @raise [Utils::Error]
# When git fails or is unavailable
# @return [String]
# Returns the most recent git commit hash
def commit
@commit ||= begin
r = cmd("git", "rev-parse", "HEAD")
r.success? ? r.stdout.strip : version
hash = nil
cmd("git", "rev-parse", "HEAD")
.success { hash = _1.stdout.strip }
.failure { raise(Error, "git exited unsuccessfully in method Utils#commit", []) }
hash
end
end