git_cli 0.8.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2137f01ad23cca0e4c523417ac601e30bb46f3eeeafd04d6e359b2d812452c9d
4
- data.tar.gz: 7127ecfaf5f42a8fdd311864003c92529ce86dffc30211d212872ac23d92d92b
3
+ metadata.gz: 77fb6b4308d34a185d9ba1355470893a53b15ee9710953ed0079c4847d8dc59d
4
+ data.tar.gz: 27d246f6554b2aa688738a38e21a2e985f8cbbb504d702f3ff0c0127ecd48949
5
5
  SHA512:
6
- metadata.gz: fa62792074ef5f323dea781ca32dd2ae81e76775b8943c6eb5c6cf3310ad0a4506a72ecbf23f05f53803648ed29d4afc811e92e93d2b233353eb6cc3ee0dea08
7
- data.tar.gz: 0b178d8eb671e405e16d5e6ba521d7aceb6765eaaa5c77e625e94465c1872def522a6aaf90304864c2910f5d8190236bb4eff5bbc75e0406ecbb83341b27662b
6
+ metadata.gz: bfb96c8d437b6df087b875be71c70a8cea9f6d92bf5aac59c4a7fd1eeb3c756bcaccc4850ff1f4caa8e83f4a26a9c24a536122f0b37841ce16613ee571f90f92
7
+ data.tar.gz: 1cbfb647558fd5d0bb1b0909fb29aa02fe3f668c5796b5097d6d29c3b5f7c72b802a50f0640475a7482e0af379d49240058a1ca1183315f60f3a57645bc31de3
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ tags
11
11
  git_cli-0.1.0.gem
12
12
  *.log
13
13
 
14
+ .rake_tasks~
@@ -0,0 +1,4 @@
1
+ ---
2
+ git_cli:
3
+ - :version: 0.10.0
4
+ :timestamp: 1661971875.794398
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,8 @@
1
+ ---
2
+ git_cli:
3
+ - :version: 0.7.0
4
+ :created_at: 2020-12-07 23:01:04.252722927 +08:00
5
+ - :version: 0.8.0
6
+ :created_at: 2020-12-07 23:14:58.685361227 +08:00
7
+ - :version: 0.9.0
8
+ :created_at: 2021-10-22 23:01:48.298477606 +08:00
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "minitest", "~> 5.0"
8
+
9
+ gem 'gvcs', git: 'gvcs', branch: 'master'
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
- require "devops_helper"
4
+ require "devops_assist"
5
5
 
6
6
  Rake::TestTask.new(:test) do |t|
7
7
  t.libs << "test"
data/git_cli.gemspec CHANGED
@@ -27,10 +27,12 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_dependency "tlogger", ">= 0.21"
31
- spec.add_dependency "toolrack", ">= 0.4.0"
32
- spec.add_dependency "gvcs", ">= 0.1.0"
30
+ #spec.add_dependency "tlogger"
31
+ spec.add_dependency 'teLogger'
32
+ spec.add_dependency "toolrack"
33
+ spec.add_dependency "gvcs"
33
34
  spec.add_dependency "ptools", "~> 1.4.0"
34
35
 
35
- spec.add_development_dependency 'devops_helper', ">= 0.2.0"
36
+ #spec.add_development_dependency 'devops_helper' #, ">= 0.2.0"
37
+ spec.add_development_dependency 'devops_assist' #, ">= 0.2.0"
36
38
  end
@@ -18,6 +18,8 @@
18
18
  module GitCli
19
19
  module AddCommit
20
20
 
21
+ class CommitError < StandardError; end
22
+
21
23
  def add_to_staging(paths)
22
24
  check_vcs
23
25
 
@@ -37,7 +39,13 @@ module GitCli
37
39
  log_debug "Add : #{cmdln}"
38
40
 
39
41
  os_exec(cmdln) do |st, res|
