Module: GitCli::Tags
- Included in:
- Workspace
- Defined in:
- lib/git_cli/tags.rb
Defined Under Namespace
Classes: TagError
Instance Method Summary collapse
- #all_tags ⇒ Object
-
#checkout_tag(tag, branch) ⇒ Object
delete_remote_tag.
- #create_tag(tag, msg = nil, branch = nil) ⇒ Object
-
#create_tag_from_commit(tag, commit, msg = nil) ⇒ Object
create_tag.
-
#delete_remote_tag(repos, tag) ⇒ Object
delete_tag.
-
#delete_tag(tag) ⇒ Object
show_tag_detail.
-
#fetch_tag_to_local ⇒ Object
create_tag_from_commit.
-
#show_tag_detail(tag, format = nil) ⇒ Object
fetch_tag_to_local.
- #tag_info(tag, format = "%H|%ad|%an|%s") ⇒ Object
-
#tag_points_at?(dest = "HEAD") ⇒ Boolean
checkout_tag.
Instance Method Details
#all_tags ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/git_cli/tags.rb', line 24 def check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "tag" cmdln = cmd.join(" ") log_debug "List tags : #{cmdln}" res = os_exec(cmdln) do |st, res| if st.success? res.strip.each_line.to_a.map { |v| v.strip } #[true, res.strip!] else raise TagError, res #[false, res] end end end |
#checkout_tag(tag, branch) ⇒ Object
delete_remote_tag
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/git_cli/tags.rb', line 323 def checkout_tag(tag, branch) raise_if_empty(tag, "Tag name cannot be empty", GitCliException) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "checkout" cmd << "tags/#{tag}" cmd << "-b" cmd << branch cmdln = cmd.join(" ") log_debug "Checkout tag '#{tag}' into branch '#{branch}': #{cmdln}" res = os_exec(cmdln) do |st, res| if st.success? res.strip #[true, res.strip!] else raise TagError, res #[false, res] end end end |
#create_tag(tag, msg = nil, branch = nil) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/git_cli/tags.rb', line 116 def create_tag(tag, msg = nil, branch= nil) raise_if_empty(tag, "Tag name cannot be empty", GitCliException) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "tag" if not_empty?(msg) msg2 = msg.gsub("\"","\\\"").gsub("\\","\\\\") cmd << "-a" #cmd << "\"#{tag}\"" cmd << tag cmd << "-m" cmd << "\"#{msg2}\"" else cmd << tag end if not_empty?(branch) cmd << branch end cmdln = cmd.join(" ") log_debug "New tag : #{cmdln}" res = os_exec(cmdln) do |st, res| if st.success? #[true, res.strip!] res.strip else raise TagError, res #[false, res] end end end |
#create_tag_from_commit(tag, commit, msg = nil) ⇒ Object
create_tag
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/git_cli/tags.rb', line 161 def create_tag_from_commit(tag, commit, msg = nil) raise_if_empty(tag, "Tag name cannot be empty", GitCliException) raise_if_empty(commit, "Commit ID cannot be empty", GitCliException) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "tag" if not_empty?(msg) msg2 = msg.gsub("\"","\\\"").gsub("\\","\\\\") cmd << "-a" cmd << tag cmd << "-m" cmd << msg2 else cmd << "-a" cmd << tag end cmd << commit cmdln = cmd.join(" ") log_debug "New tag from commit ID : #{cmdln}" res = os_exec(cmdln) do |st, res| if st.success? res.strip #[true, res.strip!] else raise TagError, res #[false, res] end end end |
#delete_remote_tag(repos, tag) ⇒ Object
delete_tag
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/git_cli/tags.rb', line 291 def delete_remote_tag(repos,tag) raise_if_empty(repos, "Repos name cannot be empty", GitCliException) raise_if_empty(tag, "Tag name cannot be empty", GitCliException) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "push" cmd << repos cmd << "--delete" #cmd << "push origin --delete" cmd << tag cmdln = cmd.join(" ") log_debug "Delete remote tag '#{tag}' at '#{repos}': #{cmdln}" res = os_exec(cmdln) do |st, res| if st.success? res #[true, res.strip!] else raise TagError, res #[false, res] end end end |
#delete_tag(tag) ⇒ Object
show_tag_detail
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/git_cli/tags.rb', line 264 def delete_tag(tag) raise_if_empty(tag, "Tag name cannot be empty", GitCliException) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "tag -d" cmd << tag cmdln = cmd.join(" ") log_debug "Delete tag '#{tag}' : #{cmdln}" res = os_exec(cmdln) do |st, res| if st.success? res.strip #[true, res.strip!] else raise TagError, res #[false, res] end end end |
#fetch_tag_to_local ⇒ Object
create_tag_from_commit
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/git_cli/tags.rb', line 205 def fetch_tag_to_local check_vcs #check_repos cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "fetch --all --tags" cmdln = cmd.join(" ") log_debug "Fetch tags from repository : #{cmdln}" res = os_exec(cmdln) do |st, res| if st.success? #[true, res.strip!] res.strip else raise TagError, res #[false, res] end end end |
#show_tag_detail(tag, format = nil) ⇒ Object
fetch_tag_to_local
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/git_cli/tags.rb', line 232 def show_tag_detail(tag, format = nil) raise_if_empty(tag, "Tag name cannot be empty", GitCliException) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "show" cmd << tag if not_empty?(format) cmd << "--format=\"#{format}\"" end cmdln = cmd.join(" ") log_debug "Show tag '#{tag}' #{not_empty?(format) ? "[#{format}]" : ""} : #{cmdln}" res = os_exec(cmdln) do |st, res| if st.success? res.strip #[true, res.strip!] else raise TagError, res #[false, res] end end end |
#tag_info(tag, format = "%H|%ad|%an|%s") ⇒ Object
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 |
# File 'lib/git_cli/tags.rb', line 51 def tag_info(tag, format = "%H|%ad|%an|%s") raise_if_empty(tag, "Tag name cannot be empty", GitCliException) check_vcs tagInfo = { } cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path #cmd << "log -1 --format=%ai" cmd << "show" cmd << tag # git show <tag> with format # doesn't really portray the actual date # the creation of tag in history commit list # the date is refers to the commit date, # not the date the tag was created if not_empty?(format) cmd << "--format=\"#{format}\"" end cmdln = cmd.join(" ") log_debug "Tag '#{tag}' with info : #{cmdln}" res = os_exec(cmdln) do |st, res| [st.success?, res] end end |
#tag_points_at?(dest = "HEAD") ⇒ Boolean
checkout_tag
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/git_cli/tags.rb', line 353 def tag_points_at?(dest = "HEAD") #raise_if_empty(tag, "Tag name cannot be empty", GitCliException) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "tag" cmd << "--points-at" cmd << dest cmdln = cmd.join(" ") log_debug "Check if current tag is pointing to #{dest}" res = os_exec(cmdln) do |st, res| if st.success? not_empty?(res.strip) else raise TagError, res end end end |