Class: PerfCheck::Git
- Inherits:
-
Object
show all
- Defined in:
- lib/perf_check/git.rb
Defined Under Namespace
Classes: BundleError, NoSuchBranch, StashError, StashPopError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(perf_check) ⇒ Git
Returns a new instance of Git.
13
14
15
16
17
18
19
|
# File 'lib/perf_check/git.rb', line 13
def initialize(perf_check)
@perf_check = perf_check
@git_root = perf_check.app_root
@logger = perf_check.logger
@current_branch = exec "git rev-parse --abbrev-ref HEAD"
end
|
Instance Attribute Details
#current_branch ⇒ Object
Returns the value of attribute current_branch.
10
11
12
|
# File 'lib/perf_check/git.rb', line 10
def current_branch
@current_branch
end
|
#git_root ⇒ Object
Returns the value of attribute git_root.
10
11
12
|
# File 'lib/perf_check/git.rb', line 10
def git_root
@git_root
end
|
#logger ⇒ Object
Returns the value of attribute logger.
11
12
13
|
# File 'lib/perf_check/git.rb', line 11
def logger
@logger
end
|
#perf_check ⇒ Object
Returns the value of attribute perf_check.
10
11
12
|
# File 'lib/perf_check/git.rb', line 10
def perf_check
@perf_check
end
|
Instance Method Details
#anything_to_stash? ⇒ Boolean
67
68
69
70
71
|
# File 'lib/perf_check/git.rb', line 67
def anything_to_stash?
git_stash = exec "git diff"
git_stash << exec("git diff --staged")
!git_stash.empty?
end
|
#checkout(branch, bundle = true) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/perf_check/git.rb', line 29
def checkout(branch, bundle=true)
logger.info("Checking out #{branch} and bundling... ")
exec "git checkout #{branch} --quiet"
unless $?.success?
logger.fatal("Problem with git checkout! Bailing...")
raise NoSuchBranch
end
exec "git submodule update --quiet"
if bundle
Bundler.with_clean_env{ exec "bundle" }
unless $?.success?
logger.fatal("Problem bundling! Bailing...")
raise BundleError
end
end
end
|
#checkout_current_branch(bundle = true) ⇒ Object
25
26
27
|
# File 'lib/perf_check/git.rb', line 25
def checkout_current_branch(bundle=true)
checkout(@current_branch, bundle)
end
|
#checkout_reference(reference = 'master') ⇒ Object
21
22
23
|
# File 'lib/perf_check/git.rb', line 21
def checkout_reference(reference='master')
checkout(reference)
end
|
#clean_db ⇒ Object
89
90
91
|
# File 'lib/perf_check/git.rb', line 89
def clean_db
exec "git checkout db"
end
|
#migrations_to_run_down ⇒ Object
83
84
85
86
87
|
# File 'lib/perf_check/git.rb', line 83
def migrations_to_run_down
current_migrations_not_on_master.map do |filename|
File.basename(filename, '.rb').split('_').first
end
end
|
#pop ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/perf_check/git.rb', line 73
def pop
logger.info("Git stash applying...")
exec "git stash pop -q"
unless $?.success?
logger.fatal("Problem with git stash! Bailing...")
raise StashPopError
end
end
|
#stash_if_needed ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/perf_check/git.rb', line 49
def stash_if_needed
if anything_to_stash?
logger.info("Stashing your changes... ")
exec "git stash -q >/dev/null"
unless $?.success?
logger.fatal("Problem with git stash! Bailing...")
raise StashError
end
@stashed = true
end
end
|
#stashed? ⇒ Boolean
63
64
65
|
# File 'lib/perf_check/git.rb', line 63
def stashed?
!!@stashed
end
|