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 Attribute Summary

Attributes included from CommandLine

#verbose

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Command.



9
10
11
12
13
# 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

Instance Method Details

#add(*files) ⇒ Object



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

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

#checkout(branch) ⇒ Object



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

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

#checkout_with(new_branch) ⇒ Object



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

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

#commit(message) ⇒ Object



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

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

#current_branchObject



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

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

#current_branch?(branch) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#current_sha1Object



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

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

#current_sha1?(sha1) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#exist_uncommitted_modify?Boolean

Returns:

  • (Boolean)


23
24
25
# 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) ⇒ 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.



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

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

#remote_url(remote) ⇒ Object



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

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

#user_emailObject



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

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

#user_nameObject



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

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