class WithGitRepo
Constants
- VERSION
Attributes
clone_url[R]
user_email[R]
user_name[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/with_git_repo.rb, line 9 def initialize(options = {}) @clone_url = options.fetch(:clone_url) @user_name = options.fetch(:user_name, 'with_git_repo') @user_email = options.fetch(:user_email, 'with_git_repo@everypolitician.org') end
Public Instance Methods
commit_changes_to_branch(branch, message) { || ... }
click to toggle source
# File lib/with_git_repo.rb, line 15 def commit_changes_to_branch(branch, message) checkout_branch!(branch) git.chdir { yield } git.add return unless git.status.changed.any? || git.status.added.any? git.commit(message) git.push('origin', branch) end
Private Instance Methods
checkout_branch!(branch)
click to toggle source
# File lib/with_git_repo.rb, line 26 def checkout_branch!(branch) if git.branches[branch] || git.branches["origin/#{branch}"] git.checkout(branch) else git.checkout(branch, new_branch: true) end end
git()
click to toggle source
# File lib/with_git_repo.rb, line 34 def git @git ||= Git.clone(clone_url, '.', path: tmpdir).tap do |g| g.config('user.name', user_name) g.config('user.email', user_email) end end
tmpdir()
click to toggle source
# File lib/with_git_repo.rb, line 41 def tmpdir @tmpdir ||= Dir.mktmpdir end