40
- [st.success?, res.strip]
42
+ res.strip!
43
+ if not st.success?
44
+ raise CommitError, res
45
+ else
46
+ res
47
+ end
48
+ #[st.success?, res.strip]
41
49
  end
42
50
  end # add_to_staging
43
51
  alias :add :add_to_staging
@@ -118,12 +126,17 @@ module GitCli
118
126
  log_debug "Commit : #{cmdln}"
119
127
 
120
128
  os_exec(cmdln) do |st, res|
121
- [st.success?, res.strip]
129
+ res.strip!
130
+ if not st.success?
131
+ raise CommitError, res
132
+ else
133
+ res
134
+ end
122
135
  end
123
136
 
124
137
  end # commit
125
138
 
126
- def commit_all(msg)
139
+ def commit_all(message)
127
140
  check_vcs
128
141
 
129
142
  # have to escape the message for command line purposes
@@ -136,14 +149,19 @@ module GitCli
136
149
  cmd << @vcs.exe_path
137
150
  cmd << "commit"
138
151
  cmd << "-am"
139
- cmd << msg
152
+ cmd << "\"#{msg}\""
140
153
 
141
154
  cmdln = cmd.join " "
142
155
 
143
156
  log_debug "Commit All : #{cmdln}"
144
157
 
145
158
  os_exec(cmdln) do |st, res|
146
- [st.success?, res.strip]
159
+ res.strip!
160
+ if not st.success?
161
+ raise CommitError, res
162
+ else
163
+ res.strip
164
+ end
147
165
  end
148
166
 
149
167
  end # commit_all
@@ -18,6 +18,8 @@
18
18
 
19
19
  module GitCli
20
20
  module Branch
21
+
22
+ class BranchError < StandardError; end
21
23
 
22
24
  def current_branch
23
25
 
@@ -50,9 +52,11 @@ module GitCli
50
52
  # end
51
53
  #end
52
54
 
53
- [true, res.strip!]
55
+ res.strip
56
+ #[true, res.strip!]
54
57
  else
55
- [false, res]
58
+ raise BranchError, res.strip
59
+ #[false, res]
56
60
  end
57
61
  end
58
62
 
@@ -70,7 +74,8 @@ module GitCli
70
74
  br.concat(rb)
71
75
  end
72
76
 
73
- [true, br]
77
+ br
78
+ #[true, br]
74
79
 
75
80
  end # all_branches
76
81
 
@@ -95,9 +100,11 @@ module GitCli
95
100
  res.each_line do |l|
96
101
  b << l.strip
97
102
  end
98
- [true, b]
103
+ b
104
+ #[true, b]
99
105
  else
100
- [false, res]
106
+ raise BranchError, res.strip
107
+ #[false, res]
101
108
  end
102
109
  end
103
110
 
@@ -125,9 +132,11 @@ module GitCli
125
132
  b << l.strip
126
133
  end
127
134
 
128
- [true, b]
135
+ #[true, b]
136
+ b
129
137
  else
130
- [false, res]
138
+ raise BranchError, res.strip
139
+ #[false, res]
131
140
  end
132
141
  end
133
142
 
@@ -151,9 +160,11 @@ module GitCli
151
160
  log_debug "Switch branch : #{cmdln}"
152
161
  res = os_exec(cmdln) do |st, res|
153
162
  if st.success?
154
- [true, res.strip]
163
+ res.strip
164
+ #[true, res.strip]
155
165
  else
156
- [false, res]
166
+ raise BranchError, res.strip
167
+ #[false, res]
157
168
  end
158
169
  end
159
170
 
@@ -180,9 +191,11 @@ module GitCli
180
191
  res = os_exec(cmdln) do |st, res|
181
192
 
182
193
  if st.success?
183
- [true, res.strip]
194
+ res.strip
195
+ #[true, res.strip]
184
196
  else
185
- [false, res]
197
+ raise BranchError, res.strip
198
+ #[false, res]
186
199
  end
187
200
  end
188
201
 
