Class: PrComet::Git::Command

Inherits:
Object
  • Object
show all
Includes:
CommandLine
Defined in:
lib/pr_comet/git/command.rb

Overview

To execute git command

Instance Method Summary collapse

Constructor Details

#initialize(user_name: nil, user_email: nil) ⇒ Command

Returns a new instance of Command.



9
10
11
12
# File 'lib/pr_comet/git/command.rb', line 9

def initialize(user_name: nil, user_email: nil)
  @user_name = user_name
  @user_email = user_email
end

Instance Method Details

#add(*files) ⇒ Object



34
35
36
# File 'lib/pr_comet/git/command.rb', line 34

def add(*files)
  run('add', *files)
end

#checkout(branch) ⇒ Object



26
27
28
# File 'lib/pr_comet/git/command.rb', line 26

def checkout(branch)
  run('checkout', branch)
end

#checkout_with(new_branch) ⇒ Object



30
31
32
# File 'lib/pr_comet/git/command.rb', line 30

def checkout_with(new_branch)
  run('checkout', '-b', new_branch)
end

#commit(message) ⇒ Object



38
39
40
# File 'lib/pr_comet/git/command.rb', line 38

def commit(message)
  run_with_environments('commit', '-m', "\"#{message}\"")
end

#current_branchObject



60
61
62
# File 'lib/pr_comet/git/command.rb', line 60

def current_branch
  run('rev-parse', '--abbrev-ref', 'HEAD')
end

#current_branch?(branch) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/pr_comet/git/command.rb', line 64

def current_branch?(branch)
  current_branch == branch.to_s
end

#current_sha1Object



52
53
54
# File 'lib/pr_comet/git/command.rb', line 52

def current_sha1
  run('rev-parse', 'HEAD')
end

#current_sha1?(sha1) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/pr_comet/git/command.rb', line 56

def current_sha1?(sha1)
  current_sha1 == sha1.to_s
end

#exist_uncommitted_modify?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/pr_comet/git/command.rb', line 22

def exist_uncommitted_modify?
  execute('git add -n .; git diff --name-only') != ''
end

#push(remote, branch = current_branch) ⇒ String

Note:

For security, this command add a quiet option automatically.

Execute git push command

Parameters:

  • remote (String)

    The remote repository name.

  • branch (String) (defaults to: current_branch)

    The target branch. default: ‘#current_branch`

Returns:

  • (String)

    The command’s standard output.



48
49
50
# File 'lib/pr_comet/git/command.rb', line 48

def push(remote, branch = current_branch)
  run('push', '-q', remote, branch)
end

#remote_url(remote) ⇒ Object



68
69
70
# File 'lib/pr_comet/git/command.rb', line 68

def remote_url(remote)
  config("--get remote.#{remote}.url")
end

#user_emailObject



18
19
20
# File 'lib/pr_comet/git/command.rb', line 18

def user_email
  @user_email ||= config('user.email')
end

#user_nameObject



14
15
16
# File 'lib/pr_comet/git/command.rb', line 14

def user_name
  @user_name ||= config('user.name')
end