Class: PerfCheck::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/perf_check/git.rb

Class Method Summary collapse

Class Method Details

.anything_to_stash?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/perf_check/git.rb', line 40

def self.anything_to_stash?
  git_stash = `git diff`
  git_stash << `git diff --staged`
  !git_stash.empty?
end

.checkout(branch) ⇒ Object



23
24
25
26
27
# File 'lib/perf_check/git.rb', line 23

def self.checkout(branch)
  $stderr.print "Checking out #{branch}... "
  `git checkout #{branch} --quiet`
  abort "Problem with git checkout! Bailing..." unless $?.success?
end

.checkout_current_branchObject



19
20
21
# File 'lib/perf_check/git.rb', line 19

def self.checkout_current_branch
  checkout(@current_branch)
end

.checkout_reference(reference = 'master') ⇒ Object



11
12
13
14
15
16
17
# File 'lib/perf_check/git.rb', line 11

def self.checkout_reference(reference='master')
  checkout(reference)
  at_exit do
    $stderr.puts
    Git.checkout_current_branch
  end
end

.current_branchObject



7
8
9
# File 'lib/perf_check/git.rb', line 7

def self.current_branch
  @current_branch
end

.popObject



46
47
48
49
50
# File 'lib/perf_check/git.rb', line 46

def self.pop
  warn("Git stash applying...")
  system('git stash pop -q')
  abort("Problem with git stash! Bailing...") unless $?.success?
end

.stash_if_neededObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/perf_check/git.rb', line 29

def self.stash_if_needed
  if anything_to_stash?
    $stderr.print("Stashing your changes... ")
    system('git stash -q >/dev/null')
    abort("Problem with git stash! Bailing...") unless $?.success?
    at_exit do
      Git.pop
    end
  end
end