lib/unwrappr/git_command_runner.rb in unwrappr-0.4.0 vs lib/unwrappr/git_command_runner.rb in unwrappr-0.5.0
- old
+ new
@@ -5,19 +5,19 @@
module Unwrappr
# Runs Git commands
module GitCommandRunner
class << self
- def create_branch!
+ def create_branch!(base_branch:)
raise 'Not a git working dir' unless git_dir?
- raise 'failed to create branch' unless branch_created?
+ raise "failed to create branch from '#{base_branch}'" unless checkout_target_branch(base_branch: base_branch)
end
def commit_and_push_changes!
- raise 'failed to add git changes' unless git_added_changes?
- raise 'failed to commit changes' unless git_committed?
- raise 'failed to push changes' unless git_pushed?
+ raise 'failed to add git changes' unless stage_all_changes
+ raise 'failed to commit changes' unless commit_staged_changes
+ raise 'failed to push changes' unless push_current_branch_to_origin
end
def reset_client
@git = nil
end
@@ -48,27 +48,27 @@
def git_dir?
git_wrap { !current_branch_name.empty? }
end
- def branch_created?
+ def checkout_target_branch(base_branch:)
timestamp = Time.now.strftime('%Y%m%d-%H%M').freeze
git_wrap do
- git.checkout('origin/master')
+ git.checkout(base_branch) unless base_branch.nil?
git.branch("auto_bundle_update_#{timestamp}").checkout
end
end
- def git_added_changes?
+ def stage_all_changes
git_wrap { git.add(all: true) }
end
- def git_committed?
+ def commit_staged_changes
git_wrap { git.commit('Automatic Bundle Update') }
end
- def git_pushed?
+ def push_current_branch_to_origin
git_wrap { git.push('origin', current_branch_name) }
end
def git
if Dir.pwd == @git&.dir&.path
@@ -78,10 +78,10 @@
end
end
def log_options
{}.tap do |opt|
- opt[:log] = Logger.new(STDOUT) if ENV['DEBUG']
+ opt[:log] = Logger.new($stdout) if ENV['DEBUG']
end
end
def git_wrap
yield