Class: Debtective::FindCommit
- Inherits:
-
Object
- Object
- Debtective::FindCommit
- Defined in:
- lib/debtective/find_commit.rb
Overview
find the commit that introduced a line of code
Defined Under Namespace
Constant Summary collapse
- SPECIAL_CHARACTER_REGEX =
/(?!\w|\s|#|:).+/
Instance Method Summary collapse
- #author ⇒ Debtective::FindCommit::Author
- #call ⇒ Debtective::FindCommit::Commit
- #commit ⇒ Git::Object::Commit
- #git ⇒ Git::Base
-
#initialize(pathname, code) ⇒ FindCommit
constructor
A new instance of FindCommit.
-
#safe_code ⇒ String
characters “ and ‘ can break the git command.
-
#sha ⇒ String
commit sha.
- #time ⇒ Time
Constructor Details
#initialize(pathname, code) ⇒ FindCommit
Returns a new instance of FindCommit.
16 17 18 19 |
# File 'lib/debtective/find_commit.rb', line 16 def initialize(pathname, code) @pathname = pathname @code = code end |
Instance Method Details
#author ⇒ Debtective::FindCommit::Author
30 31 32 |
# File 'lib/debtective/find_commit.rb', line 30 def Author.new(commit..email, commit..name) end |
#call ⇒ Debtective::FindCommit::Commit
22 23 24 25 26 27 |
# File 'lib/debtective/find_commit.rb', line 22 def call Commit.new(sha, , time) rescue Git::GitExecuteError = Author.new(nil, nil) Commit.new(nil, , nil) end |
#commit ⇒ Git::Object::Commit
45 46 47 |
# File 'lib/debtective/find_commit.rb', line 45 def commit git.gcommit(sha) end |
#git ⇒ Git::Base
40 41 42 |
# File 'lib/debtective/find_commit.rb', line 40 def git Git.open(".") end |
#safe_code ⇒ String
characters “ and ‘ can break the git command
62 63 64 |
# File 'lib/debtective/find_commit.rb', line 62 def safe_code @code.gsub(/"/, "\\\"").gsub("`", "\\\\`") end |
#sha ⇒ String
commit sha
51 52 53 54 55 56 57 58 |
# File 'lib/debtective/find_commit.rb', line 51 def sha @sha ||= begin cmd = "git log -S \"#{safe_code}\" #{@pathname}" stdout, _stderr, _status = ::Open3.capture3(cmd) stdout[/commit (\w{40})\n/, 1] end end |
#time ⇒ Time
35 36 37 |
# File 'lib/debtective/find_commit.rb', line 35 def time commit.date end |