module Spoom::Git
Execute git commands
Public Class Methods
checkout(*arg, path: ".")
click to toggle source
# File lib/spoom/git.rb, line 29 def self.checkout(*arg, path: ".") exec("git checkout -q #{arg.join(' ')}", path: path) end
commit_time(sha, path: ".")
click to toggle source
# File lib/spoom/git.rb, line 72 def self.commit_time(sha, path: ".") timestamp = commit_timestamp(sha, path: path) return nil unless timestamp epoch_to_time(timestamp.to_s) end
commit_timestamp(sha, path: ".")
click to toggle source
# File lib/spoom/git.rb, line 64 def self.commit_timestamp(sha, path: ".") out, _, status = show("--no-notes --no-patch --pretty=%at #{sha}", path: path) return nil unless status out.strip.to_i end
current_branch(path: ".")
click to toggle source
# File lib/spoom/git.rb, line 54 def self.current_branch(path: ".") out, _, status = exec("git branch --show-current", path: path) return nil unless status out.strip end
diff(*arg, path: ".")
click to toggle source
# File lib/spoom/git.rb, line 34 def self.diff(*arg, path: ".") exec("git diff #{arg.join(' ')}", path: path) end
epoch_to_time(timestamp)
click to toggle source
# File lib/spoom/git.rb, line 88 def self.epoch_to_time(timestamp) Time.strptime(timestamp, "%s") end
exec(command, *arg, path: '.')
click to toggle source
# File lib/spoom/git.rb, line 13 def self.exec(command, *arg, path: '.') return "", "Error: `#{path}` is not a directory.", false unless File.directory?(path) opts = {} opts[:chdir] = path i, o, e, s = Open3.popen3(*T.unsafe([command, *T.unsafe(arg), opts])) out = o.read.to_s o.close err = e.read.to_s e.close i.close [out, err, T.cast(s.value, Process::Status).success?] end
last_commit(path: ".")
click to toggle source
# File lib/spoom/git.rb, line 80 def self.last_commit(path: ".") out, _, status = rev_parse("HEAD", path: path) return nil unless status out.strip end
log(*arg, path: ".")
click to toggle source
# File lib/spoom/git.rb, line 39 def self.log(*arg, path: ".") exec("git log #{arg.join(' ')}", path: path) end
rev_parse(*arg, path: ".")
click to toggle source
# File lib/spoom/git.rb, line 44 def self.rev_parse(*arg, path: ".") exec("git rev-parse --short #{arg.join(' ')}", path: path) end
show(*arg, path: ".")
click to toggle source
# File lib/spoom/git.rb, line 49 def self.show(*arg, path: ".") exec("git show #{arg.join(' ')}", path: path) end
sorbet_intro_commit(path: ".")
click to toggle source
# File lib/spoom/git.rb, line 100 def self.sorbet_intro_commit(path: ".") res, _, status = Spoom::Git.log("--diff-filter=A --format='%h' -1 -- sorbet/config", path: path) return nil unless status res.strip! return nil if res.empty? res end
sorbet_removal_commit(path: ".")
click to toggle source
# File lib/spoom/git.rb, line 110 def self.sorbet_removal_commit(path: ".") res, _, status = Spoom::Git.log("--diff-filter=D --format='%h' -1 -- sorbet/config", path: path) return nil unless status res.strip! return nil if res.empty? res end
workdir_clean?(path: ".")
click to toggle source
# File lib/spoom/git.rb, line 94 def self.workdir_clean?(path: ".") diff("HEAD", path: path).first.empty? end