Module: GitCli::Tags

Included in:
Gvcs::Workspace
Defined in:
lib/git_cli/tags.rb

Instance Method Summary collapse

Instance Method Details

#all_tagsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/git_cli/tags.rb', line 22

def all_tags

  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?
      [true, res.strip!]
    else
      [false, res]
    end
  end
  
end

#checkout_tag(tag, branch) ⇒ Object

delete_remote_tag



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/git_cli/tags.rb', line 304

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?
      [true, res.strip!]
    else
      [false, res]
    end
  end
  
end

#create_tag(tag, msg = nil, branch = nil) ⇒ Object



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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/git_cli/tags.rb', line 112

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!]
    else
      [false, res]
    end
  end

end

#create_tag_from_commit(tag, commit, msg = nil) ⇒ Object

create_tag



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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/git_cli/tags.rb', line 155

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?
      [true, res.strip!]
    else
      [false, res]
    end
  end
  
end

#delete_remote_tag(repos, tag) ⇒ Object

delete_tag



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/git_cli/tags.rb', line 277

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 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?
      [true, res.strip!]
    else
      [false, res]
    end
  end
  
end

#delete_tag(tag) ⇒ Object

show_tag_detail



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/git_cli/tags.rb', line 252

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?
      [true, res.strip!]
    else
      [false, res]
    end
  end
  
end

#fetch_tag_to_localObject

create_tag_from_commit



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/git_cli/tags.rb', line 197

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!]
    else
      [false, res]
    end
  end
  
end

#show_tag_detail(tag, format = nil) ⇒ Object

fetch_tag_to_local



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/git_cli/tags.rb', line 222

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?
      [true, res.strip!]
    else
      [false, res]
    end
  end
  
end

#tag_info(tag, format = "%H|%ad|%an|%s") ⇒ Object



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
# File 'lib/git_cli/tags.rb', line 47

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