Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 3 additions & 0 deletions lib/rdoc/generator/template/aliki/_footer.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<p>
Generated by <a href="https://ruby.github.io/rdoc/">RDoc <%= RDoc::VERSION %></a>
using the Aliki theme by <a href="http://st0012.dev">Stan Lo</a>
<% if @options.git_commit_sha %>
Generated with commit <%= @options.git_commit_sha %>
<% end %>
</p>
</div>
</footer>
5 changes: 5 additions & 0 deletions lib/rdoc/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions lib/rdoc/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link
Copy Markdown
Contributor

@extern-c extern-c Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider using Ruby's Open3.capture3 to run Git commands directly and capture the output you need, instead of relying on the git gem. This can simplify things if you only need to run a single command.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!! @extern-c
I changed the code to use Open3.capture3.

rescue StandardError
nil
end

##
# Generates documentation for +file_info+ (from #parse_files) into the
# output dir using the generator selected
Expand Down
1 change: 1 addition & 0 deletions test/rdoc/rdoc_options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down