Class: RubocopPr::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop_pr/git.rb

Overview

small helper for git commands, everything should be stubbed in tests

Instance Attribute Summary collapse

Instance Method Summary collapse

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: '', **_options)
  @post_checkout = post_checkout
  @origin = origin
end

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



4
5
6
# File 'lib/rubocop_pr/git.rb', line 4

def origin
  @origin
end

#post_checkoutObject (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

#branchObject



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(message)
  system 'git add .'
  system "git commit -m '#{message}'"
end

#current_branchObject



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

def current_branch
  `git branch --show-current`.chomp
end

#pushObject



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

def push
  system "git push --set-upstream #{origin} #{current_branch}"
end

#statusObject



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

def status
  `git status -s`
end