Class: Nixenvironment::Git
- Inherits:
-
CmdExecutor
- Object
- CmdExecutor
- Nixenvironment::Git
- 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
-
.checkout(branch, options = {}) ⇒ Object
options :orphan => orphan branch.
-
.clone(url, working_dir = nil, options = {}) ⇒ Object
options :recursive, :r => after the clone is created, initialize all submodules within.
-
.commit(options = {}) ⇒ Object
options :message, :m => commit message.
-
.fetch(options = {}) ⇒ Object
options :tags, :t => fetch tags.
- .ls_remote(url) ⇒ Object
-
.push(remote = nil, refspec = nil, options = {}) ⇒ Object
options :force, :f => force push, ignore checks.
- .remote_add(name, url) ⇒ Object
-
.status(options = {}) ⇒ Object
options :porcelain => give the output in an easy-to-parse format.
- .tag ⇒ Object
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, = {}) arr_opts = [] arr_opts << ORPHAN_OPT if [:orphan] arr_opts << BRANCH_OPT if [:branch] || [: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, = {}) arr_opts = [] arr_opts << RECURSIVE_OPT if [:recursive] || [: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
67 68 69 70 71 72 73 |
# File 'lib/nixenvironment/git.rb', line 67 def self.commit( = {}) = [:message] || [:m] arr_opts = [] arr_opts << "#{MESSAGE_OPT} '#{message}'" if execute(COMMIT_CMD, arr_opts) end |
.fetch(options = {}) ⇒ Object
options
:tags, :t => fetch
47 48 49 50 51 52 |
# File 'lib/nixenvironment/git.rb', line 47 def self.fetch( = {}) arr_opts = [] arr_opts << TAGS_OPT if [:tags] || [: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, = {}) arr_opts = [] arr_opts << FORCE_OPT if [:force] || [: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( = {}) arr_opts = [] arr_opts << PORCELAIN_OPT if [:porcelain] execute(STATUS_CMD, arr_opts) end |
.tag ⇒ Object
103 104 105 106 107 |
# File 'lib/nixenvironment/git.rb', line 103 def self.tag = execute(TAG_CMD).lines .map!(&:strip!) .sort_by!(&:to_i) end |