squared 0.0.10 → 0.0.12
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 +98 -26
- data/lib/squared/app.rb +10 -0
- data/lib/squared/common/base.rb +12 -16
- data/lib/squared/common/class.rb +26 -1
- data/lib/squared/common/format.rb +79 -24
- data/lib/squared/common/prompt.rb +36 -0
- data/lib/squared/common/shell.rb +4 -3
- data/lib/squared/common/system.rb +15 -47
- data/lib/squared/common/utils.rb +51 -16
- data/lib/squared/common.rb +1 -4
- data/lib/squared/config.rb +48 -43
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +245 -125
- data/lib/squared/workspace/project/base.rb +448 -188
- data/lib/squared/workspace/project/git.rb +97 -113
- data/lib/squared/workspace/project/node.rb +217 -109
- data/lib/squared/workspace/project/python.rb +37 -34
- data/lib/squared/workspace/project/ruby.rb +137 -100
- data/lib/squared/workspace/project.rb +0 -3
- data/lib/squared/workspace/repo.rb +32 -18
- data/lib/squared/workspace/series.rb +82 -53
- data/lib/squared/workspace.rb +6 -5
- data/lib/squared.rb +1 -11
- metadata +4 -3
- data/lib/squared/common/task.rb +0 -24
@@ -12,58 +12,63 @@ 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
|
+
name = ws.task_name('all')
|
17
18
|
desc ws.task_name('all[git?=rebase|stash]', desc: true)
|
18
|
-
task
|
19
|
+
task name, [:git] do |_, args|
|
19
20
|
sync = lambda do |key|
|
20
21
|
key = ws.task_name(key)
|
21
|
-
ws.task_defined?(ret =
|
22
|
+
ws.task_defined?(ret = ws.task_join(key, 'sync')) ? ret : key
|
22
23
|
end
|
23
24
|
cmd = [case args.git
|
24
25
|
when 'rebase'
|
25
26
|
sync.('rebase')
|
26
27
|
when 'stash'
|
27
|
-
invoke(sync.('stash'),
|
28
|
+
invoke(sync.('stash'), **ws.invokeargs)
|
28
29
|
sync.('pull')
|
29
30
|
else
|
30
31
|
sync.('pull')
|
31
32
|
end]
|
32
|
-
cmd << ws.task_name(
|
33
|
-
Common::
|
33
|
+
cmd << ws.task_name('build')
|
34
|
+
Common::Utils.task_invoke(*cmd, **ws.invokeargs)
|
34
35
|
end
|
36
|
+
ws.series.sync << name
|
37
|
+
ws.series.multiple << name
|
35
38
|
end
|
36
39
|
|
37
40
|
def tasks
|
38
41
|
%i[pull rebase fetch stash status].freeze
|
39
42
|
end
|
40
43
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
def batchargs
|
45
|
+
[ref, { 'pull-s': %i[stash pull], 'rebase-s': %i[stash rebase] }]
|
46
|
+
end
|
47
|
+
|
48
|
+
def config?(val)
|
49
|
+
return false unless (val = as_path(val))
|
50
|
+
|
51
|
+
val.join('.git').directory?
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
50
55
|
@@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]
|
56
|
+
checkout: %i[branch detach force merge].freeze,
|
57
|
+
commit: %i[add amend amend-orig all no-all].freeze,
|
58
|
+
diff: %i[head cached branch files].freeze,
|
59
|
+
fetch: %i[all submodules unshallow].freeze,
|
60
|
+
files: %i[cached modified deleted others].freeze,
|
61
|
+
pull: %i[head rebase no-rebase commit no-commit submodules].freeze,
|
62
|
+
stash: %i[push pop apply list clear].freeze,
|
63
|
+
refs: %i[heads tags].freeze,
|
64
|
+
reset: %i[head soft mixed hard merge keep submodules].freeze,
|
65
|
+
restore: %i[worktree staged overlay].freeze,
|
66
|
+
rev: %i[commit branch].freeze
|
62
67
|
}.freeze
|
63
68
|
|
64
69
|
def initialize(*, **)
|
65
70
|
super
|
66
|
-
initialize_ref(Git.ref) if
|
71
|
+
initialize_ref(Git.ref) if gitpath.exist?
|
67
72
|
end
|
68
73
|
|
69
74
|
def ref
|
@@ -93,8 +98,7 @@ module Squared
|
|
93
98
|
else
|
94
99
|
desc format_desc(action, flag, 'pathspec+')
|
95
100
|
task flag, [:pathspec] do |_, args|
|
96
|
-
files = args.to_a
|
97
|
-
guard_params(action, flag, args: files)
|
101
|
+
files = guard_params(action, flag, args: args.to_a)
|
98
102
|
__send__(action, flag, files)
|
99
103
|
end
|
100
104
|
end
|
@@ -126,11 +130,7 @@ module Squared
|
|
126
130
|
desc format_desc(action, flag, 'index?=0,pathspec*')
|
127
131
|
task flag, [:pathspec] do |_, args|
|
128
132
|
files = args.to_a
|
129
|
-
diff(flag, files, index:
|
130
|
-
files.shift.to_i
|
131
|
-
else
|
132
|
-
0
|
133
|
-
end)
|
133
|
+
diff(flag, files, index: /^\d+$/.match?(files[0]) && !option('index') ? files.shift.to_i : 0)
|
134
134
|
end
|
135
135
|
when :cached
|
136
136
|
desc format_desc(action, flag, 'pathspec*')
|
@@ -140,15 +140,15 @@ module Squared
|
|
140
140
|
when :branch
|
141
141
|
desc format_desc(action, flag, 'name,pathspec*')
|
142
142
|
task flag, [:name, :pathspec] do |_, args|
|
143
|
-
guard_params(action, flag, args: args, key: :name)
|
144
|
-
diff(flag, args.to_a[1..-1], branch:
|
143
|
+
branch = guard_params(action, flag, args: args, key: :name)
|
144
|
+
diff(flag, args.to_a[1..-1] || [], branch: branch)
|
145
145
|
end
|
146
146
|
when :files
|
147
147
|
desc format_desc(action, flag, 'path1,path2')
|
148
148
|
task flag, [:path1, :path2] do |_, args|
|
149
|
-
guard_params(action, flag, args: args, key: :path1)
|
150
|
-
guard_params(action, flag, args: args, key: :path2)
|
151
|
-
diff(flag, [
|
149
|
+
path1 = guard_params(action, flag, args: args, key: :path1)
|
150
|
+
path2 = guard_params(action, flag, args: args, key: :path2)
|
151
|
+
diff(flag, [path1, path2])
|
152
152
|
end
|
153
153
|
end
|
154
154
|
when :checkout
|
@@ -156,7 +156,7 @@ module Squared
|
|
156
156
|
when :branch
|
157
157
|
desc format_desc(action, flag, 'name,create?=b|B,commit?,detach?=d')
|
158
158
|
task flag, [:name, :create, :commit, :detach] do |_, args|
|
159
|
-
guard_params(action, flag, args: args, key: :name)
|
159
|
+
branch = guard_params(action, flag, args: args, key: :name)
|
160
160
|
create = args.create
|
161
161
|
if args.commit == 'd'
|
162
162
|
detach = 'd'
|
@@ -174,7 +174,7 @@ module Squared
|
|
174
174
|
commit = args.commit
|
175
175
|
end
|
176
176
|
guard_params(action, flag, args: { create: create }, key: :create, pat: /^b$/i) if create
|
177
|
-
checkout(flag, branch:
|
177
|
+
checkout(flag, branch: branch, create: create, commit: commit, detach: detach)
|
178
178
|
end
|
179
179
|
when :detach
|
180
180
|
desc format_desc(action, flag, 'branch/commit?')
|
@@ -189,10 +189,9 @@ module Squared
|
|
189
189
|
end
|
190
190
|
when :reset
|
191
191
|
if flag == :head
|
192
|
-
desc format_desc(action, flag, 'ref
|
192
|
+
desc format_desc(action, flag, 'ref,pathspec+')
|
193
193
|
task flag, [:ref, :pathspec] do |_, args|
|
194
|
-
files = args.to_a[1..-1]
|
195
|
-
guard_params(action, flag, args: files)
|
194
|
+
files = guard_params(action, flag, args: args.to_a[1..-1] || [])
|
196
195
|
reset(flag, files, ref: args.ref)
|
197
196
|
end
|
198
197
|
else
|
@@ -210,18 +209,18 @@ module Squared
|
|
210
209
|
|
211
210
|
def pull(flag = nil, sync: invoked_sync?('pull', flag), opts: [])
|
212
211
|
cmd = git_session 'pull'
|
213
|
-
if flag == :'no-rebase'
|
212
|
+
if flag == :'no-rebase' || option('rebase', equals: '0')
|
214
213
|
cmd << '--no-rebase'
|
215
|
-
elsif flag == :rebase ||
|
214
|
+
elsif flag == :rebase || option('rebase')
|
216
215
|
cmd << '--rebase'
|
217
216
|
end
|
218
|
-
if flag == :'no-commit'
|
217
|
+
if flag == :'no-commit' || option('commit', equals: '0')
|
219
218
|
cmd << '--no-commit'
|
220
|
-
elsif flag == :commit ||
|
219
|
+
elsif flag == :commit || option('commit')
|
221
220
|
cmd << '--commit'
|
222
221
|
end
|
223
222
|
append_pull opts, OPT_PULL, flag
|
224
|
-
source(sync: sync, **
|
223
|
+
source(sync: sync, **threadargs)
|
225
224
|
end
|
226
225
|
|
227
226
|
def rebase
|
@@ -230,28 +229,28 @@ module Squared
|
|
230
229
|
|
231
230
|
def fetch(flag = nil, opts: [])
|
232
231
|
cmd = git_session 'fetch'
|
233
|
-
cmd << '--all' if flag == :all ||
|
232
|
+
cmd << '--all' if flag == :all || option('all')
|
234
233
|
append_pull opts, OPT_FETCH, flag
|
235
|
-
source(sync: invoked_sync?('fetch', flag), **
|
234
|
+
source(sync: invoked_sync?('fetch', flag), **threadargs)
|
236
235
|
end
|
237
236
|
|
238
237
|
def stash(flag = nil, files = [], commit: nil)
|
239
|
-
cmd = git_session 'stash',
|
238
|
+
cmd = git_session 'stash', flag || 'push'
|
240
239
|
case flag
|
241
240
|
when :apply, :pop
|
242
|
-
cmd << '--index' if
|
241
|
+
cmd << '--index' if option('index')
|
243
242
|
cmd << commit
|
244
243
|
else
|
245
244
|
append_option %w[all staged include-untracked].freeze
|
246
|
-
append_message
|
245
|
+
append_message option('message', 'm', ignore: false)
|
247
246
|
append_pathspec files
|
248
247
|
end
|
249
|
-
source(sync: invoked_sync?('stash', flag), **
|
248
|
+
source(sync: invoked_sync?('stash', flag), **threadargs)
|
250
249
|
end
|
251
250
|
|
252
251
|
def status
|
253
|
-
cmd = git_session 'status',
|
254
|
-
if (val =
|
252
|
+
cmd = git_session 'status', option('long') ? '--long' : '--short'
|
253
|
+
if (val = option('ignore-submodules', ignore: false))
|
255
254
|
cmd << "--ignore-submodules=#{case val
|
256
255
|
when '0', 'none'
|
257
256
|
'none'
|
@@ -269,15 +268,15 @@ module Squared
|
|
269
268
|
print_item banner
|
270
269
|
banner = nil
|
271
270
|
end
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
271
|
+
ret = write_lines(out, banner: banner, sub: if verbose
|
272
|
+
[
|
273
|
+
{ pat: /^(.)([A-Z])(.+)$/, styles: :red, index: 2 },
|
274
|
+
{ pat: /^([A-Z])(.+)$/, styles: :green },
|
275
|
+
{ pat: /^(\?\?)(.+)$/, styles: :red },
|
276
|
+
{ pat: /^(## )(.+)(\.{3})(.+)$/,
|
277
|
+
styles: [nil, :green, nil, :red], index: -1 }
|
278
|
+
]
|
279
|
+
end)
|
281
280
|
list_result(ret, 'files', action: 'modified')
|
282
281
|
end
|
283
282
|
|
@@ -294,7 +293,7 @@ module Squared
|
|
294
293
|
append_submodules flag
|
295
294
|
else
|
296
295
|
cmd << '--mixed'
|
297
|
-
cmd << '--no-refresh' if
|
296
|
+
cmd << '--no-refresh' if option('refresh', equals: '0')
|
298
297
|
end
|
299
298
|
append_commit ref
|
300
299
|
end
|
@@ -305,10 +304,10 @@ module Squared
|
|
305
304
|
cmd = git_session 'checkout'
|
306
305
|
case flag
|
307
306
|
when :branch
|
308
|
-
cmd << '--detach' if detach == 'd' ||
|
307
|
+
cmd << '--detach' if detach == 'd' || option('detach')
|
309
308
|
if create
|
310
309
|
cmd << "-#{create}" << branch
|
311
|
-
if (val =
|
310
|
+
if (val = option('start-point'))
|
312
311
|
cmd << val
|
313
312
|
end
|
314
313
|
else
|
@@ -362,32 +361,32 @@ module Squared
|
|
362
361
|
sha = nil
|
363
362
|
end
|
364
363
|
end
|
365
|
-
if (val =
|
364
|
+
if (val = option('unified')).to_i > 0
|
366
365
|
cmd << "--unified=#{val}"
|
367
366
|
end
|
368
367
|
append_nocolor
|
369
368
|
case flag
|
370
369
|
when :cached
|
371
370
|
cmd << '--cached'
|
372
|
-
cmd << '--merge-base' if
|
371
|
+
cmd << '--merge-base' if option('merge-base')
|
373
372
|
when :branch
|
374
373
|
cmd << branch
|
375
374
|
when :files
|
376
375
|
cmd << '--no-index'
|
377
376
|
else
|
378
|
-
if (val =
|
377
|
+
if (val = option('index')) || index > 0
|
379
378
|
cmd << "HEAD~#{val || index}"
|
380
|
-
elsif sha &&
|
379
|
+
elsif sha && option('merge-base')
|
381
380
|
cmd << '--merge-base'
|
382
381
|
end
|
383
382
|
end
|
384
383
|
cmd << sha
|
385
|
-
append_pathspec(files,
|
384
|
+
append_pathspec(files, parent: flag == :files)
|
386
385
|
source(exception: cmd.include?('--exit-code'))
|
387
386
|
end
|
388
387
|
|
389
388
|
def commit(flag, files = [], message: nil, pass: false)
|
390
|
-
message ||=
|
389
|
+
message ||= option('message', 'm', prefix: 'git', ignore: false)
|
391
390
|
amend = flag.to_s.start_with?('amend')
|
392
391
|
if !message && !amend
|
393
392
|
return if pass
|
@@ -397,8 +396,7 @@ module Squared
|
|
397
396
|
pathspec = if flag == :all || (amend && files.size == 1 && files.first == '*')
|
398
397
|
'--all'
|
399
398
|
else
|
400
|
-
files =
|
401
|
-
raise_error('commit', 'pathspec', hint: 'missing') if files.empty?
|
399
|
+
raise_error('commit', 'pathspec', hint: 'missing') if (files = projectmap(files)).empty?
|
402
400
|
"-- #{files.join(' ')}"
|
403
401
|
end
|
404
402
|
unless push?
|
@@ -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,11 @@ module Squared
|
|
448
446
|
|
449
447
|
private
|
450
448
|
|
451
|
-
def source(cmd = @session, exception: true,
|
452
|
-
cmd =
|
449
|
+
def source(cmd = @session, exception: true, io: false, sync: true, stdout: false, stderr: false, banner: true)
|
450
|
+
cmd = session_done(cmd)
|
453
451
|
log.info cmd
|
454
|
-
banner = format_banner(cmd.gsub(File.join(path, ''), ''), banner: banner
|
455
|
-
cmd = cmd.sub(/^git\b/, "git --work-tree #{shell_quote(path)} --git-dir #{shell_quote(
|
452
|
+
banner = format_banner(cmd.gsub(File.join(path, ''), ''), banner: banner)
|
453
|
+
cmd = cmd.sub(/^git\b/, "git --work-tree #{shell_quote(path)} --git-dir #{shell_quote(gitpath)}")
|
456
454
|
begin
|
457
455
|
if io
|
458
456
|
[IO.popen(cmd), banner]
|
@@ -527,11 +525,6 @@ module Squared
|
|
527
525
|
end
|
528
526
|
end
|
529
527
|
|
530
|
-
def source_path(files, pass: false)
|
531
|
-
files = files.select { |val| source_path?(val) } unless pass
|
532
|
-
files.map { |val| val == '.' ? '.' : shell_quote(base_path(val.strip)) }
|
533
|
-
end
|
534
|
-
|
535
528
|
def append_pull(opts, list, flag = nil)
|
536
529
|
append_submodules flag
|
537
530
|
opts.each do |opt|
|
@@ -545,18 +538,18 @@ module Squared
|
|
545
538
|
|
546
539
|
def append_commit(val)
|
547
540
|
val = val.to_s.strip
|
548
|
-
val.empty? ? 'HEAD' : val
|
541
|
+
@session << (val.empty? ? 'HEAD' : val)
|
549
542
|
end
|
550
543
|
|
551
|
-
def append_pathspec(files = [], expect: false,
|
552
|
-
if files.empty? && (val =
|
544
|
+
def append_pathspec(files = [], expect: false, parent: false)
|
545
|
+
if files.empty? && (val = option('pathspec'))
|
553
546
|
files = split_escape(val)
|
554
547
|
end
|
555
|
-
files =
|
548
|
+
files = projectmap(files, parent: parent)
|
556
549
|
if !files.empty?
|
557
550
|
@session << "-- #{files.join(' ')}"
|
558
551
|
elsif expect
|
559
|
-
raise_error(
|
552
|
+
raise_error(parent ? 'pathspec not present' : 'pathspec not within worktree', hint: 'invalid')
|
560
553
|
end
|
561
554
|
end
|
562
555
|
|
@@ -565,50 +558,35 @@ module Squared
|
|
565
558
|
end
|
566
559
|
|
567
560
|
def append_head
|
568
|
-
@session << (
|
561
|
+
@session << (option('head') || option('tree-ish'))
|
569
562
|
end
|
570
563
|
|
571
564
|
def append_ours
|
572
|
-
if
|
565
|
+
if option('ours')
|
573
566
|
@session << '--ours'
|
574
|
-
elsif
|
567
|
+
elsif option('theirs')
|
575
568
|
@session << '--theirs'
|
576
569
|
end
|
577
570
|
end
|
578
571
|
|
579
572
|
def append_submodules(flag = nil)
|
580
|
-
if
|
573
|
+
if option('recurse-submodules', equals: '0')
|
581
574
|
@session << '--no-recurse-submodules'
|
582
|
-
elsif flag == :submodules ||
|
575
|
+
elsif flag == :submodules || option('recurse-submodules')
|
583
576
|
@session << '--recurse-submodules'
|
584
577
|
end
|
585
578
|
end
|
586
579
|
|
587
580
|
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
|
581
|
+
list.each { |val| @session << "--#{val}" if option(val) }
|
600
582
|
end
|
601
583
|
|
602
584
|
def git_session(*cmd)
|
603
585
|
session('git', *cmd)
|
604
586
|
end
|
605
587
|
|
606
|
-
def
|
607
|
-
|
608
|
-
end
|
609
|
-
|
610
|
-
def gitdir
|
611
|
-
base_path('.git')
|
588
|
+
def gitpath
|
589
|
+
basepath('.git')
|
612
590
|
end
|
613
591
|
|
614
592
|
def push?
|
@@ -618,7 +596,13 @@ module Squared
|
|
618
596
|
def dry_run?
|
619
597
|
@session.include?('--dry-run')
|
620
598
|
end
|
599
|
+
|
600
|
+
def threadargs
|
601
|
+
{ stderr: true, exception: exception || !workspace.series.multiple? }
|
602
|
+
end
|
621
603
|
end
|
604
|
+
|
605
|
+
Application.implement Git
|
622
606
|
end
|
623
607
|
end
|
624
608
|
end
|