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_commits(path, branch_name) ⇒ Object
- #has_local_branch(path, branch_name) ⇒ Object
- #has_remote_branch(path, branch_name) ⇒ Object
- #pull(path) ⇒ Object
- #push(path, branch_name) ⇒ Object
- #tag(path, version) ⇒ Object
- #user ⇒ Object
Instance Method Details
#clone(path, git_base) ⇒ Object
62 63 64 65 66 |
# File 'lib/big_keeper/util/git_operator.rb', line 62 def clone(path, git_base) Dir.chdir(path) do `git clone #{git_base}` end end |
#commit(path, message) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/big_keeper/util/git_operator.rb', line 68 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
108 109 110 111 112 113 |
# File 'lib/big_keeper/util/git_operator.rb', line 108 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
40 41 42 43 44 45 46 47 48 |
# File 'lib/big_keeper/util/git_operator.rb', line 40 def git_checkout(path, branch_name) Dir.chdir(path) do IO.popen("git checkout #{branch_name}") do |io| io.each do |line| raise "Checkout #{branch_name} failed." if line.include? 'error' end end end end |
#git_fetch(path) ⇒ Object
50 51 52 53 54 |
# File 'lib/big_keeper/util/git_operator.rb', line 50 def git_fetch(path) Dir.chdir(path) do `git fetch origin` end end |
#git_rebase(path, branch_name) ⇒ Object
56 57 58 59 60 |
# File 'lib/big_keeper/util/git_operator.rb', line 56 def git_rebase(path, branch_name) Dir.chdir(path) do `git rebase origin/#{branch_name}` end end |
#has_branch(path, branch_name) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/big_keeper/util/git_operator.rb', line 30 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
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/big_keeper/util/git_operator.rb', line 97 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_commits(path, branch_name) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/big_keeper/util/git_operator.rb', line 87 def has_commits(path, branch_name) has_commits = false IO.popen("cd #{path}; git log --branches --not --remotes") do |io| io.each do |line| has_commits = true if line.include? branch_name end end has_commits end |
#has_local_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_local_branch(path, branch_name) has_branch = false IO.popen("cd #{path}; git branch") do |io| io.each do |line| has_branch = true if line.include? branch_name end end has_branch 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 -r") do |io| io.each do |line| has_branch = true if line.include? branch_name end end has_branch end |
#pull(path) ⇒ Object
81 82 83 84 85 |
# File 'lib/big_keeper/util/git_operator.rb', line 81 def pull(path) Dir.chdir(path) do p `git pull` end end |
#push(path, branch_name) ⇒ Object
75 76 77 78 79 |
# File 'lib/big_keeper/util/git_operator.rb', line 75 def push(path, branch_name) Dir.chdir(path) do p `git push -u origin #{branch_name}` end end |
#tag(path, version) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/big_keeper/util/git_operator.rb', line 119 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
115 116 117 |
# File 'lib/big_keeper/util/git_operator.rb', line 115 def user `git config user.name`.chop end |