Class: PrComet::Git::Command
- Inherits:
-
Object
- Object
- PrComet::Git::Command
- Includes:
- CommandLine
- Defined in:
- lib/pr_comet/git/command.rb
Overview
To execute git command
Instance Attribute Summary
Attributes included from CommandLine
Instance Method Summary collapse
- #add(*files) ⇒ Object
- #checkout(branch) ⇒ Object
- #checkout_with(new_branch) ⇒ Object
- #commit(message) ⇒ Object
- #current_branch ⇒ Object
- #current_branch?(branch) ⇒ Boolean
- #current_sha1 ⇒ Object
- #current_sha1?(sha1) ⇒ Boolean
- #exist_uncommitted_modify? ⇒ Boolean
-
#initialize(user_name: nil, user_email: nil, verbose: false) ⇒ Command
constructor
A new instance of Command.
-
#push(remote, branch = current_branch) ⇒ String
Execute git push command.
- #remote_url(remote) ⇒ Object
- #user_email ⇒ Object
- #user_name ⇒ Object
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() run_with_environments('commit', '-m', "\"#{}\"") end |
#current_branch ⇒ Object
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
65 66 67 |
# File 'lib/pr_comet/git/command.rb', line 65 def current_branch?(branch) current_branch == branch.to_s end |
#current_sha1 ⇒ Object
53 54 55 |
# File 'lib/pr_comet/git/command.rb', line 53 def current_sha1 run('rev-parse', 'HEAD') end |
#current_sha1?(sha1) ⇒ 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
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
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_email ⇒ Object
19 20 21 |
# File 'lib/pr_comet/git/command.rb', line 19 def user_email @user_email ||= config('user.email') end |
#user_name ⇒ Object
15 16 17 |
# File 'lib/pr_comet/git/command.rb', line 15 def user_name @user_name ||= config('user.name') end |