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

#clone(path, git_base) ⇒ Object



38
39
40
41
42
# File 'lib/big_keeper/util/git_operator.rb', line 38

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

#commit(path, message) ⇒ Object



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

def commit(path, message)
  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



74
75
76
77
78
79
# File 'lib/big_keeper/util/git_operator.rb', line 74

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



20
21
22
23
24
# File 'lib/big_keeper/util/git_operator.rb', line 20

def git_checkout(path, branch_name)
  Dir.chdir(path) do
    `git checkout #{branch_name}`
  end
end

#git_fetch(path) ⇒ Object



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

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

#git_rebase(path, branch_name) ⇒ Object



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

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

#has_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_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



63
64
65
66
67
68
69
70
71
72
# File 'lib/big_keeper/util/git_operator.rb', line 63

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

#pull(path, branch_name) ⇒ Object



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

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

#push(path, branch_name) ⇒ Object



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

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

#tag(path, version) ⇒ Object



85
86
87
88
89
90
# File 'lib/big_keeper/util/git_operator.rb', line 85

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



81
82
83
# File 'lib/big_keeper/util/git_operator.rb', line 81

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