Module: Spoom::Git
- Extended by:
- T::Sig
- Defined in:
- lib/spoom/git.rb
Overview
Execute git commands
Class Method Summary collapse
- .checkout(*arg, path: ".") ⇒ Object
- .commit_time(sha, path: ".") ⇒ Object
- .commit_timestamp(sha, path: ".") ⇒ Object
- .diff(*arg, path: ".") ⇒ Object
- .epoch_to_time(timestamp) ⇒ Object
- .exec(command, *arg, path: '.') ⇒ Object
- .last_commit(path: ".") ⇒ Object
- .log(*arg, path: ".") ⇒ Object
- .rev_parse(*arg, path: ".") ⇒ Object
- .show(*arg, path: ".") ⇒ Object
- .sorbet_intro_commit(path: ".") ⇒ Object
- .workdir_clean?(path: ".") ⇒ Boolean
Class Method Details
.checkout(*arg, path: ".") ⇒ Object
28 29 30 |
# File 'lib/spoom/git.rb', line 28 def self.checkout(*arg, path: ".") exec("git checkout -q #{arg.join(' ')}", path: path) end |
.commit_time(sha, path: ".") ⇒ Object
64 65 66 67 68 |
# File 'lib/spoom/git.rb', line 64 def self.commit_time(sha, path: ".") = (sha, path: path) return nil unless epoch_to_time(.to_s) end |
.commit_timestamp(sha, path: ".") ⇒ Object
56 57 58 59 60 |
# File 'lib/spoom/git.rb', line 56 def self.(sha, path: ".") out, _, status = show("--no-notes --no-patch --pretty=%at #{sha}", path: path) return nil unless status out.strip.to_i end |
.diff(*arg, path: ".") ⇒ Object
33 34 35 |
# File 'lib/spoom/git.rb', line 33 def self.diff(*arg, path: ".") exec("git diff #{arg.join(' ')}", path: path) end |
.epoch_to_time(timestamp) ⇒ Object
80 81 82 |
# File 'lib/spoom/git.rb', line 80 def self.epoch_to_time() Time.strptime(, "%s") end |
.exec(command, *arg, path: '.') ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# 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 _, 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 [out, err, T.cast(s.value, Process::Status).success?] end |
.last_commit(path: ".") ⇒ Object
72 73 74 75 76 |
# File 'lib/spoom/git.rb', line 72 def self.last_commit(path: ".") out, _, status = rev_parse("HEAD", path: path) return nil unless status out.strip end |
.log(*arg, path: ".") ⇒ Object
38 39 40 |
# File 'lib/spoom/git.rb', line 38 def self.log(*arg, path: ".") exec("git log #{arg.join(' ')}", path: path) end |
.rev_parse(*arg, path: ".") ⇒ Object
43 44 45 |
# File 'lib/spoom/git.rb', line 43 def self.rev_parse(*arg, path: ".") exec("git rev-parse --short #{arg.join(' ')}", path: path) end |
.show(*arg, path: ".") ⇒ Object
48 49 50 |
# File 'lib/spoom/git.rb', line 48 def self.show(*arg, path: ".") exec("git show #{arg.join(' ')}", path: path) end |
.sorbet_intro_commit(path: ".") ⇒ Object
92 93 94 95 96 |
# File 'lib/spoom/git.rb', line 92 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 end |
.workdir_clean?(path: ".") ⇒ Boolean
86 87 88 |
# File 'lib/spoom/git.rb', line 86 def self.workdir_clean?(path: ".") diff("HEAD", path: path).first.empty? end |