class PrComet::Git::Command
To execute git command
Public Class Methods
new(user_name: nil, user_email: nil, verbose: false)
click to toggle source
# File lib/pr_comet/git/command.rb, line 9 def initialize(user_name: nil, user_email: nil, verbose: false) @user_name = user_name @user_email = user_email @verbose = verbose end
Public Instance Methods
add(*files)
click to toggle source
# File lib/pr_comet/git/command.rb, line 35 def add(*files) run('add', *files) end
checkout(branch)
click to toggle source
# File lib/pr_comet/git/command.rb, line 27 def checkout(branch) run('checkout', branch) end
checkout_with(new_branch)
click to toggle source
# File lib/pr_comet/git/command.rb, line 31 def checkout_with(new_branch) run('checkout', '-b', new_branch) end
commit(message)
click to toggle source
# File lib/pr_comet/git/command.rb, line 39 def commit(message) run_with_environments('commit', '-m', "\"#{message}\"") end
current_branch()
click to toggle source
# File lib/pr_comet/git/command.rb, line 61 def current_branch run('rev-parse', '--abbrev-ref', 'HEAD') end
current_branch?(branch)
click to toggle source
# File lib/pr_comet/git/command.rb, line 65 def current_branch?(branch) current_branch == branch.to_s end
current_sha1()
click to toggle source
# File lib/pr_comet/git/command.rb, line 53 def current_sha1 run('rev-parse', 'HEAD') end
current_sha1?(sha1)
click to toggle source
# File lib/pr_comet/git/command.rb, line 57 def current_sha1?(sha1) current_sha1 == sha1.to_s end
exist_uncommitted_modify?()
click to toggle source
# File lib/pr_comet/git/command.rb, line 23 def exist_uncommitted_modify? execute('git add -n .; git diff --name-only') != '' end
push(remote, branch = current_branch)
click to toggle source
Execute git push command
@note For security, this command add a quiet option automatically. @param remote [String] The remote repository name. @param branch [String] The target branch. default: `#current_branch` @return [String] The command's standard output.
# File lib/pr_comet/git/command.rb, line 49 def push(remote, branch = current_branch) run('push', '-q', remote, branch) end
remote_url(remote)
click to toggle source
# File lib/pr_comet/git/command.rb, line 69 def remote_url(remote) config("--get remote.#{remote}.url") end
user_email()
click to toggle source
# File lib/pr_comet/git/command.rb, line 19 def user_email @user_email ||= config('user.email') end
user_name()
click to toggle source
# File lib/pr_comet/git/command.rb, line 15 def user_name @user_name ||= config('user.name') end
Private Instance Methods
config(key)
click to toggle source
# File lib/pr_comet/git/command.rb, line 85 def config(key) run('config', key) end
environments()
click to toggle source
# File lib/pr_comet/git/command.rb, line 89 def environments @environments ||= [ "GIT_AUTHOR_NAME=\"#{user_name}\"", "GIT_AUTHOR_EMAIL=\"#{user_email}\"", "GIT_COMMITTER_NAME=\"#{user_name}\"", "GIT_COMMITTER_EMAIL=\"#{user_email}\"" ].join(' ') end
run(*subcommands)
click to toggle source
# File lib/pr_comet/git/command.rb, line 75 def run(*subcommands) command = "git #{subcommands.join(' ')}" execute(command) end
run_with_environments(*subcommands)
click to toggle source
# File lib/pr_comet/git/command.rb, line 80 def run_with_environments(*subcommands) command = "#{environments} git #{subcommands.join(' ')}" execute(command) end