squared 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,7 @@ module Squared
29
29
  else
30
30
  sync.('pull')
31
31
  end]
32
- cmd << ws.task_name(ws.dev? && ws.series.some?(:refresh) ? 'refresh' : 'build')
32
+ cmd << ws.task_name(ws.dev?(global: true) && ws.series.some?(:refresh) ? 'refresh' : 'build')
33
33
  Common::Task.invoke(cmd, exception: ws.exception, warning: ws.warning)
34
34
  end
35
35
  end
@@ -63,7 +63,7 @@ module Squared
63
63
 
64
64
  def initialize(*, **)
65
65
  super
66
- initialize_ref(Git.ref)
66
+ initialize_ref(Git.ref) if gitdir.exist?
67
67
  end
68
68
 
69
69
  def ref
@@ -72,22 +72,17 @@ module Squared
72
72
 
73
73
  def populate(*)
74
74
  super
75
- return unless gitdir.exist? && ref?(Git.ref)
75
+ return unless ref?(Git.ref)
76
76
 
77
77
  namespace name do
78
78
  @@tasks[Git.ref].each do |action, flags|
79
79
  namespace action do
80
80
  flags.each do |flag|
81
81
  case action
82
- when :pull
83
- desc format_desc(action, flag, OPT_PULL)
82
+ when :pull, :fetch
83
+ desc format_desc(action, flag, flag == :pull ? OPT_PULL : OPT_FETCH)
84
84
  task flag, [:opts] do |_, args|
85
- pull(flag, opts: args.to_a)
86
- end
87
- when :fetch
88
- desc format_desc(action, flag, OPT_FETCH)
89
- task flag, [:opts] do |_, args|
90
- fetch(flag, opts: args.to_a)
85
+ __send__(action, flag, opts: args.to_a)
91
86
  end
92
87
  when :commit, :restore
93
88
  if flag == :all
@@ -131,8 +126,11 @@ module Squared
131
126
  desc format_desc(action, flag, 'index?=0,pathspec*')
132
127
  task flag, [:pathspec] do |_, args|
133
128
  files = args.to_a
134
- index = /^\d+$/.match?(files.first) && !git_option('index') ? files.shift.to_i : 0
135
- diff(flag, files, index: index)
129
+ diff(flag, files, index: if /^\d+$/.match?(files.first) && !git_option('index')
130
+ files.shift.to_i
131
+ else
132
+ 0
133
+ end)
136
134
  end
137
135
  when :cached
138
136
  desc format_desc(action, flag, 'pathspec*')
@@ -193,7 +191,9 @@ module Squared
193
191
  if flag == :head
194
192
  desc format_desc(action, flag, 'ref?=HEAD,pathspec+')
195
193
  task flag, [:ref, :pathspec] do |_, args|
196
- reset(flag, args.to_a[1..-1], ref: args.ref)
194
+ files = args.to_a[1..-1]
195
+ guard_params(action, flag, args: files)
196
+ reset(flag, files, ref: args.ref)
197
197
  end
198
198
  else
199
199
  desc format_desc(action, flag, 'ref?=HEAD')
@@ -221,7 +221,7 @@ module Squared
221
221
  cmd << '--commit'
222
222
  end
223
223
  append_pull opts, OPT_PULL, flag
224
- source(sync: sync, stderr: true, exception: !workspace.series.multiple?)
224
+ source(sync: sync, **gitthread)
225
225
  end
226
226
 
227
227
  def rebase
@@ -232,7 +232,7 @@ module Squared
232
232
  cmd = git_session 'fetch'
233
233
  cmd << '--all' if flag == :all || git_option('all')
234
234
  append_pull opts, OPT_FETCH, flag
235
- source(sync: invoked_sync?('fetch', flag), stderr: true, exception: !workspace.series.multiple?)
235
+ source(sync: invoked_sync?('fetch', flag), **gitthread)
236
236
  end
237
237
 
238
238
  def stash(flag = nil, files = [], commit: nil)
@@ -242,11 +242,11 @@ module Squared
242
242
  cmd << '--index' if git_option('index')
243
243
  cmd << commit
244
244
  else
245
- append_option %w[all staged include-untracked]
245
+ append_option %w[all staged include-untracked].freeze
246
246
  append_message git_option('message', 'm', zero: false)
247
247
  append_pathspec files
248
248
  end
249
- source(sync: invoked_sync?('stash', flag), exception: workspace.exception)
249
+ source(sync: invoked_sync?('stash', flag), **gitthread)
250
250
  end
251
251
 
252
252
  def status
@@ -265,11 +265,11 @@ module Squared
265
265
  end
266
266
  append_pathspec
267
267
  out, banner = source(io: true)
268
- if banner && invoked_sync?('status')
268
+ if invoked_sync?('status')
269
269
  print_item banner
270
270
  banner = nil
271
271
  end
