# frozen_string_literal: true require 'rugged' require 'rugged/repository' module Booru # A helper class for reading the current repository # version. class VersionReader # Get a new reference to the application repository. # # This is not memoized, so as to avoid holding a long-lived # reference to a repository object in the application. # # @return [Rugged::Repository] def self.repo Rugged::Repository.new(Rails.root.to_s) end # The current branch name as a string (e.g. "master"). # # @return [String] def self.branch_name repo.branches.detect(&:head?).name rescue ArgumentError 'unknown' end # The object id of the most recent commit as a string # (e.g. "3717f613f48df0222311f974cf8a06c8a6c97bae"). # # @return [String] def self.head_commit repo.head.target.oid rescue ArgumentError 'unknown' end end end