squared 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.ruby.md +45 -26
- data/lib/squared/app.rb +10 -0
- data/lib/squared/common/base.rb +7 -13
- data/lib/squared/common/class.rb +20 -3
- data/lib/squared/common/format.rb +59 -15
- data/lib/squared/common/prompt.rb +38 -0
- data/lib/squared/common/system.rb +6 -36
- data/lib/squared/common/task.rb +3 -2
- data/lib/squared/common/utils.rb +25 -16
- data/lib/squared/common.rb +1 -0
- data/lib/squared/config.rb +18 -16
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +224 -110
- data/lib/squared/workspace/project/base.rb +258 -163
- data/lib/squared/workspace/project/git.rb +66 -76
- data/lib/squared/workspace/project/node.rb +220 -73
- data/lib/squared/workspace/project/python.rb +22 -16
- data/lib/squared/workspace/project/ruby.rb +76 -60
- data/lib/squared/workspace/project.rb +0 -3
- data/lib/squared/workspace/repo.rb +25 -12
- data/lib/squared/workspace/series.rb +80 -52
- data/lib/squared/workspace.rb +5 -4
- data/lib/squared.rb +1 -11
- metadata +4 -2
@@ -12,25 +12,25 @@ module Squared
|
|
12
12
|
include ::Rake::DSL
|
13
13
|
|
14
14
|
def populate(ws, **)
|
15
|
-
return if ws.series
|
15
|
+
return if ws.series[:pull].empty?
|
16
16
|
|
17
17
|
desc ws.task_name('all[git?=rebase|stash]', desc: true)
|
18
18
|
task ws.task_name('all'), [:git] do |_, args|
|
19
19
|
sync = lambda do |key|
|
20
20
|
key = ws.task_name(key)
|
21
|
-
ws.task_defined?(ret =
|
21
|
+
ws.task_defined?(ret = ws.task_join(key, 'sync')) ? ret : key
|
22
22
|
end
|
23
23
|
cmd = [case args.git
|
24
24
|
when 'rebase'
|
25
25
|
sync.('rebase')
|
26
26
|
when 'stash'
|
27
|
-
invoke(sync.('stash'),
|
27
|
+
invoke(sync.('stash'), **ws.invokeargs)
|
28
28
|
sync.('pull')
|
29
29
|
else
|
30
30
|
sync.('pull')
|
31
31
|
end]
|
32
|
-
cmd << ws.task_name(
|
33
|
-
Common::Task.invoke(cmd,
|
32
|
+
cmd << ws.task_name('build')
|
33
|
+
Common::Task.invoke(cmd, **ws.invokeargs)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -38,32 +38,34 @@ module Squared
|
|
38
38
|
%i[pull rebase fetch stash status].freeze
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
def batchargs
|
42
|
+
[ref, { 'pull-s': %i[stash pull], 'rebase-s': %i[stash rebase] }]
|
43
|
+
end
|
44
|
+
|
45
|
+
def config?(val)
|
46
|
+
return false unless (val = as_path(val))
|
47
|
+
|
48
|
+
val.join('.git').directory?
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
52
|
@@tasks[ref] = {
|
51
|
-
checkout: %i[branch detach force merge],
|
52
|
-
commit: %i[add amend amend-orig all no-all],
|
53
|
-
diff: %i[head cached branch files],
|
54
|
-
fetch: %i[all submodules unshallow],
|
55
|
-
files: %i[cached modified deleted others],
|
56
|
-
pull: %i[head rebase no-rebase commit no-commit submodules],
|
57
|
-
stash: %i[push pop apply list clear],
|
58
|
-
refs: %i[heads tags],
|
59
|
-
reset: %i[head soft mixed hard merge keep submodules],
|
60
|
-
restore: %i[worktree staged overlay],
|
61
|
-
rev: %i[commit branch]
|
53
|
+
checkout: %i[branch detach force merge].freeze,
|
54
|
+
commit: %i[add amend amend-orig all no-all].freeze,
|
55
|
+
diff: %i[head cached branch files].freeze,
|
56
|
+
fetch: %i[all submodules unshallow].freeze,
|
57
|
+
files: %i[cached modified deleted others].freeze,
|
58
|
+
pull: %i[head rebase no-rebase commit no-commit submodules].freeze,
|
59
|
+
stash: %i[push pop apply list clear].freeze,
|
60
|
+
refs: %i[heads tags].freeze,
|
61
|
+
reset: %i[head soft mixed hard merge keep submodules].freeze,
|
62
|
+
restore: %i[worktree staged overlay].freeze,
|
63
|
+
rev: %i[commit branch].freeze
|
62
64
|
}.freeze
|
63
65
|
|
64
66
|
def initialize(*, **)
|
65
67
|
super
|
66
|
-
initialize_ref(Git.ref) if
|
68
|
+
initialize_ref(Git.ref) if git_path.exist?
|
67
69
|
end
|
68
70
|
|
69
71
|
def ref
|
@@ -126,11 +128,7 @@ module Squared
|
|
126
128
|
desc format_desc(action, flag, 'index?=0,pathspec*')
|
127
129
|
task flag, [:pathspec] do |_, args|
|
128
130
|
files = args.to_a
|
129
|
-
diff(flag, files, index:
|
130
|
-
files.shift.to_i
|
131
|
-
else
|
132
|
-
0
|
133
|
-
end)
|
131
|
+
diff(flag, files, index: /^\d+$/.match?(files[0]) && !option('index') ? files.shift.to_i : 0)
|
134
132
|
end
|
135
133
|
when :cached
|
136
134
|
desc format_desc(action, flag, 'pathspec*')
|
@@ -210,18 +208,18 @@ module Squared
|
|
210
208
|
|
211
209
|
def pull(flag = nil, sync: invoked_sync?('pull', flag), opts: [])
|
212
210
|
cmd = git_session 'pull'
|
213
|
-
if flag == :'no-rebase'
|
211
|
+
if flag == :'no-rebase' || option('rebase', equals: '0')
|
214
212
|
cmd << '--no-rebase'
|
215
|
-
elsif flag == :rebase ||
|
213
|
+
elsif flag == :rebase || option('rebase')
|
216
214
|
cmd << '--rebase'
|
217
215
|
end
|
218
|
-
if flag == :'no-commit'
|
216
|
+
if flag == :'no-commit' || option('commit', equals: '0')
|
219
217
|
cmd << '--no-commit'
|
220
|
-
elsif flag == :commit ||
|
218
|
+
elsif flag == :commit || option('commit')
|
221
219
|
cmd << '--commit'
|
222
220
|
end
|
223
221
|
append_pull opts, OPT_PULL, flag
|
224
|
-
source(sync: sync, **
|
222
|
+
source(sync: sync, **threadargs)
|
225
223
|
end
|
226
224
|
|
227
225
|
def rebase
|
@@ -230,28 +228,28 @@ module Squared
|
|
230
228
|
|
231
229
|
def fetch(flag = nil, opts: [])
|
232
230
|
cmd = git_session 'fetch'
|
233
|
-
cmd << '--all' if flag == :all ||
|
231
|
+
cmd << '--all' if flag == :all || option('all')
|
234
232
|
append_pull opts, OPT_FETCH, flag
|
235
|
-
source(sync: invoked_sync?('fetch', flag), **
|
233
|
+
source(sync: invoked_sync?('fetch', flag), **threadargs)
|
236
234
|
end
|
237
235
|
|
238
236
|
def stash(flag = nil, files = [], commit: nil)
|
239
237
|
cmd = git_session 'stash', (flag || 'push').to_s
|
240
238
|
case flag
|
241
239
|
when :apply, :pop
|
242
|
-
cmd << '--index' if
|
240
|
+
cmd << '--index' if option('index')
|
243
241
|
cmd << commit
|
244
242
|
else
|
245
243
|
append_option %w[all staged include-untracked].freeze
|
246
|
-
append_message
|
244
|
+
append_message option('message', 'm', ignore: false)
|
247
245
|
append_pathspec files
|
248
246
|
end
|
249
|
-
source(sync: invoked_sync?('stash', flag), **
|
247
|
+
source(sync: invoked_sync?('stash', flag), **threadargs)
|
250
248
|
end
|
251
249
|
|
252
250
|
def status
|
253
|
-
cmd = git_session 'status',
|
254
|
-
if (val =
|
251
|
+
cmd = git_session 'status', option('long') ? '--long' : '--short'
|
252
|
+
if (val = option('ignore-submodules', ignore: false))
|
255
253
|
cmd << "--ignore-submodules=#{case val
|
256
254
|
when '0', 'none'
|
257
255
|
'none'
|
@@ -294,7 +292,7 @@ module Squared
|
|
294
292
|
append_submodules flag
|
295
293
|
else
|
296
294
|
cmd << '--mixed'
|
297
|
-
cmd << '--no-refresh' if
|
295
|
+
cmd << '--no-refresh' if option('refresh', equals: '0')
|
298
296
|
end
|
299
297
|
append_commit ref
|
300
298
|
end
|
@@ -305,10 +303,10 @@ module Squared
|
|
305
303
|
cmd = git_session 'checkout'
|
306
304
|
case flag
|
307
305
|
when :branch
|
308
|
-
cmd << '--detach' if detach == 'd' ||
|
306
|
+
cmd << '--detach' if detach == 'd' || option('detach')
|
309
307
|
if create
|
310
308
|
cmd << "-#{create}" << branch
|
311
|
-
if (val =
|
309
|
+
if (val = option('start-point'))
|
312
310
|
cmd << val
|
313
311
|
end
|
314
312
|
else
|
@@ -362,22 +360,22 @@ module Squared
|
|
362
360
|
sha = nil
|
363
361
|
end
|
364
362
|
end
|
365
|
-
if (val =
|
363
|
+
if (val = option('unified')).to_i > 0
|
366
364
|
cmd << "--unified=#{val}"
|
367
365
|
end
|
368
366
|
append_nocolor
|
369
367
|
case flag
|
370
368
|
when :cached
|
371
369
|
cmd << '--cached'
|
372
|
-
cmd << '--merge-base' if
|
370
|
+
cmd << '--merge-base' if option('merge-base')
|
373
371
|
when :branch
|
374
372
|
cmd << branch
|
375
373
|
when :files
|
376
374
|
cmd << '--no-index'
|
377
375
|
else
|
378
|
-
if (val =
|
376
|
+
if (val = option('index')) || index > 0
|
379
377
|
cmd << "HEAD~#{val || index}"
|
380
|
-
elsif sha &&
|
378
|
+
elsif sha && option('merge-base')
|
381
379
|
cmd << '--merge-base'
|
382
380
|
end
|
383
381
|
end
|
@@ -387,7 +385,7 @@ module Squared
|
|
387
385
|
end
|
388
386
|
|
389
387
|
def commit(flag, files = [], message: nil, pass: false)
|
390
|
-
message ||=
|
388
|
+
message ||= option('message', 'm', prefix: 'git', ignore: false)
|
391
389
|
amend = flag.to_s.start_with?('amend')
|
392
390
|
if !message && !amend
|
393
391
|
return if pass
|
@@ -413,7 +411,7 @@ module Squared
|
|
413
411
|
end
|
414
412
|
raise_error('commit', 'work tree is not usable') unless push?
|
415
413
|
cmd = git_session 'commit'
|
416
|
-
cmd << '--dry-run' if
|
414
|
+
cmd << '--dry-run' if option('dry-run')
|
417
415
|
if amend
|
418
416
|
cmd << '--amend'
|
419
417
|
else
|
@@ -421,7 +419,7 @@ module Squared
|
|
421
419
|
end
|
422
420
|
if message
|
423
421
|
append_message message
|
424
|
-
elsif flag == :'amend-orig' ||
|
422
|
+
elsif flag == :'amend-orig' || option('no-edit')
|
425
423
|
cmd << '--no-edit'
|
426
424
|
end
|
427
425
|
a = ['git add --verbose']
|
@@ -448,11 +446,12 @@ module Squared
|
|
448
446
|
|
449
447
|
private
|
450
448
|
|
451
|
-
def source(cmd = @session, exception: true,
|
452
|
-
|
449
|
+
def source(cmd = @session, exception: true, io: false, sync: true, stdout: false, stderr: false,
|
450
|
+
banner: ARG[:BANNER])
|
451
|
+
cmd = session_done(cmd)
|
453
452
|
log.info cmd
|
454
453
|
banner = format_banner(cmd.gsub(File.join(path, ''), ''), banner: banner, multiple: true)
|
455
|
-
cmd = cmd.sub(/^git\b/, "git --work-tree #{shell_quote(path)} --git-dir #{shell_quote(
|
454
|
+
cmd = cmd.sub(/^git\b/, "git --work-tree #{shell_quote(path)} --git-dir #{shell_quote(git_path)}")
|
456
455
|
begin
|
457
456
|
if io
|
458
457
|
[IO.popen(cmd), banner]
|
@@ -549,7 +548,7 @@ module Squared
|
|
549
548
|
end
|
550
549
|
|
551
550
|
def append_pathspec(files = [], expect: false, pass: false)
|
552
|
-
if files.empty? && (val =
|
551
|
+
if files.empty? && (val = option('pathspec'))
|
553
552
|
files = split_escape(val)
|
554
553
|
end
|
555
554
|
files = source_path(files, pass: pass)
|
@@ -565,49 +564,34 @@ module Squared
|
|
565
564
|
end
|
566
565
|
|
567
566
|
def append_head
|
568
|
-
@session << (
|
567
|
+
@session << (option('head') || option('tree-ish'))
|
569
568
|
end
|
570
569
|
|
571
570
|
def append_ours
|
572
|
-
if
|
571
|
+
if option('ours')
|
573
572
|
@session << '--ours'
|
574
|
-
elsif
|
573
|
+
elsif option('theirs')
|
575
574
|
@session << '--theirs'
|
576
575
|
end
|
577
576
|
end
|
578
577
|
|
579
578
|
def append_submodules(flag = nil)
|
580
|
-
if
|
579
|
+
if option('recurse-submodules', equals: '0')
|
581
580
|
@session << '--no-recurse-submodules'
|
582
|
-
elsif flag == :submodules ||
|
581
|
+
elsif flag == :submodules || option('recurse-submodules')
|
583
582
|
@session << '--recurse-submodules'
|
584
583
|
end
|
585
584
|
end
|
586
585
|
|
587
586
|
def append_option(list)
|
588
|
-
list.each { |val| @session << "--#{val}" if
|
589
|
-
end
|
590
|
-
|
591
|
-
def git_option(*args, equals: nil, zero: true)
|
592
|
-
for val in args
|
593
|
-
break if (ret = ENV["GIT_#{val.gsub(/\W/, '_').upcase}"])
|
594
|
-
end
|
595
|
-
if !equals.nil?
|
596
|
-
ret == equals.to_s
|
597
|
-
elsif !ret.nil? && !ret.empty? && !(ret == '0' && zero)
|
598
|
-
ret
|
599
|
-
end
|
587
|
+
list.each { |val| @session << "--#{val}" if option(val) }
|
600
588
|
end
|
601
589
|
|
602
590
|
def git_session(*cmd)
|
603
591
|
session('git', *cmd)
|
604
592
|
end
|
605
593
|
|
606
|
-
def
|
607
|
-
{ stderr: true, exception: !workspace.series.multiple? }
|
608
|
-
end
|
609
|
-
|
610
|
-
def gitdir
|
594
|
+
def git_path
|
611
595
|
base_path('.git')
|
612
596
|
end
|
613
597
|
|
@@ -618,7 +602,13 @@ module Squared
|
|
618
602
|
def dry_run?
|
619
603
|
@session.include?('--dry-run')
|
620
604
|
end
|
605
|
+
|
606
|
+
def threadargs
|
607
|
+
{ stderr: true, exception: !workspace.series.multiple? }
|
608
|
+
end
|
621
609
|
end
|
610
|
+
|
611
|
+
Application.implement Git
|
622
612
|
end
|
623
613
|
end
|
624
614
|
end
|