@@ -205,9 +218,11 @@ module GitCli
205
218
  res = os_exec(cmdln) do |st, res|
206
219
 
207
220
  if st.success?
208
- [true, res.strip]
221
+ res.strip
222
+ #[true, res.strip]
209
223
  else
210
- [false, res]
224
+ raise BranchError, res.strip
225
+ #[false, res]
211
226
  end
212
227
  end
213
228
 
@@ -232,9 +247,11 @@ module GitCli
232
247
  res = os_exec(cmdln) do |st, res|
233
248
 
234
249
  if st.success?
235
- [true, res.strip]
250
+ res.strip
251
+ #[true, res.strip]
236
252
  else
237
- [false, res]
253
+ raise BranchError, res.strip
254
+ #[false, res]
238
255
  end
239
256
  end
240
257
 
@@ -260,9 +277,11 @@ module GitCli
260
277
  res = os_exec(cmdln) do |st, res|
261
278
 
262
279
  if st.success?
263
- [true, res.strip]
280
+ res.strip
281
+ #[true, res.strip]
264
282
  else
265
- [false, res]
283
+ raise BranchError, res.strip
284
+ #[false, res]
266
285
  end
267
286
 
268
287
  end
data/lib/git_cli/delta.rb CHANGED
@@ -19,6 +19,102 @@
19
19
  module GitCli
20
20
  module Delta
21
21
 
22
+ class GitDeltaError < StandardError; end
23
+ class VCSItem
24
+ attr_reader :path, :full, :type
25
+ def initialize(type, path, full)
26
+ @type = type
27
+ @path = path
28
+ @full = full
29
+ end
30
+
31
+ # support sort
32
+ def <=>(val)
33
+ @path <=> val.path
34
+ end
35
+ end
36
+ class NewDir < VCSItem
37
+ def initialize(path, full)
38
+ super(:dir, path, full)
39
+ end
40
+ def to_s
41
+ "[N] #{@path}"
42
+ end
43
+ end
44
+ class NewFile < VCSItem
45
+ def initialize(path, full)
46
+ super(:file, path, full)
47
+ end
48
+ def to_s
49
+ "[N] #{@path}"
50
+ end
51
+ end
52
+ class ModifiedDir < VCSItem
53
+ def initialize(path, full)
54
+ super(:dir, path, full)
55
+ end
56
+ def to_s
57
+ "[M] #{@path}"
58
+ end
59
+ end
60
+ class ModifiedFile < VCSItem
61
+ def initialize(path, full)
62
+ super(:file, path, full)
63
+ end
64
+ def to_s
65
+ "[M] #{@path}"
66
+ end
67
+ end
68
+ class DeletedDir < VCSItem
69
+ def initialize(path, full)
70
+ super(:dir, path, full)
71
+ end
72
+ def to_s
73
+ "[D] #{@path}"
74
+ end
75
+ end
76
+ class DeletedFile < VCSItem
77
+ def initialize(path, full)
78
+ super(:file, path, full)
79
+ end
80
+ def to_s
81
+ "[D] #{@path}"
82
+ end
83
+ end
84
+ class StagedDir < VCSItem
85
+ def initialize(path, full)
86
+ super(:dir, path, full)
87
+ end
88
+ def to_s
89
+ "[S] #{@path}"
90
+ end
91
+ end
92
+ class StagedFile < VCSItem
93
+ def initialize(path, full)
94
+ super(:file, path, full)
95
+ end
96
+ def to_s
97
+ "[S] #{@path}"
98
+ end
99
+ end
100
+ class ConflictedDir < VCSItem
101
+ def initialize(path, full)
102
+ super(:dir, path, full)
103
+ end
104
+ def to_s
105
+ "[C] #{@path}"
106
+ end
107
+ end
108
+ class ConflictedFile < VCSItem
109
+ def initialize(path, full)
110
+ super(:file, path, full)
111
+ end
112
+ def to_s
113
+ "[C] #{@path}"
114
+ end
115
+ end
116
+
117
+
22
118
  def status
