Class: Build::GitHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/core_blur/git_helper.rb

Class Method Summary collapse

Class Method Details

.add_stag(path) ⇒ Object



26
27
28
29
# File 'lib/core_blur/git_helper.rb', line 26

def GitHelper.add_stag(path)
  command = "git add ."
  GitHelper.execute(path, command, true)
end

.checkout(path, checkout_branch) ⇒ Object



55
56
57
58
# File 'lib/core_blur/git_helper.rb', line 55

def GitHelper.checkout(path, checkout_branch)
  command = "git checkout #{checkout_branch}"
  GitHelper.execute(path, command, true)
end

.clone(path, url, branch = nil, only_head) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/core_blur/git_helper.rb', line 5

def GitHelper.clone(path, url, branch = nil, only_head)
  unless Dir.exist?(path)
    Dir.mkdir(path)
  end
  branch = (branch and branch != "") ? "--branch #{branch} ": " "
  head = only_head == true ? "--single-branch --depth 1 " : " "
  command = "/usr/bin/git clone #{url} #{branch}#{head}#{path}"
  GitHelper.execute(path, command, true)
end

.commit(path, commit_msg = nil) ⇒ Object



30
31
32
33
34
# File 'lib/core_blur/git_helper.rb', line 30

def GitHelper.commit(path, commit_msg = nil)
  commit_msg = commit_msg ? commit_msg : "#ignore_scan# none message"
  command = "git commit -m \"#{commit_msg}\""
  GitHelper.execute(path, command, true)
end

.fetch(path) ⇒ Object



51
52
53
54
# File 'lib/core_blur/git_helper.rb', line 51

def GitHelper.fetch(path)
  command = "git fetch"
  GitHelper.execute(path, command, true)
end

.pull(path) ⇒ Object



35
36
37
38
# File 'lib/core_blur/git_helper.rb', line 35

def GitHelper.pull(path)
  command = "git pull"
  GitHelper.execute(path, command, true)
end

.push(path, branch) ⇒ Object



39
40
41
42
# File 'lib/core_blur/git_helper.rb', line 39

def GitHelper.push(path, branch)
  command = "git push origin #{branch}"
  GitHelper.execute(path, command, true)
end

.push_f(path, branch) ⇒ Object



43
44
45
46
# File 'lib/core_blur/git_helper.rb', line 43

def GitHelper.push_f(path, branch)
  command = "git push origin -f #{branch}"
  GitHelper.execute(path, command, true)
end

.push_tags(path) ⇒ Object



75
76
77
78
# File 'lib/core_blur/git_helper.rb', line 75

def GitHelper.push_tags(path)
  command = "git push origin --tags"
  GitHelper.execute(path, command, true)
end

.reset_hard(path) ⇒ Object



47
48
49
50
# File 'lib/core_blur/git_helper.rb', line 47

def GitHelper.reset_hard(path)
  command = "git reset --hard"
  GitHelper.execute(path, command, true)
end

.status(path) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/core_blur/git_helper.rb', line 14

def GitHelper.status(path)
  current = Dir.pwd
  Dir.chdir(path)
  puts "-> 获取代码状态(#{File.basename(path)}): git status"
  res = %x(git status)
  if res.include? 'nothing to commit, working tree clean'
    puts "当前无变更"
    return false
  end
  Dir.chdir(current)
  true
end

.tag_delete_local(path, tag) ⇒ Object



59
60
61
62
# File 'lib/core_blur/git_helper.rb', line 59

def GitHelper.tag_delete_local(path, tag)
  command = "git tag -d #{tag}"
  GitHelper.execute(path, command, false)
end

.tag_delete_origin(path, tag) ⇒ Object



63
64
65
66
# File 'lib/core_blur/git_helper.rb', line 63

def GitHelper.tag_delete_origin(path, tag)
  command = "git push origin :refs/tags/#{tag}"
  GitHelper.execute(path, command, true)
end

.tag_local(path, tag) ⇒ Object



67
68
69
70
# File 'lib/core_blur/git_helper.rb', line 67

def GitHelper.tag_local(path, tag)
  command = "git tag #{tag}"
  GitHelper.execute(path, command, true)
end

.tag_origin(path, tag) ⇒ Object



71
72
73
74
# File 'lib/core_blur/git_helper.rb', line 71

def GitHelper.tag_origin(path, tag)
  command = "git push origin #{tag}"
  GitHelper.execute(path, command, true)
end