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 = perf_check.options.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
56
57
58
59
60
|
# File 'lib/perf_check/git.rb', line 56
def anything_to_stash?
git_stash = exec "git diff"
git_stash << exec("git diff --staged")
!git_stash.empty?
end
|
#checkout(branch, bundle_after_checkout: true, hard_reset: false) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/perf_check/git.rb', line 21
def checkout(branch, bundle_after_checkout: true, hard_reset: false)
logger.info("Checking out #{branch} and bundling... ")
if hard_reset
exec "git fetch --quiet && git reset --hard origin/#{branch} --quiet"
else
exec "git checkout #{branch} --quiet"
end
unless $?.success?
logger.fatal("Problem with git checkout! Bailing...")
raise NoSuchBranch
end
update_submodules
bundle if bundle_after_checkout
end
|
#clean_db ⇒ Object
78
79
80
|
# File 'lib/perf_check/git.rb', line 78
def clean_db
exec "git checkout db"
end
|
#migrations_to_run_down ⇒ Object
72
73
74
75
76
|
# File 'lib/perf_check/git.rb', line 72
def migrations_to_run_down
current_migrations_not_on_master.map do |filename|
File.basename(filename, '.rb').split('_').first
end
end
|
#pop ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/perf_check/git.rb', line 62
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
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/perf_check/git.rb', line 38
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
52
53
54
|
# File 'lib/perf_check/git.rb', line 52
def stashed?
!!@stashed
end
|