Class: Zubat::GitCommandWrapper
- Inherits:
-
Object
- Object
- Zubat::GitCommandWrapper
- Defined in:
- lib/zubat/git_command_wrapper.rb
Defined Under Namespace
Modules: Stub
Constant Summary collapse
- Log =
Data.define(:sha, :time)
Class Method Summary collapse
Instance Method Summary collapse
- #diff(sha:, file:) ⇒ Object
- #exists?(sha:, file:) ⇒ Boolean
- #log(files:) ⇒ Object
- #remote_origin_url ⇒ Object
- #show(sha:, file:) ⇒ Object
Class Method Details
Instance Method Details
#diff(sha:, file:) ⇒ Object
88 89 90 |
# File 'lib/zubat/git_command_wrapper.rb', line 88 def diff(sha:, file:) `git show #{sha} -- #{file}` end |
#exists?(sha:, file:) ⇒ Boolean
80 81 82 |
# File 'lib/zubat/git_command_wrapper.rb', line 80 def exists?(sha:, file:) !`git ls-tree -r #{sha} -- #{file} 2>/dev/null`.empty? end |
#log(files:) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/zubat/git_command_wrapper.rb', line 64 def log(files:) logs = `git log --oneline --pretty=format:'{ "sha": "%h", "time": "%ad" }' -- #{files.join(' ')}`.split("\n") logs.map! do |log| args = JSON.parse(log, symbolize_names: true) Log.new(sha: args[:sha], time: Time.parse(args[:time])) end logs.sort_by!(&:time) logs.reverse! logs end |
#remote_origin_url ⇒ Object
60 61 62 |
# File 'lib/zubat/git_command_wrapper.rb', line 60 def remote_origin_url `git config --get remote.origin.url`.chomp end |
#show(sha:, file:) ⇒ Object
84 85 86 |
# File 'lib/zubat/git_command_wrapper.rb', line 84 def show(sha:, file:) `git show #{sha}:#{file}` end |