23
119
 
24
120
  check_vcs
@@ -34,11 +130,16 @@ module GitCli
34
130
  log_debug "Status : #{cmdln}"
35
131
  res = os_exec(cmdln) do |st, res|
36
132
 
37
- if st.success?
38
- [true, res]
133
+ if not st.success?
134
+ raise GitDeltaError, res
39
135
  else
40
- [false, res]
136
+ res
41
137
  end
138
+ #if st.success?
139
+ # [true, res]
140
+ #else
141
+ # [false, res]
142
+ #end
42
143
  end
43
144
 
44
145
  end # status
@@ -61,19 +162,21 @@ module GitCli
61
162
  files = []
62
163
  res = os_exec(cmdln) do |st, res|
63
164
 
64
- if st.success?
165
+ if not st.success?
166
+ raise GitDeltaError, res
167
+ else
65
168
  res.each_line do |l|
66
169
  l.chomp!
67
- if File.directory?(File.join(@wsPath,l))
68
- dirs << l
170
+ full = File.join(@wsPath,l)
171
+ if File.directory?(full)
172
+ dirs << ModifiedDir.new(l,full)
69
173
  else
70
- files << l
174
+ files << ModifiedFile.new(l,full)
71
175
  end
72
176
  end
73
177
 
74
- [true, dirs.sort, files.sort]
75
- else
76
- [false, [], []]
178
+ #[true, dirs.sort, files.sort]
179
+ [dirs.sort, files.sort]
77
180
  end
78
181
 
79
182
  end
@@ -96,19 +199,20 @@ module GitCli
96
199
  files = []
97
200
  res = os_exec(cmdln) do |st, res|
98
201
 
99
- if st.success?
202
+ if not st.success?
203
+ raise GitDeltaError, res
204
+ else
100
205
  res.each_line do |l|
101
206
  l.chomp!
102
- if File.directory?(File.join(@wsPath,l))
103
- dirs << l
207
+ full = File.join(@wsPath,l)
208
+ if File.directory?(full)
209
+ dirs << ConflictedDir.new(l, full)
104
210
  else
105
- files << l
211
+ files << ConflictedFile.new(l, full)
106
212
  end
107
213
  end
108
214
 
109
- [true, dirs.sort, files.sort]
110
- else
111
- [false, [], []]
215
+ [dirs.sort, files.sort]
112
216
  end
113
217
 
114
218
  end
@@ -131,19 +235,20 @@ module GitCli
131
235
  files = []
132
236
  res = os_exec(cmdln) do |st, res|
133
237
 
134
- if st.success?
238
+ if not st.success?
239
+ raise GitDeltaError, res
240
+ else
135
241
  res.each_line do |l|
136
242
  l.chomp!
137
- if File.directory?(File.join(@wsPath,l))
138
- dirs << l
243
+ full = File.join(@wsPath,l)
244
+ if File.directory?(full)
245
+ dirs << NewDir.new(l,full)
139
246
  else
140
- files << l
247
+ files << NewFile.new(l,full)
141
248
  end
142
249
  end
143
250
 
144
- [true, dirs.sort, files.sort]
145
- else
146
- [false, [], []]
251
+ [dirs.sort, files.sort]
147
252
  end
148
253
  end
149
254
 
@@ -166,19 +271,20 @@ module GitCli
166
271
  files = []
167
272
  res = os_exec(cmdln) do |st, res|
168
273
 
169
- if st.success?
274
+ if not st.success?
275
+ raise GitDeltaError, res
276
+ else
170
277
  res.each_line do |l|
171
278
  l.chomp!
172
- if File.directory?(File.join(@wsPath,l))
173
- dirs << l
279
+ full = File.join(@wsPath,l)
280
+ if File.directory?(full)
281
+ dirs << DeletedDir.new(l,full)
174
282
  else
175
- files << l
283
+ files << DeletedFile.new(l,full)
176
284
  end
