diff --git a/Gemfile b/Gemfile index 957cbbd227..cca435f0b8 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem 'rubocop', '>= 1.31.0' gem 'gettext' gem 'prism', '>= 0.30.0' gem 'webrick' +gem 'git' platforms :ruby do if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.2') diff --git a/lib/rdoc/generator/template/aliki/_footer.rhtml b/lib/rdoc/generator/template/aliki/_footer.rhtml index 525d853dec..f2c573045d 100644 --- a/lib/rdoc/generator/template/aliki/_footer.rhtml +++ b/lib/rdoc/generator/template/aliki/_footer.rhtml @@ -18,6 +18,9 @@

Generated by RDoc <%= RDoc::VERSION %> using the Aliki theme by Stan Lo + <% if @options.git_commit_sha %> + Generated with commit <%= @options.git_commit_sha %> + <% end %>

diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index c3f16d37b1..943bca2a69 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -393,6 +393,10 @@ class RDoc::Options attr_accessor :footer_content + ## + # Git hash value + attr_accessor :git_commit_sha + def initialize(loaded_options = nil) # :nodoc: init_ivars override loaded_options if loaded_options @@ -450,6 +454,7 @@ def init_ivars # :nodoc: @file_path_prefix = nil @canonical_root = nil @footer_content = nil + @git_commit_sha = nil end def init_with(map) # :nodoc: diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index 8beeac52f5..54b389f72f 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -468,6 +468,8 @@ def document(options) @options.default_title = "RDoc Documentation" + @options.git_commit_sha = detect_git_commit + @store.complete @options.visibility @stats.coverage_level = @options.coverage_report @@ -494,6 +496,13 @@ def document(options) exit @stats.fully_documented? if @options.coverage_report end + def detect_git_commit + require "git" + Git.open(Dir.pwd).object("HEAD").sha + rescue StandardError + nil + end + ## # Generates documentation for +file_info+ (from #parse_files) into the # output dir using the generator selected diff --git a/test/rdoc/rdoc_options_test.rb b/test/rdoc/rdoc_options_test.rb index be87b39d78..376e8f1909 100644 --- a/test/rdoc/rdoc_options_test.rb +++ b/test/rdoc/rdoc_options_test.rb @@ -91,6 +91,7 @@ def test_to_yaml 'file_path_prefix' => nil, 'canonical_root' => nil, 'footer_content' => nil, + 'git_commit_sha' => nil, } assert_equal expected, coder