Class: RubocopPr::Git
- Inherits:
-
Object
- Object
- RubocopPr::Git
- Defined in:
- lib/rubocop_pr/git.rb
Overview
small helper for git commands, everything should be stubbed in tests
Instance Attribute Summary collapse
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#post_checkout ⇒ Object
readonly
Returns the value of attribute post_checkout.
Instance Method Summary collapse
- #branch ⇒ Object
- #checkout(file_or_branch) ⇒ Object
- #commit_all(message) ⇒ Object
- #current_branch ⇒ Object
-
#initialize(post_checkout: '', origin: '', **_options) ⇒ Git
constructor
A new instance of Git.
- #push ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(post_checkout: '', origin: '', **_options) ⇒ Git
Returns a new instance of Git.
6 7 8 9 |
# File 'lib/rubocop_pr/git.rb', line 6 def initialize(post_checkout: '', origin: '', **) @post_checkout = post_checkout @origin = origin end |
Instance Attribute Details
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
4 5 6 |
# File 'lib/rubocop_pr/git.rb', line 4 def origin @origin end |
#post_checkout ⇒ Object (readonly)
Returns the value of attribute post_checkout.
4 5 6 |
# File 'lib/rubocop_pr/git.rb', line 4 def post_checkout @post_checkout end |
Instance Method Details
#branch ⇒ Object
34 35 36 |
# File 'lib/rubocop_pr/git.rb', line 34 def branch `git branch` end |
#checkout(file_or_branch) ⇒ Object
11 12 13 14 15 |
# File 'lib/rubocop_pr/git.rb', line 11 def checkout(file_or_branch) return process_post_checkout if exec_checkout(file_or_branch) exec_checkout file_or_branch, flags: ['-b'] process_post_checkout end |
#commit_all(message) ⇒ Object
17 18 19 20 |
# File 'lib/rubocop_pr/git.rb', line 17 def commit_all() system 'git add .' system "git commit -m '#{message}'" end |
#current_branch ⇒ Object
26 27 28 |
# File 'lib/rubocop_pr/git.rb', line 26 def current_branch `git branch --show-current`.chomp end |
#push ⇒ Object
22 23 24 |
# File 'lib/rubocop_pr/git.rb', line 22 def push system "git push --set-upstream #{origin} #{current_branch}" end |
#status ⇒ Object
30 31 32 |
# File 'lib/rubocop_pr/git.rb', line 30 def status `git status -s` end |