Class: Gistory::GitRepo
- Inherits:
-
Object
- Object
- Gistory::GitRepo
- Defined in:
- lib/gistory/git_repo.rb
Instance Method Summary collapse
- #changes_to_file(filename) ⇒ Object
- #file_content_at_commit(commit_hash, filename) ⇒ Object
-
#initialize(path:) ⇒ GitRepo
constructor
A new instance of GitRepo.
Constructor Details
#initialize(path:) ⇒ GitRepo
Returns a new instance of GitRepo.
7 8 9 10 |
# File 'lib/gistory/git_repo.rb', line 7 def initialize(path:) raise(Gistory::Error, "This is not a valid git repository") unless Dir.exist?(File.join(path, ".git")) raise(Gistory::Error, "git is not available, please install it") unless git_cli_available? end |
Instance Method Details
#changes_to_file(filename) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/gistory/git_repo.rb', line 12 def changes_to_file(filename) max_count = Gistory.config.max_fetched_commits strategy = git_log_strategy(filename) hashes_and_dates = git("log --pretty=format:'%h|%cD' --max-count=#{max_count} #{strategy}") to_commits(hashes_and_dates.split("\n")) end |
#file_content_at_commit(commit_hash, filename) ⇒ Object
19 20 21 |
# File 'lib/gistory/git_repo.rb', line 19 def file_content_at_commit(commit_hash, filename) git("show #{commit_hash}:#{filename}") end |