272
- sub = if verbose?
272
+ sub = if verbose
273
273
  [
274
274
  { pat: /^(.)([A-Z])(.+)$/, styles: :red, index: 2 },
275
275
  { pat: /^([A-Z])(.+)$/, styles: :green },
@@ -284,7 +284,6 @@ module Squared
284
284
  def reset(flag, files = [], ref: nil)
285
285
  cmd = git_session 'reset'
286
286
  if flag == :head
287
- guard_params('reset', flag, args: files)
288
287
  append_commit ref
289
288
  append_pathspec files
290
289
  else
@@ -328,12 +327,11 @@ module Squared
328
327
  end
329
328
 
330
329
  def rev(flag, ref: nil, size: nil)
331
- opt = if flag == :branch
332
- '--abbrev-ref'
333
- else
334
- (n = size.to_i) > 0 ? "--short=#{[n, 5].max}" : '--verify'
335
- end
336
- git_session 'rev-parse', opt
330
+ git_session 'rev-parse', if flag == :branch
331
+ '--abbrev-ref'
332
+ else
333
+ (n = size.to_i) > 0 ? "--short=#{[n, 5].max}" : '--verify'
334
+ end
337
335
  append_commit ref
338
336
  source
339
337
  end
@@ -403,7 +401,7 @@ module Squared
403
401
  raise_error('commit', 'pathspec', hint: 'missing') if files.empty?
404
402
  "-- #{files.join(' ')}"
405
403
  end
406
- if !push?
404
+ unless push?
407
405
  source('git branch -vv --list', io: true, banner: false).first.each do |val|
408
406
  origin = %r{^\* [^\[]+(?<= )\[([\w.-/]+?)/([\w.-]+)\] }.match(val)
409
407
  next unless origin
@@ -414,7 +412,6 @@ module Squared
414
412
  end
415
413
  end
416
414
  raise_error('commit', 'work tree is not usable') unless push?
417
-
418
415
  cmd = git_session 'commit'
419
416
  cmd << '--dry-run' if git_option('dry-run')
420
417
  if amend
@@ -443,11 +440,7 @@ module Squared
443
440
  end
444
441
 
445
442
  def restore(flag, files)
446
- cmd = git_session 'restore'
447
- case flag
448
- when :worktree, :staged, :overlay
449
- cmd << "--#{flag}"
450
- end
443
+ git_session 'restore', "--#{flag}"
451
444
  append_ours
452
445
  append_pathspec(files, expect: true)
453
446
  source(stdout: true)
@@ -463,12 +456,12 @@ module Squared
463
456
  begin
464
457
  if io
465
458
  [IO.popen(cmd), banner]
466
- elsif pipe? ? sync : stdout
459
+ elsif stdin? ? sync : stdout
467
460
  print_item banner
468
461
  ret = `#{cmd}`
469
462
  if !ret.empty?
470
463
  puts ret
471
- elsif banner && stdout && !pipe?
464
+ elsif banner && stdout && !stdin?
472
465
  puts 'Success'
473
466
  end
474
467
  elsif sync || (!exception && !stderr)
@@ -482,7 +475,7 @@ module Squared
482
475
  if ret == 0
483
476
  write_lines(err, banner: banner)
484
477
  else
485
- write_lines(err, loglevel: Logger::DEBUG)
478
+ write_lines(err, loglevel: ::Logger::DEBUG)
486
479
  end
487
480
  end
488
481
  else
@@ -493,16 +486,16 @@ module Squared
493
486
  log.error e
494
487
  raise if exception
495
488
 
496
- warn e if workspace.warning
489
+ warn log_message(::Logger::WARN, e) if warning?
497
490
  end
498
491
  end
499
492
 
500
- def write_lines(iter, banner: nil, loglevel: nil, grep: nil, sub: nil, pass: false)
493
+ def write_lines(data, banner: nil, loglevel: nil, grep: nil, sub: nil, pass: false)
501
494
  grep = Regexp.new(grep == '*' ? '.+' : grep) if grep.is_a?(::String)
502
- sub = nil if pipe?
503
- found = 0
495
+ sub = nil if stdin?
496
+ ret = 0
504
497
  lines = []
505
- iter.each do |line|
498
+ data.each do |line|
506
499
  next if grep && !line.match?(grep)
507
500
 
508
501
  if loglevel
@@ -515,14 +508,14 @@ module Squared
515
508
  puts line
516
509
  end
517
510
  end
518
- found += 1
511
+ ret += 1
519
512
  end
520
- print_item banner, lines if banner && (found > 0 || !pass)
521
- found
513
+ print_item banner, lines if banner && (ret > 0 || !pass)
514
+ ret
522
515
  end
523
516
 
524
517
  def list_result(size, type, action: 'found', grep: nil)
525
- return unless verbose?
518
+ return unless verbose
526
519
 
527
520
  if size > 0
528
521
  styles = theme.fetch(:banner, []).reject { |s| s.to_s.end_with?('!') }
@@ -610,14 +603,12 @@ module Squared
610
603
  session('git', *cmd)
611
604
  end
612
605
 
613
- def gitdir
614
- base_path('.git')
606
+ def gitthread
607
+ { stderr: true, exception: !workspace.series.multiple? }
615
608
  end
616
609
 
617
- def source_path?(val)
618
- return val.to_s.start_with?(File.join(path, '').to_s) if Pathname.new(val).absolute?
619
-
620
- !val.match?(%r{^\.\.[/\\]})
610
+ def gitdir
611
+ base_path('.git')
621
612
  end
622
613
 
623
614
  def push?