177
285
  end
178
286
 
179
- [true, dirs.sort, files.sort]
180
- else
181
- [false, [], []]
287
+ [dirs.sort, files.sort]
182
288
  end
183
289
  end
184
290
 
@@ -196,24 +302,25 @@ module GitCli
196
302
  cmd << "diff --name-only --cached"
197
303
 
198
304
  cmdln = cmd.join(" ")
199
- log_debug "New Files : #{cmdln}"
305
+ log_debug "Staged Files : #{cmdln}"
200
306
  dirs = []
201
307
  files = []
202
308
  res = os_exec(cmdln) do |st, res|
203
309
 
204
- if st.success?
310
+ if not st.success?
311
+ raise GitDeltaError, res
312
+ else
205
313
  res.each_line do |l|
206
314
  l.chomp!
207
- if File.directory?(File.join(@wsPath,l))
208
- dirs << l
315
+ full = File.join(@wsPath,l)
316
+ if File.directory?(full)
317
+ dirs << StagedDir.new(l,full)
209
318
  else
210
- files << l
319
+ files << StagedFile.new(l,full)
211
320
  end
212
321
  end
213
322
 
214
- [true, dirs.sort, files.sort]
215
- else
216
- [false, [], []]
323
+ [dirs.sort, files.sort]
217
324
  end
218
325
  end
219
326
 
@@ -221,7 +328,7 @@ module GitCli
221
328
 
222
329
  def reset_file_changes(path)
223
330
 
224
- raise_if_empty(path, "Path cannot be empty for reset file changes operation", GitCliException)
331
+ raise_if_empty(path, "Path cannot be empty for reset file changes operation", GitDeltaError)
225
332
 
226
333
  check_vcs
227
334
 
@@ -260,6 +367,41 @@ module GitCli
260
367
 
261
368
  end # reset all changes
262
369
 
370
+ # If remote is ahead of local
371
+ # git rev-list HEAD..origin/main --count
372
+ #
373
+ # if local is ahead of remote
374
+ # git rev-list origin/main..HEAD --count
375
+ #
376
+ def calculate_distance(from, to)
377
+
378
+ check_vcs
379
+
380
+ cmd = []
381
+ cmd << "cd"
382
+ cmd << @wsPath
383
+ cmd << "&&"
384
+ cmd << @vcs.exe_path
385
+ cmd << "rev-list #{from}..#{to} --count"
386
+
387
+ cmdln = cmd.join(" ")
388
+ log_debug "Calculate distance between two repos : #{cmdln}"
389
+ res = os_exec(cmdln) do |st, res|
390
+ [st.success?, res]
391
+ end
392
+
393
+ end
394
+
395
+ def is_local_ahead_of_remote?(remote_name, branch = "main")
396
+
397
+ calculate_distance("#{remote_name}/#{branch}", "HEAD")
398
+
399
+ end
400
+
401
+ def is_remote_ahead_of_local?(remote_name, branch = "main")
402
+
403
+ calculate_distance("HEAD","#{remote_name}/#{branch}")
404
+ end
263
405
 
264
406
  end
265
407
  end
@@ -15,9 +15,12 @@
15
15
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
17
 
18
- require 'tlogger'
18
+ #require 'tlogger'
19
+ require 'teLogger'
19
20
  require 'singleton'
20
21
 
22
+ include TeLogger
23
+
21
24
  module GitCli
22
25
  class Global
23
26
  include Singleton
@@ -19,9 +19,12 @@
19
19
  module GitCli
20
20
  module Ignore
21
21
 
22
- def ignore(val)
22
+ def ignore(*val)
23
23
  with_ignore_file do |f|
24
- f.puts val
24
+ val.each do |v|
25
+ f.puts v
26
+ end
27
+ #f.puts val
25
28
  end
26
29
  log_debug ".gitignore file updated with line '#{val}'"
27
30
  [true,".gitignore file updated"]
