Class: Mbeditor::GitFileHistoryService
- Inherits:
-
Object
- Object
- Mbeditor::GitFileHistoryService
- Includes:
- GitService
- Defined in:
- app/services/mbeditor/git_file_history_service.rb
Overview
Returns the per-file commit history using ‘git log –follow`.
Each entry:
{
"hash" => String,
"title" => String,
"author" => String,
"date" => String # ISO-8601
}
Constant Summary collapse
- MAX_COMMITS =
200
Constants included from GitService
Mbeditor::GitService::SAFE_GIT_REF
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#repo_path ⇒ Object
readonly
Returns the value of attribute repo_path.
Instance Method Summary collapse
-
#call ⇒ Object
Returns Array of commit hashes for the file.
-
#initialize(repo_path:, file_path:) ⇒ GitFileHistoryService
constructor
A new instance of GitFileHistoryService.
Methods included from GitService
ahead_behind, current_branch, parse_git_log, parse_git_log_with_parents, resolve_path, run_git, upstream_branch
Constructor Details
#initialize(repo_path:, file_path:) ⇒ GitFileHistoryService
Returns a new instance of GitFileHistoryService.
20 21 22 23 |
# File 'app/services/mbeditor/git_file_history_service.rb', line 20 def initialize(repo_path:, file_path:) @repo_path = repo_path.to_s @file_path = file_path.to_s end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
18 19 20 |
# File 'app/services/mbeditor/git_file_history_service.rb', line 18 def file_path @file_path end |
#repo_path ⇒ Object (readonly)
Returns the value of attribute repo_path.
18 19 20 |
# File 'app/services/mbeditor/git_file_history_service.rb', line 18 def repo_path @repo_path end |
Instance Method Details
#call ⇒ Object
Returns Array of commit hashes for the file.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/mbeditor/git_file_history_service.rb', line 26 def call output, status = GitService.run_git( repo_path, "log", "--follow", "-n", MAX_COMMITS.to_s, "--pretty=format:%H%x1f%s%x1f%an%x1f%aI%x1e", "--", file_path ) raise "git log failed for #{file_path}" unless status.success? GitService.parse_git_log(output) end |