class PerfCheck::Git
Attributes
current_branch[R]
git_root[R]
logger[RW]
perf_check[R]
Public Class Methods
new(perf_check)
click to toggle source
# 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
Public Instance Methods
anything_to_stash?()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/perf_check/git.rb, line 78 def clean_db exec "git checkout db" end
migrations_to_run_down()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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?()
click to toggle source
# File lib/perf_check/git.rb, line 52 def stashed? !!@stashed end
Private Instance Methods
bundle()
click to toggle source
# File lib/perf_check/git.rb, line 88 def bundle Bundler.with_original_env{ exec "bundle" } unless $?.success? logger.fatal("Problem bundling! Bailing...") raise BundleError end end
current_migrations_not_on_master()
click to toggle source
# File lib/perf_check/git.rb, line 96 def current_migrations_not_on_master exec("git diff master --name-only --diff-filter=A db/migrate/"). split.reverse end
exec(command)
click to toggle source
# File lib/perf_check/git.rb, line 101 def exec(command) root = Shellwords.shellescape(git_root) `cd #{root} && #{command}`.strip end
update_submodules()
click to toggle source
# File lib/perf_check/git.rb, line 84 def update_submodules exec "git submodule update --quiet" end