data/lib/git_cli/repos.rb CHANGED
@@ -18,6 +18,7 @@
18
18
 
19
19
  module GitCli
20
20
  module Repos
21
+ class ReposError < StandardError; end
21
22
 
22
23
  def remote_config
23
24
  check_vcs
@@ -32,21 +33,26 @@ module GitCli
32
33
  cmdln = cmd.join(" ")
33
34
  log_debug "Remote config : #{cmdln}"
34
35
  res = os_exec(cmdln) do |st, res|
35
-
36
+
36
37
  if st.success?
37
38
 
38
39
  remotes = { }
39
40
  res.each_line do |l|
40
41
  ls = l.split("\t")
41
42
  lss = ls[1].split(" ")
42
- if not remotes.keys.include?(ls[0])
43
- remotes[ls[0]] = lss[0]
44
- end
43
+
44
+ remotes[ls[0]] = { } if is_empty?(remotes[ls[0]])
45
+ rem = remotes[ls[0]]
46
+ type = lss[-1]
47
+ type.gsub!("(","").gsub!(")","")
48
+ rem[type] = lss[0]
45
49
  end
46
50
 
47
- [true, remotes]
51
+ #[true, remotes]
52
+ remotes
48
53
  else
49
- [false, res]
54
+ raise ReposError, res.strip
55
+ #[false, res]
50
56
  end
51
57
  end
52
58
 
@@ -74,9 +80,11 @@ module GitCli
74
80
  res = os_exec(cmdln) do |st, res|
75
81
 
76
82
  if st.success?
77
- [true, res.strip]
83
+ #[true, res.strip]
84
+ res.strip
78
85
  else
79
- [false, res.strip]
86
+ raise ReposError, res.strip
87
+ #[false, res.strip]
80
88
  end
81
89
  end
82
90
 
@@ -103,13 +111,16 @@ module GitCli
103
111
  res = os_exec(cmdln) do |st, res|
104
112
 
105
113
  if st.success?
106
- [true, res.strip]
114
+ #[true, res.strip]
115
+ res.strip
107
116
  else
108
- [false, res.strip]
117
+ raise ReposError, res.strip
118
+ #[false, res.strip]
109
119
  end
110
120
  end
111
121
 
112
122
  end # remove_remote
123
+ alias_method :remove_del, :remove_remote
113
124
 
114
125
 
115
126
 
data/lib/git_cli/tags.rb CHANGED
@@ -19,6 +19,8 @@
19
19
  module GitCli
20
20
  module Tags
21
21
 
22
+ class TagError < StandardError; end
23
+
22
24
  def all_tags
23
25
 
24
26
  check_vcs
@@ -35,9 +37,11 @@ module GitCli
35
37
  res = os_exec(cmdln) do |st, res|
36
38
 
37
39
  if st.success?
38
- [true, res.strip!]
40
+ res.strip
41
+ #[true, res.strip!]
39
42
  else
40
- [false, res]
43
+ raise TagError, res
44
+ #[false, res]
41
45
  end
42
46
  end
43
47
 
@@ -144,9 +148,11 @@ module GitCli
144
148
  log_debug "New tag : #{cmdln}"
145
149
  res = os_exec(cmdln) do |st, res|
146
150
  if st.success?
147
- [true, res.strip!]
151
+ #[true, res.strip!]
152
+ res.strip
148
153
  else
149
- [false, res]
154
+ raise TagError, res
155
+ #[false, res]
150
156
  end
151
157
  end
152
158
 
@@ -186,9 +192,11 @@ module GitCli
186
192
  log_debug "New tag from commit ID : #{cmdln}"
187
193
  res = os_exec(cmdln) do |st, res|
188
194
  if st.success?
189
- [true, res.strip!]
195
+ res.strip
196
+ #[true, res.strip!]
190
197
  else
191
- [false, res]
198
+ raise TagError, res
199
+ #[false, res]
192
200
  end
193
201
  end
194
202
 
