Class: Release::Gem::Action::VcsAction
- Inherits:
-
Object
- Object
- Release::Gem::Action::VcsAction
- Includes:
- TR::CondUtils
- Defined in:
- lib/release/gem/vcs_action.rb
Instance Attribute Summary collapse
-
#ui ⇒ Object
Returns the value of attribute ui.
Instance Method Summary collapse
- #add_to_staging(*files) ⇒ Object
- #commit(msg = nil, &block) ⇒ Object
-
#exec(&block) ⇒ Object
def dev_mode_end if File.exist?(@gitBack) FileUtils.mv(@gitBack, @gitDir) end end.
- #ignore(*files) ⇒ Object
-
#initialize(root, opts = { }) ⇒ VcsAction
constructor
A new instance of VcsAction.
- #push(remote = nil, branch = nil, &block) ⇒ Object
- #remove_from_staging(*files) ⇒ Object
- #tag(*args, &block) ⇒ Object
Constructor Details
#initialize(root, opts = { }) ⇒ VcsAction
Returns a new instance of VcsAction.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/release/gem/vcs_action.rb', line 16 def initialize(root, opts = { }) raise VcsActionError, "root cannot be null" if is_empty?(root) @ws = Gvcs::Workspace.new(root) oopts = opts || {} @ui = oopts[:ui] @engine = oopts[:engine] st, path = @ws.workspace_root #@gitDir = File.join(path.strip,".git") #p @gitDir #@gitBack = File.join(path.strip,".git_bak") #p @gitBack end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mtd, *args, &block) ⇒ Object (private)
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/release/gem/vcs_action.rb', line 197 def method_missing(mtd, *args, &block) if @ws.respond_to?(mtd) @ws.send(mtd, *args, &block) else if not @engine.nil? and @engine.respond_to?(mtd) @engine.send(mtd, *args, &block) else super end end end |
Instance Attribute Details
#ui ⇒ Object
Returns the value of attribute ui.
14 15 16 |
# File 'lib/release/gem/vcs_action.rb', line 14 def ui @ui end |
Instance Method Details
#add_to_staging(*files) ⇒ Object
183 184 185 |
# File 'lib/release/gem/vcs_action.rb', line 183 def add_to_staging(*files) @ws.add_to_staging(*files) end |
#commit(msg = nil, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/release/gem/vcs_action.rb', line 45 def commit(msg = nil, &block) res = :value if block counter = 0 loop do stgDir, stgFiles = @ws.staged_files modDir, modFiles = @ws.modified_files newDir, newFiles = @ws.new_files delDir, delFiles = @ws.deleted_files modFiles.delete_if { |f| stgFiles.include?(f) } modDir.delete_if { |f| stgDir.include?(f) } # block should call vcs for add, remove, ignore and other operations res = block.call(:select_files_to_commit, { modified: { files: modFiles, dirs: modDir }, new: { files: newFiles, dirs: newDir }, deleted: { files: delFiles, dirs: delDir }, staged: { files: stgFiles, dirs: stgDir }, vcs: self, counter: counter } ) break if res == :skip or res == :done counter += 1 end if res == :done stgDir, stgFiles = @ws.staged_files block.call(:staged_elements_of_commit, { files: stgFiles, dirs: stgDir }) msg = block.call(:commit_message) if is_empty?(msg) raise VcsActionError, "Commit message is empty" if is_empty?(msg) cp "Commit with user message : #{msg}" st, res = @ws.commit(msg) if st block.call(:commit_successful, res) if block else block.call(:commit_failed, res) if block end [st, res] end else msg = "Auto commit all ('-am' flag) by gem-release gem" if is_empty?(msg) cp msg # changed files only without new files @ws.commit_all(msg) end res end |
#exec(&block) ⇒ Object
def dev_mode_end
if File.exist?(@gitBack)
FileUtils.mv(@gitBack, @gitDir)
end
end
41 42 43 |
# File 'lib/release/gem/vcs_action.rb', line 41 def exec(&block) instance_eval(&block) if block end |
#ignore(*files) ⇒ Object
187 188 189 |
# File 'lib/release/gem/vcs_action.rb', line 187 def ignore(*files) @ws.ignore(*files) end |
#push(remote = nil, branch = nil, &block) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/release/gem/vcs_action.rb', line 139 def push(remote = nil, branch= nil, &block) remoteConf = @ws.remote_config if is_empty?(remoteConf) if block remote = block.call(:no_remote_repos_defined) end else if is_empty?(remote) if block remote = block.call(:select_remote, remoteConf) else remote = remoteConf.keys.first end end end raise VcsActionError, "Push repository remote cannot be empty" if is_empty?(remote) if remote != :skip branch = @ws.current_branch if is_empty?(branch) if is_local_ahead_of_remote?("#{remote}/#{branch}", branch) cp "pushing to #{remote}/#{branch}" st, res = @ws.(remote, branch) if st block.call(:push_successful, res) if block else block.call(:push_failed, res) if block end [st, res] else block.call(:no_changes_to_push, { remote: remote, branch: branch }) if block end end end |
#remove_from_staging(*files) ⇒ Object
191 192 193 |
# File 'lib/release/gem/vcs_action.rb', line 191 def remove_from_staging(*files) @ws.remove_from_staging(*files) end |
#tag(*args, &block) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/release/gem/vcs_action.rb', line 101 def tag(*args, &block) opts = args.first || { } tag = opts[:tag] msg = opts[:message] if not @ws.tag_points_at?("HEAD") if is_empty?(tag) raise VcsActionError, "tag name cannot be empty" if not block tag = block.call(:tag_name) raise VcsActionError, "tag name cannot be empty" if is_empty?(tag) end if is_empty?(msg) if block msg = block.call(:tag_message) end end cp "tagged with name : #{tag} and message : #{msg}" st, res = @ws.create_tag(tag, msg) if st block.call(:tagging_success, res) if block else block.call(:tagging_failed, res) if block end [st, res] else block.call(:no_tagging_required) if block [true, "No tagging required"] end end |