Class: Nixenvironment::Git

Inherits:
CmdExecutor show all
Defined in:
lib/nixenvironment/git.rb

Constant Summary collapse

HEAD =
'HEAD'
DEVELOP =
'develop'
REMOTE_MASTER =
'refs/heads/master'
DEFAULT_REFSPEC =
"#{HEAD}:#{REMOTE_MASTER}"
CLONE_CMD =
'clone'
FETCH_CMD =
'fetch'
CHECKOUT_CMD =
'checkout'
COMMIT_CMD =
'commit'
PUSH_CMD =
'push'
REMOTE_ADD_CMD =
'remote add'
STATUS_CMD =
'status'
TAG_CMD =
'tag'
LS_REMOTE =
'ls-remote'
RECURSIVE_OPT =
'--recursive'
TAGS_OPT =
'--tags'
ORPHAN_OPT =
'--orphan'
MESSAGE_OPT =
'--message'
FORCE_OPT =
'--force'
PORCELAIN_OPT =
'--porcelain'
BRANCH_OPT =
'-b'

Class Method Summary collapse

Methods inherited from CmdExecutor

execute, last_cmd_exitstatus, last_cmd_success?

Class Method Details

.checkout(branch, options = {}) ⇒ Object

options

:orphan => orphan branch


56
57
58
59
60
61
62
63
# File 'lib/nixenvironment/git.rb', line 56

def self.checkout(branch, options = {})
  arr_opts = []
  arr_opts << ORPHAN_OPT if options[:orphan]
  arr_opts << BRANCH_OPT if options[:branch] || options[:b]
  arr_opts << branch

  execute(CHECKOUT_CMD, arr_opts)
end

.clone(url, working_dir = nil, options = {}) ⇒ Object

options

:recursive, :r => after the clone is created, initialize all submodules within


36
37
38
39
40
41
42
43
# File 'lib/nixenvironment/git.rb', line 36

def self.clone(url, working_dir = nil, options = {})
  arr_opts = []
  arr_opts << RECURSIVE_OPT if options[:recursive] || options[:r]
  arr_opts << url
  arr_opts << working_dir if working_dir.present?

  execute(CLONE_CMD, arr_opts)
end

.commit(options = {}) ⇒ Object

options

:message, :m => commit message


67
68
69
70
71
72
73
# File 'lib/nixenvironment/git.rb', line 67

def self.commit(options = {})
  message = options[:message] || options[:m]
  arr_opts = []
  arr_opts << "#{MESSAGE_OPT} '#{message}'" if message

  execute(COMMIT_CMD, arr_opts)
end

.fetch(options = {}) ⇒ Object

options

:tags, :t => fetch tags


47
48
49
50
51
52
# File 'lib/nixenvironment/git.rb', line 47

def self.fetch(options = {})
  arr_opts = []
  arr_opts << TAGS_OPT if options[:tags] || options[:t]

  execute(FETCH_CMD, arr_opts)
end

.ls_remote(url) ⇒ Object



109
110
111
112
113
114
# File 'lib/nixenvironment/git.rb', line 109

def self.ls_remote(url)
  arr_opts = []
  arr_opts << url

  execute(LS_REMOTE, arr_opts)
end

.push(remote = nil, refspec = nil, options = {}) ⇒ Object

options

:force, :f => force push, ignore checks


77
78
79
80
81
82
83
84
# File 'lib/nixenvironment/git.rb', line 77

def self.push(remote = nil, refspec = nil, options = {})
  arr_opts = []
  arr_opts << FORCE_OPT if options[:force] || options[:f]
  arr_opts << remote if remote.present?
  arr_opts << refspec if refspec.present?

  execute(PUSH_CMD, arr_opts)
end

.remote_add(name, url) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/nixenvironment/git.rb', line 86

def self.remote_add(name, url)
  arr_opts = []
  arr_opts << name
  arr_opts << url

  execute(REMOTE_ADD_CMD, arr_opts)
end

.status(options = {}) ⇒ Object

options

:porcelain => give the output in an easy-to-parse format


96
97
98
99
100
101
# File 'lib/nixenvironment/git.rb', line 96

def self.status(options = {})
  arr_opts = []
  arr_opts << PORCELAIN_OPT if options[:porcelain]

  execute(STATUS_CMD, arr_opts)
end

.tagObject



103
104
105
106
107
# File 'lib/nixenvironment/git.rb', line 103

def self.tag
  tags = execute(TAG_CMD).lines
  tags.map!(&:strip!)
  tags.sort_by!(&:to_i)
end