Class: BigKeeper::GitOperator
- Inherits:
-
Object
- Object
- BigKeeper::GitOperator
- Defined in:
- lib/big_keeper/util/git_operator.rb
Overview
Operator for got
Instance Method Summary collapse
- #clone(path, git_base) ⇒ Object
- #commit(path, message) ⇒ Object
- #current_branch(path) ⇒ Object
- #del(path, branch_name) ⇒ Object
- #git_checkout(path, branch_name) ⇒ Object
- #git_fetch(path) ⇒ Object
- #git_rebase(path, branch_name) ⇒ Object
- #has_branch(path, branch_name) ⇒ Object
- #has_changes(path) ⇒ Object
- #has_remote_branch(path, branch_name) ⇒ Object
- #pull(path, branch_name) ⇒ Object
- #push(path, branch_name) ⇒ Object
- #tag(path, version) ⇒ Object
- #user ⇒ Object
Instance Method Details
#clone(path, git_base) ⇒ Object
48 49 50 51 52 |
# File 'lib/big_keeper/util/git_operator.rb', line 48 def clone(path, git_base) Dir.chdir(path) do `git clone #{git_base}` end end |
#commit(path, message) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/big_keeper/util/git_operator.rb', line 54 def commit(path, ) Dir.chdir(path) do `git add .` `git commit -m "#{message}"` end end |
#current_branch(path) ⇒ Object
4 5 6 7 8 |
# File 'lib/big_keeper/util/git_operator.rb', line 4 def current_branch(path) Dir.chdir(path) do `git rev-parse --abbrev-ref HEAD`.chop end end |
#del(path, branch_name) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/big_keeper/util/git_operator.rb', line 84 def del(path, branch_name) Dir.chdir(path) do p `git branch -D #{branch_name}` p `git push origin --delete #{branch_name}` end end |
#git_checkout(path, branch_name) ⇒ Object
30 31 32 33 34 |
# File 'lib/big_keeper/util/git_operator.rb', line 30 def git_checkout(path, branch_name) Dir.chdir(path) do `git checkout #{branch_name}` end end |
#git_fetch(path) ⇒ Object
36 37 38 39 40 |
# File 'lib/big_keeper/util/git_operator.rb', line 36 def git_fetch(path) Dir.chdir(path) do `git fetch origin` end end |
#git_rebase(path, branch_name) ⇒ Object
42 43 44 45 46 |
# File 'lib/big_keeper/util/git_operator.rb', line 42 def git_rebase(path, branch_name) Dir.chdir(path) do `git rebase origin/#{branch_name}` end end |
#has_branch(path, branch_name) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/big_keeper/util/git_operator.rb', line 20 def has_branch(path, branch_name) has_branch = false IO.popen("cd #{path}; git branch -a") do |io| io.each do |line| has_branch = true if line.include? branch_name end end has_branch end |
#has_changes(path) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/big_keeper/util/git_operator.rb', line 73 def has_changes(path) has_changes = true clear_flag = 'nothing to commit, working tree clean' IO.popen("cd #{path}; git status") do |io| io.each do |line| has_changes = false if line.include? clear_flag end end has_changes end |
#has_remote_branch(path, branch_name) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/big_keeper/util/git_operator.rb', line 10 def has_remote_branch(path, branch_name) has_branch = false IO.popen("cd #{path}; git branch -a") do |io| io.each do |line| has_branch = true if line =~ /remotes\/origin\/#{branch_name}/ end end has_branch end |
#pull(path, branch_name) ⇒ Object
67 68 69 70 71 |
# File 'lib/big_keeper/util/git_operator.rb', line 67 def pull(path, branch_name) Dir.chdir(path) do p `git pull origin #{branch_name}` end end |
#push(path, branch_name) ⇒ Object
61 62 63 64 65 |
# File 'lib/big_keeper/util/git_operator.rb', line 61 def push(path, branch_name) Dir.chdir(path) do p `git push origin #{branch_name}` end end |
#tag(path, version) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/big_keeper/util/git_operator.rb', line 95 def tag(path, version) Dir.chdir(path) do p `git tag -a #{version} -m "release: V #{version}" master` p `git push --tags` end end |
#user ⇒ Object
91 92 93 |
# File 'lib/big_keeper/util/git_operator.rb', line 91 def user `git config user.name`.chop end |