Class: Zubat::GitCommandWrapper

Inherits:
Object
  • Object
show all
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

Class Method Details

.newObject



54
55
56
57
58
# File 'lib/zubat/git_command_wrapper.rb', line 54

def self.new
  instance = super
  instance.extend(Stub) if Zubat.stubbed?
  instance
end

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

Returns:

  • (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_urlObject



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