Class: BigKeeper::GitOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/big_keeper/util/git_operator.rb

Overview

Operator for got

Instance Method Summary collapse

Instance Method Details

#checkout(path, branch_name) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/big_keeper/util/git_operator.rb', line 42

def checkout(path, branch_name)
  Dir.chdir(path) do
    IO.popen("git checkout #{branch_name}") do |io|
      io.each do |line|
        Logger.error("Checkout #{branch_name} failed.") if line.include? 'error'
      end
    end
  end
end

#clone(path, git_base) ⇒ Object



64
65
66
67
68
# File 'lib/big_keeper/util/git_operator.rb', line 64

def clone(path, git_base)
  Dir.chdir(path) do
    `git clone #{git_base}`
  end
end

#commit(path, message) ⇒ Object



70
71
72
73
74
75
# File 'lib/big_keeper/util/git_operator.rb', line 70

def commit(path, message)
  Dir.chdir(path) do
    `git add .`
    `git commit -m "#{message}"`
  end
end

#current_branch(path) ⇒ Object



6
7
8
9
10
# File 'lib/big_keeper/util/git_operator.rb', line 6

def current_branch(path)
  Dir.chdir(path) do
    `git rev-parse --abbrev-ref HEAD`.chop
  end
end

#del_local(path, branch_name) ⇒ Object



116
117
118
119
120
# File 'lib/big_keeper/util/git_operator.rb', line 116

def del_local(path, branch_name)
  Dir.chdir(path) do
    p `git branch -D #{branch_name}`
  end
end

#del_remote(path, branch_name) ⇒ Object



122
123
124
125
126
# File 'lib/big_keeper/util/git_operator.rb', line 122

def del_remote(path, branch_name)
  Dir.chdir(path) do
    p `git push origin --delete #{branch_name}`
  end
end

#dicard(path) ⇒ Object



110
111
112
113
114
# File 'lib/big_keeper/util/git_operator.rb', line 110

def dicard(path)
  Dir.chdir(path) do
    `git checkout . && git clean -xdf`
  end
end

#fetch(path) ⇒ Object



52
53
54
55
56
# File 'lib/big_keeper/util/git_operator.rb', line 52

def fetch(path)
  Dir.chdir(path) do
    `git fetch origin`
  end
end

#has_branch(path, branch_name) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/big_keeper/util/git_operator.rb', line 32

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



99
100
101
102
103
104
105
106
107
108
# File 'lib/big_keeper/util/git_operator.rb', line 99

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



89
90
91
92
93
94
95
96
97
# File 'lib/big_keeper/util/git_operator.rb', line 89

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



22
23
24
25
26
27
28
29
30
# File 'lib/big_keeper/util/git_operator.rb', line 22

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



12
13
14
15
16
17
18
19
20
# File 'lib/big_keeper/util/git_operator.rb', line 12

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



83
84
85
86
87
# File 'lib/big_keeper/util/git_operator.rb', line 83

def pull(path)
  Dir.chdir(path) do
    p `git pull`
  end
end

#push_to_remote(path, branch_name) ⇒ Object



77
78
79
80
81
# File 'lib/big_keeper/util/git_operator.rb', line 77

def push_to_remote(path, branch_name)
  Dir.chdir(path) do
    `git push -u origin #{branch_name}`
  end
end

#rebase(path, branch_name) ⇒ Object



58
59
60
61
62
# File 'lib/big_keeper/util/git_operator.rb', line 58

def rebase(path, branch_name)
  Dir.chdir(path) do
    `git rebase origin/#{branch_name}`
  end
end

#tag(path, version) ⇒ Object



132
133
134
135
136
137
# File 'lib/big_keeper/util/git_operator.rb', line 132

def tag(path, version)
  Dir.chdir(path) do
    p `git tag -a #{version} -m "release: V #{version}" master`
    p `git push --tags`
  end
end

#userObject



128
129
130
# File 'lib/big_keeper/util/git_operator.rb', line 128

def user
  `git config user.name`.chop
end