@@ -211,9 +219,11 @@ module GitCli
211
219
  res = os_exec(cmdln) do |st, res|
212
220
 
213
221
  if st.success?
214
- [true, res.strip!]
222
+ #[true, res.strip!]
223
+ res.strip
215
224
  else
216
- [false, res]
225
+ raise TagError, res
226
+ #[false, res]
217
227
  end
218
228
  end
219
229
 
@@ -241,9 +251,11 @@ module GitCli
241
251
  log_debug "Show tag '#{tag}' #{not_empty?(format) ? "[#{format}]" : ""} : #{cmdln}"
242
252
  res = os_exec(cmdln) do |st, res|
243
253
  if st.success?
244
- [true, res.strip!]
254
+ res.strip
255
+ #[true, res.strip!]
245
256
  else
246
- [false, res]
257
+ raise TagError, res
258
+ #[false, res]
247
259
  end
248
260
  end
249
261
 
@@ -266,9 +278,11 @@ module GitCli
266
278
  log_debug "Delete tag '#{tag}' : #{cmdln}"
267
279
  res = os_exec(cmdln) do |st, res|
268
280
  if st.success?
269
- [true, res.strip!]
281
+ res.strip
282
+ #[true, res.strip!]
270
283
  else
271
- [false, res]
284
+ raise TagError, res
285
+ #[false, res]
272
286
  end
273
287
  end
274
288
 
@@ -293,9 +307,11 @@ module GitCli
293
307
  log_debug "Delete remote tag '#{tag}' at '#{repos}': #{cmdln}"
294
308
  res = os_exec(cmdln) do |st, res|
295
309
  if st.success?
296
- [true, res.strip!]
310
+ res
311
+ #[true, res.strip!]
297
312
  else
298
- [false, res]
313
+ raise TagError, res
314
+ #[false, res]
299
315
  end
300
316
  end
301
317
 
@@ -321,9 +337,11 @@ module GitCli
321
337
  log_debug "Checkout tag '#{tag}' into branch '#{branch}': #{cmdln}"
322
338
  res = os_exec(cmdln) do |st, res|
323
339
  if st.success?
324
- [true, res.strip!]
340
+ res.strip
341
+ #[true, res.strip!]
325
342
  else
326
- [false, res]
343
+ raise TagError, res
344
+ #[false, res]
327
345
  end
328
346
  end
329
347
 
@@ -15,5 +15,5 @@
15
15
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
17
  module GitCli
18
- VERSION = "0.8.0"
18
+ VERSION = "0.11.0"
19
19
  end
data/lib/git_cli.rb CHANGED
@@ -46,6 +46,9 @@ module GitCli
46
46
  include Antrapol::ToolRack::ExceptionUtils
47
47
 
48
48
  def os_exec(path, &block)
49
+
50
+ Gvcs::Config.instance.command_output.puts("Git command : #{path}") if Gvcs::Config.instance.is_show_vcs_command?
51
+
49
52
  # redirect stderr to stdout
50
53
  path = "#{path} 2>&1"
51
54
  res = Antrapol::ToolRack::ProcessUtilsEngine.exec(path)
@@ -118,13 +121,21 @@ module GitCli
118
121
  include GitCli::Repos
119
122
  include GitCli::Stash
120
123
 
124
+ include TR::CondUtils
125
+
121
126
  attr_accessor :repos
122
- def initialize(vcs, path)
127
+ def initialize(path, vcs = nil)
123
128
 
124
- raise_if_empty(vcs , "VCS cannot be empty", GitCliException)
129
+ #raise_if_empty(vcs , "VCS cannot be empty", GitCliException)
125
130
  raise_if_empty(path, "Workspace path cannot be empty", GitCliException)
126
-
127
- @vcs = vcs
131
+
132
+ if is_empty?(vcs)
133
+ @vcs = Gvcs::Vcs.new
134
+ else
135
+ @vcs = vcs
136
+ end
137
+
138
+ #@vcs = vcs
128
139
  @givenPath = path
129
140
 
130
141
  @wsPath = File.expand_path(@givenPath)
@@ -151,6 +162,7 @@ module GitCli
151
162
 
152
163
  def is_repos_exist?(name)
153
164
  found = false
165
+ load_remote_to_repos
154
166
  @repos.each do |re|
155
167
  if re.name == name
156
168
  found = true
@@ -161,8 +173,15 @@ module GitCli
161
173
  end # is_repos_exist?
162
174
 
163
175
  def is_workspace?
164
- st, res = status
165
- st
176
+ begin
177
+ status
178
+ true
179
+ rescue GitDeltaError => ex
180
+ log_debug ex.message
181
+ false
182
+ end
183
+ #st, res = status
184
+ #st
166
185
  end
167
186
 
168
187
  def workspace_root
@@ -195,6 +214,33 @@ module GitCli
195
214
 
196
215
  end # workspace_root
197
216
 
217
+ def load_remote_to_repos
218
+ conf = remote_config
219
+ conf.each do |k,v|
220
+ repo = Gvcs::Repository.new(k, v.values.first)
221
+ repo.support_fetch if v.keys.include?("fetch")
222
+ repo.support_push if v.keys.include?("push")
223
+ add_repos(repo)
224
+ end
225
+ end
226
+
227
+ def repos
228
+ if @repos.nil? or @repos.empty?
229
+ load_remote_to_repos
230
+ end
231
+ @repos
232
+ end
233
+
234
+ def is_clean?
235
+ nd, nf = new_files
236
+ md, mf = modified_files
237
+ dd, df = deleted_files
238
+ sd, sf = staged_files
239
+
240
+ (nd.length == 0 and nf.length == 0 and md.length == 0 and mf.length == 0 and dd.length == 0 and df.length == 0 and sd.length == 0 and sf.length == 0)
241
+ end
242
+ alias_method :clean?, :is_clean?
243
+
198
244
  end # Gvcs::Workspace
199
245
 
200
246
 
@@ -208,12 +254,31 @@ module GitCli
208
254
  @url = url
209
255
  #@branches = branches
210
256
  @sslVerify = true
257
+
258
+ @fetch = false
259
+ @push = false
211
260
  end
212
261
 
213
262
  def ssl_verify(bool)
214
263
  @sslVerify = bool
215
264
  end
216
265
 
266
+ def support_fetch
267
+ @fetch = true
268
+ end
269
+ def is_fetch_supported?
270
+ @fetch
271
+ end
272
+ alias_method :can_fetch?, :is_fetch_supported?
273
+
274
+ def support_push
275
+ @push = true
276
+ end
277
+ def is_push_supported?
278
+ @push
279
+ end
280
+ alias_method :can_push?, :is_push_supported?
281
+
217
282
  end # repository
218
283
 
219
284
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Liaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-07 00:00:00.000000000 Z
11
+ date: 2023-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: tlogger
14
+ name: teLogger
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.21'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0.21'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: toolrack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.0
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.4.0
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gvcs
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.0
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.0
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: ptools
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.4.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: devops_helper
70
+ name: devops_assist
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.2.0
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 0.2.0
82
+ version: '0'
83
83
  description: Interface to GIT via command line interface instead of some sor of library
84
84
  email:
85
85
  - chrisliaw@antrapol.com
@@ -88,7 +88,10 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".release_history.yml"
92
+ - ".rspec"
91
93
  - ".travis.yml"
94
+ - ".version_history.yml"
92
95
  - CODE_OF_CONDUCT.md
93
96
  - Gemfile
94
97
  - LICENSE.txt
@@ -136,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
139
  - !ruby/object:Gem::Version
137
140
  version: '0'
138
141
  requirements: []
139
- rubygems_version: 3.1.2
142
+ rubygems_version: 3.2.22
140
143
  signing_key:
141
144
  specification_version: 4
142
145
  summary: GIT command line interface