Prevent git errors from showing in command output

This would be a very rare case, but one time the git command failed, printing out an obscure "fatal" message to stderr which caused confusion.
This commit is contained in:
David Cook
2023-07-28 12:07:49 +10:00
parent 774bb7a607
commit febe6501c0
2 changed files with 18 additions and 2 deletions

15
lib/git_utils.rb Normal file
View File

@@ -0,0 +1,15 @@
class GitUtils
# Generate a description of the git version based on latest tag.
# Eg: "v4.4.4-156-g8afcd82-modified"
# - tag name
# - number of commits since tag
# - commit ID
# - "modified" if uncommitted changes
#
def self.git_version
# Capture stderr so that confusing errors aren't shown in comand output
stdout, _stderr, _status = Open3.capture3("git describe --tags --dirty=-modified")
# Strip trailing linebreak
stdout.strip
end
end