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 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) ⇒ 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) ⇒ 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() run_with_environments('commit', '-m', "\"#{message}\"") end |
#current_branch ⇒ Object
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
64 65 66 |
# File 'lib/pr_comet/git/command.rb', line 64 def current_branch?(branch) current_branch == branch.to_s end |
#current_sha1 ⇒ Object
52 53 54 |
# File 'lib/pr_comet/git/command.rb', line 52 def current_sha1 run('rev-parse', 'HEAD') end |
#current_sha1?(sha1) ⇒ 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
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
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_email ⇒ Object
18 19 20 |
# File 'lib/pr_comet/git/command.rb', line 18 def user_email @user_email ||= config('user.email') end |
#user_name ⇒ Object
14 15 16 |
# File 'lib/pr_comet/git/command.rb', line 14 def user_name @user_name ||= config('user.name') end |