squared 0.5.16 → 0.6.0
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/CHANGELOG.md +87 -64
- data/README.md +75 -34
- data/lib/squared/common/base.rb +1 -22
- data/lib/squared/common/format.rb +34 -26
- data/lib/squared/common/prompt.rb +57 -34
- data/lib/squared/common/shell.rb +70 -49
- data/lib/squared/common/system.rb +69 -36
- data/lib/squared/common/utils.rb +29 -6
- data/lib/squared/config.rb +23 -26
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +80 -81
- data/lib/squared/workspace/project/base.rb +517 -354
- data/lib/squared/workspace/project/docker.rb +376 -273
- data/lib/squared/workspace/project/git.rb +329 -314
- data/lib/squared/workspace/project/node.rb +494 -265
- data/lib/squared/workspace/project/python.rb +328 -199
- data/lib/squared/workspace/project/ruby.rb +655 -347
- data/lib/squared/workspace/project/support/class.rb +189 -169
- data/lib/squared/workspace/repo.rb +43 -41
- data/lib/squared/workspace/series.rb +6 -6
- data/lib/squared/workspace/support/base.rb +3 -24
- data/lib/squared/workspace/support/variables.rb +48 -0
- data/lib/squared/workspace/support.rb +1 -1
- data/lib/squared/workspace.rb +1 -1
- metadata +2 -2
- data/lib/squared/workspace/support/data.rb +0 -11
|
@@ -41,13 +41,13 @@ module Squared
|
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
data.each do |key, val|
|
|
44
|
-
if val.is_a?(Hash)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
uri = if val.is_a?(Hash)
|
|
45
|
+
opts = val.fetch(:options, {})
|
|
46
|
+
val.fetch(:uri, '')
|
|
47
|
+
else
|
|
48
|
+
opts = options
|
|
49
|
+
val.is_a?(String) ? val : key.to_s
|
|
50
|
+
end
|
|
51
51
|
unless uri.match?(GIT_PROTO) || Pathname.new(uri).absolute?
|
|
52
52
|
if uri.start_with?('.')
|
|
53
53
|
uri = @root + uri
|
|
@@ -57,8 +57,7 @@ module Squared
|
|
|
57
57
|
next
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
|
-
key = task_name
|
|
61
|
-
GIT_REPO[main][key] = [uri.to_s, opts]
|
|
60
|
+
GIT_REPO[main][key = task_name(key)] = [uri.to_s, opts]
|
|
62
61
|
@kind[key] << Project::Git
|
|
63
62
|
end
|
|
64
63
|
if cache == true
|
|
@@ -69,6 +68,16 @@ module Squared
|
|
|
69
68
|
self
|
|
70
69
|
end
|
|
71
70
|
|
|
71
|
+
def git_repo(name)
|
|
72
|
+
(ret = GIT_REPO[main]) && ret[name]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def git_clone?(path, name = nil)
|
|
76
|
+
return false if name && !git_repo(name)
|
|
77
|
+
|
|
78
|
+
!path.exist? || path.empty?
|
|
79
|
+
end
|
|
80
|
+
|
|
72
81
|
def revbuild(file: nil)
|
|
73
82
|
@revfile = @home.join(file || "#{@main}.revb")
|
|
74
83
|
@revdoc = JSON.parse(@revfile.read) if @revfile.exist?
|
|
@@ -81,10 +90,6 @@ module Squared
|
|
|
81
90
|
self
|
|
82
91
|
end
|
|
83
92
|
|
|
84
|
-
def git_repo(name)
|
|
85
|
-
(ret = GIT_REPO[main]) && ret[name]
|
|
86
|
-
end
|
|
87
|
-
|
|
88
93
|
def rev_entry(*keys, val: nil, create: true)
|
|
89
94
|
return unless @revdoc
|
|
90
95
|
return @revdoc.dig(*keys) unless val
|
|
@@ -138,18 +143,6 @@ module Squared
|
|
|
138
143
|
ensure
|
|
139
144
|
@revlock = false
|
|
140
145
|
end
|
|
141
|
-
|
|
142
|
-
def git_clone?(path, name = nil)
|
|
143
|
-
return false if name && !git_repo(name)
|
|
144
|
-
|
|
145
|
-
!path.exist? || path.empty?
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
private
|
|
149
|
-
|
|
150
|
-
def rev_timenow
|
|
151
|
-
Time.now.utc.strftime('%s%L').to_i
|
|
152
|
-
end
|
|
153
146
|
end
|
|
154
147
|
Application.include Git
|
|
155
148
|
|
|
@@ -159,12 +152,11 @@ module Squared
|
|
|
159
152
|
common: %w[c=q bare glob-pathspecs icase-pathspecs literal-pathspecs no-optional-locks no-pager
|
|
160
153
|
no-replace-objects noglob-pathspecs paginate attr-source=b config-env=q exec-path=p
|
|
161
154
|
namespace=p].freeze,
|
|
162
|
-
add: %w[A
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
sort=q t|track=b].freeze,
|
|
155
|
+
add: %w[A e|edit f|force ignore-errors ignore-missing i|interactive n|dry-run p|patch pathspec-file-nul
|
|
156
|
+
refresh renormalize sparse u|update v|verbose chmod=b pathspec-from-file=p].freeze,
|
|
157
|
+
branch: %w[a|all create-reflog i|ignore-case omit-empty q|quiet r|remotes v|verbose abbrev=i color=b column=b
|
|
158
|
+
contains=b format=q merged=b no-contains=b no-merged=b points-at=b u|set-upstream-to=b sort=q
|
|
159
|
+
t|track=b].freeze,
|
|
168
160
|
checkout: %w[l d|detach f|force ignore-other-worktrees ignore-skip-worktree-bits m|merge p|patch
|
|
169
161
|
pathspec-file-nul q|quiet ours theirs conflict=b orphan=b pathspec-from-file=p t|track=b].freeze,
|
|
170
162
|
diff: {
|
|
@@ -174,17 +166,22 @@ module Squared
|
|
|
174
166
|
fetch: {
|
|
175
167
|
base: %w[multiple porcelain progress P|prune-tags refetch stdin u|update-head-ok
|
|
176
168
|
recurse-submodules-default=b].freeze,
|
|
177
|
-
pull: %w[4 6 n t a|append atomic dry-run f|force k|keep negotiate-only prefetch p|prune q|quiet
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
upload-pack=q].freeze
|
|
169
|
+
pull: %w[4 6 n t a|append atomic dry-run f|force k|keep negotiate-only prefetch p|prune q|quiet set-upstream
|
|
170
|
+
unshallow update-shallow v|verbose deepen=i depth=i j|jobs=i negotiation-tip=q recurse-submodules=v
|
|
171
|
+
refmap=q o|server-option=q shallow-exclude=b shallow-since=v upload-pack=q].freeze
|
|
181
172
|
}.freeze,
|
|
182
173
|
git: {
|
|
183
174
|
add: %w[N|intent-to-add refresh].freeze,
|
|
184
175
|
blame: %w[b c l s t w C=im? L=q M=im? S=p color-by-age color-lines first-parent incremental line-porcelain
|
|
185
|
-
p|porcelain root score-debug f|show-name e|show-email n|show-number show-stats abbrev=i
|
|
186
|
-
|
|
176
|
+
p|porcelain root score-debug f|show-name e|show-email n|show-number show-stats abbrev=i contents=p
|
|
177
|
+
date=q encoding=b ignore-rev=b ignore-revs-file=p reverse=q].freeze,
|
|
187
178
|
clean: %w[d x X f|force n|dry-run i|interactive q|quiet e|exclude=q].freeze,
|
|
179
|
+
grep: %w[e f=p h H I O=bm r all-match and G|basic-regexp break cached column c|count E|extended-regexp
|
|
180
|
+
l|files-with-matches L|files-without-match F|fixed-strings full-name W|function-context heading
|
|
181
|
+
i|ignore-case v|invert-match n|line-number name-only no-index not z|null o|only-matching or
|
|
182
|
+
P|perl-regexp q|quiet recurse-submodules p|show-function a|text untracked w|word-regexp
|
|
183
|
+
A|after-context=i B|before-context=i color=b C|context=i m|max-count=n max-depth=i
|
|
184
|
+
open-files-in-pager=b threads=n].freeze,
|
|
188
185
|
mv: %w[k f|force n|dry-run v|verbose].freeze,
|
|
189
186
|
revert: %w[e S=bm? abort continue n|no-commit quit reference skip cleanup=b gpg-sign=b? m|mainline=i
|
|
190
187
|
s|signoff strategy=b X|strategy-option=b].freeze,
|
|
@@ -204,26 +201,27 @@ module Squared
|
|
|
204
201
|
format: %w[t children combined-all-paths dd oneline left-right no-diff-merges parents relative-date
|
|
205
202
|
show-notes-by-default show-signature date=q diff-merges=b encoding=b expand-tabs=i format=q
|
|
206
203
|
notes=b pretty=q? show-linear-break=q?].freeze,
|
|
207
|
-
diff: %w[p R u z B=bm? C=bm? l=im G=qm I=qm M=bm? O=qm S=qm
|
|
204
|
+
diff: %w[p R u z B=bm? C=bm? l=im G=qm I=qm M=bm? O=qm S=qm binary check compact-summary cumulative
|
|
208
205
|
find-copies-harder full-index W|function-context w|ignore-all-space ignore-blank-lines
|
|
209
206
|
ignore-cr-at-eol ignore-space-at-eol b|ignore-space-change D|irreversible-delete graph
|
|
210
207
|
ita-invisible-in-index minimal name-only name-status no-color-moved-ws no-prefix no-renames numstat
|
|
211
208
|
patch-with-raw patch-with-stat patience pickaxe-all pickaxe-regex raw shortstat summary a|text
|
|
212
209
|
abbrev=i? anchored=q break-rewrites=b? color=b color-moved=b color-moved-ws=b color-words=q?
|
|
213
210
|
diff-algorithm=b diff-filter=e? X|dirstat=b? dirstat-by-file=b? dst-prefix=q find-copies=i?
|
|
214
|
-
find-object=b find-renames=b? ignore-matching-lines=q ignore-submodules=b?
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
211
|
+
find-object=b find-renames=b? ignore-matching-lines=q ignore-submodules=b? line-prefix=q output=p
|
|
212
|
+
output-indicator-context=q output-indicator-new=q output-indicator-old=q relative=p rotate-to=p
|
|
213
|
+
skip-to=p src-prefix=q stat=b? stat-count=i stat-width=i stat-name-width=i submodule=b?
|
|
214
|
+
word-diff=b? word-diff-regex=q ws-error-highlight=b].freeze,
|
|
215
|
+
diff_context: %w[U=im inter-hunk-context=i unified=i].freeze
|
|
218
216
|
}.freeze,
|
|
219
217
|
ls_files: %w[f t v z debug deduplicate directory eol error-unmatch exclude-standard full-name i|ignored
|
|
220
218
|
k|killed no-empty-directory recurse-submodules sparse s|stage u|unmerged abbrev=i x|exclude=q
|
|
221
219
|
X|exclude-from=p exclude-per-directory=p format=q with-tree=q].freeze,
|
|
222
220
|
ls_remote: %w[exit-code get-url q|quiet symref o|server-option=q sort=q upload-pack=q].freeze,
|
|
223
|
-
merge: %w[e n S=bm? allow-unrelated-histories ff-only m=q q|quiet v|verbose cleanup=b F|file=p
|
|
224
|
-
into-name=b log=i s|strategy=b X|strategy-option=b].freeze,
|
|
225
|
-
pull: %w[e n S=bm? allow-unrelated-histories ff-only cleanup=b gpg-sign=b? log=i r|rebase=v?
|
|
226
|
-
X|strategy-option=b].freeze,
|
|
221
|
+
merge: %w[e n S=bm? allow-unrelated-histories compact-summary ff-only m=q q|quiet v|verbose cleanup=b F|file=p
|
|
222
|
+
gpg-sign=b? into-name=b log=i s|strategy=b X|strategy-option=b].freeze,
|
|
223
|
+
pull: %w[e n S=bm? allow-unrelated-histories compact-summary ff-only cleanup=b gpg-sign=b? log=i r|rebase=v?
|
|
224
|
+
s|strategy=b X|strategy-option=b].freeze,
|
|
227
225
|
rebase: %w[n C=im S=bm? allow-empty-message apply committer-date-is-author-date edit-todo empty=b
|
|
228
226
|
f|force-rebase ignore-date ignore-whitespace i|interactive keep-base m|merge no-ff q|quiet quit
|
|
229
227
|
reset-author-date root show-current-patch signoff v|verbose empty=b x|exec=q gpg-sign=b? onto=b
|
|
@@ -242,8 +240,8 @@ module Squared
|
|
|
242
240
|
encoding=b expand-tabs=i notes=q show-notes=q?].freeze,
|
|
243
241
|
stash: {
|
|
244
242
|
common: %w[q|quiet].freeze,
|
|
245
|
-
push: %w[a|all u|include-untracked k|keep-index no-keep-index no-include-untracked pathspec-file-nul
|
|
246
|
-
|
|
243
|
+
push: %w[a|all u|include-untracked k|keep-index no-keep-index no-include-untracked pathspec-file-nul p|patch
|
|
244
|
+
S|staged m|message=q pathspec-from-file=p].freeze,
|
|
247
245
|
pop: %w[index].freeze,
|
|
248
246
|
apply: %w[index].freeze
|
|
249
247
|
}.freeze,
|
|
@@ -261,6 +259,7 @@ module Squared
|
|
|
261
259
|
tag: %w[n=im cleanup=b create-reflog i|ignore-case omit-empty color=b? column=b contains=b? format=q merged=b?
|
|
262
260
|
no-contains=b? no-merged=b? points-at=q sort=q trailer=q].freeze,
|
|
263
261
|
no: {
|
|
262
|
+
add: %w[all ignore-removal].freeze,
|
|
264
263
|
blame: %w[progress].freeze,
|
|
265
264
|
branch: %w[color color-moved column track].freeze,
|
|
266
265
|
checkout: %w[overwrite-ignore guess overlay progress recurse-submodules track].freeze,
|
|
@@ -268,6 +267,7 @@ module Squared
|
|
|
268
267
|
base: %w[auto-gc auto-maintenance write-commit-graph write-fetch-head].freeze,
|
|
269
268
|
pull: %w[all ipv4 ipv6 recurse-submodules show-forced-updates tags].freeze
|
|
270
269
|
},
|
|
270
|
+
grep: %w[color exclude-standard recursive textconv].freeze,
|
|
271
271
|
log: {
|
|
272
272
|
base: %w[decorate mailmap merges use-mailmap].freeze,
|
|
273
273
|
diff: %w[color color-moved ext-diff indent-heuristic patch relative rename-empty textconv].freeze,
|
|
@@ -303,33 +303,6 @@ module Squared
|
|
|
303
303
|
class << self
|
|
304
304
|
include Rake::DSL
|
|
305
305
|
|
|
306
|
-
def populate(ws, **)
|
|
307
|
-
return if ws.series.exclude?(:pull, true) || ws.size == 1
|
|
308
|
-
|
|
309
|
-
namespace ws.task_name('git') do |ns|
|
|
310
|
-
ws.format_desc(all = ws.task_join(ns.scope.path, 'all'), 'stash|rebase|autostash?,depend?')
|
|
311
|
-
task 'all' do |_, args|
|
|
312
|
-
args = args.to_a
|
|
313
|
-
cmd = if args.include?('stash')
|
|
314
|
-
['stash', 'pull']
|
|
315
|
-
elsif args.include?('rebase')
|
|
316
|
-
['rebase']
|
|
317
|
-
elsif args.include?('autostash')
|
|
318
|
-
['autostash']
|
|
319
|
-
else
|
|
320
|
-
['pull']
|
|
321
|
-
end
|
|
322
|
-
cmd.map! { |val| ws.task_sync(val) }
|
|
323
|
-
cmd << ws.task_sync('depend') if args.include?('depend') && !ws.series.exclude?(:depend, true)
|
|
324
|
-
cmd << ws.task_sync('build')
|
|
325
|
-
Common::Utils.task_invoke(*cmd, **ws.invokeargs)
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
ws.series.sync << all
|
|
329
|
-
ws.series.multiple << all
|
|
330
|
-
end
|
|
331
|
-
end
|
|
332
|
-
|
|
333
306
|
def tasks
|
|
334
307
|
%i[pull rebase autostash fetch clone stash status branch revbuild].freeze
|
|
335
308
|
end
|
|
@@ -348,7 +321,7 @@ module Squared
|
|
|
348
321
|
'diff' => %i[head branch files view between contain].freeze,
|
|
349
322
|
'fetch' => %i[origin remote all].freeze,
|
|
350
323
|
'files' => %i[cached modified deleted others].freeze,
|
|
351
|
-
'git' => %i[add blame clean mv revert rm status].freeze,
|
|
324
|
+
'git' => %i[add blame clean grep mv revert rm status].freeze,
|
|
352
325
|
'log' => %i[view between contain].freeze,
|
|
353
326
|
'merge' => %i[commit no-commit send].freeze,
|
|
354
327
|
'pull' => %i[origin remote all].freeze,
|
|
@@ -358,7 +331,7 @@ module Squared
|
|
|
358
331
|
'restore' => %i[source staged worktree].freeze,
|
|
359
332
|
'rev' => %i[commit build output].freeze,
|
|
360
333
|
'show' => %i[format oneline textconv].freeze,
|
|
361
|
-
'stash' => %i[push pop apply branch drop clear list all].freeze,
|
|
334
|
+
'stash' => %i[push pop apply branch drop clear list all staged worktree].freeze,
|
|
362
335
|
'submodule' => %i[status update branch url sync].freeze,
|
|
363
336
|
'switch' => %i[branch create detach].freeze,
|
|
364
337
|
'tag' => %i[add sign delete list].freeze
|
|
@@ -366,7 +339,7 @@ module Squared
|
|
|
366
339
|
|
|
367
340
|
def initialize(*, **)
|
|
368
341
|
super
|
|
369
|
-
@submodule =
|
|
342
|
+
@submodule = exist?('.gitmodules')
|
|
370
343
|
initialize_ref Git.ref if gitpath.exist?
|
|
371
344
|
end
|
|
372
345
|
|
|
@@ -389,16 +362,16 @@ module Squared
|
|
|
389
362
|
if flag == :remote
|
|
390
363
|
format_desc action, flag, 'remote?,opts*'
|
|
391
364
|
task flag, [:remote] do |_, args|
|
|
392
|
-
if (remote = args.remote)
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
365
|
+
args = if (remote = args.remote)
|
|
366
|
+
args.extras
|
|
367
|
+
else
|
|
368
|
+
remote = choice_remote
|
|
369
|
+
args.to_a
|
|
370
|
+
end
|
|
398
371
|
__send__(action, flag, args, remote: remote)
|
|
399
372
|
end
|
|
400
373
|
else
|
|
401
|
-
format_desc(action, flag, 'opts*', after: flag == :all && action == 'pull'
|
|
374
|
+
format_desc(action, flag, 'opts*', after: ('pattern*' if flag == :all && action == 'pull'))
|
|
402
375
|
task flag do |_, args|
|
|
403
376
|
__send__ action, flag, args.to_a
|
|
404
377
|
end
|
|
@@ -435,11 +408,11 @@ module Squared
|
|
|
435
408
|
commit(flag, message: args.message)
|
|
436
409
|
end
|
|
437
410
|
else
|
|
438
|
-
format_desc(action, flag, 'pathspec+', before: flag == :add
|
|
411
|
+
format_desc(action, flag, 'pathspec+', before: ('opts*' if flag == :add))
|
|
439
412
|
task flag do |_, args|
|
|
440
413
|
if flag == :fixup
|
|
441
|
-
ref, squash, pick = choice_commit(accept: [
|
|
442
|
-
values:
|
|
414
|
+
ref, squash, pick = choice_commit(reflog: false, accept: [accept_b('Auto squash?')],
|
|
415
|
+
values: 'Pick [amend|reword]')
|
|
443
416
|
pick &&= case pick.downcase
|
|
444
417
|
when 'a', 'amend'
|
|
445
418
|
'amend'
|
|
@@ -481,7 +454,7 @@ module Squared
|
|
|
481
454
|
task flag do |_, args|
|
|
482
455
|
refs = args.to_a
|
|
483
456
|
if refs.empty?
|
|
484
|
-
refs = choice_refs('Choose a tag', 'tags', multiple: true, accept: 'Delete?'
|
|
457
|
+
refs = choice_refs('Choose a tag', 'tags', multiple: true, series: true, accept: 'Delete?')
|
|
485
458
|
remote = choice_remote
|
|
486
459
|
end
|
|
487
460
|
tag(flag, refs: refs, remote: remote)
|
|
@@ -494,12 +467,13 @@ module Squared
|
|
|
494
467
|
commit = commithead args.commit
|
|
495
468
|
remote = args.remote
|
|
496
469
|
else
|
|
497
|
-
commit, name, message = choice_commit(
|
|
498
|
-
|
|
470
|
+
commit, name, message = choice_commit(reflog: false, series: true,
|
|
471
|
+
values: [['Enter tag name', true], 'Enter message'])
|
|
499
472
|
remote = choice_remote
|
|
500
473
|
end
|
|
501
|
-
|
|
502
|
-
|
|
474
|
+
tag(flag, refs: [name], message: message, commit: commit, remote: remote).tap do |ret|
|
|
475
|
+
success?(ret, !remote)
|
|
476
|
+
end
|
|
503
477
|
end
|
|
504
478
|
end
|
|
505
479
|
when 'stash'
|
|
@@ -515,9 +489,8 @@ module Squared
|
|
|
515
489
|
when 'log', 'diff'
|
|
516
490
|
case flag
|
|
517
491
|
when :view, :between, :contain
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
format_desc action, flag, '(^)commit*|:,opts*,ref?,pathspec*'
|
|
492
|
+
if action == 'log' && flag == :view
|
|
493
|
+
format_desc action, flag, '(^)commit*|:,opts*,pathspec*'
|
|
521
494
|
task flag do |_, args|
|
|
522
495
|
args = args.to_a
|
|
523
496
|
if args.first == ':'
|
|
@@ -544,16 +517,17 @@ module Squared
|
|
|
544
517
|
format_desc action, flag, 'commit1,commit2,opts*,pathspec*'
|
|
545
518
|
task flag, [:commit1, :commit2] do |_, args|
|
|
546
519
|
commit1 = commithead args.commit1
|
|
547
|
-
if commit1
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
520
|
+
range = if commit1
|
|
521
|
+
commit2 = commithead param_guard(action, flag, args: args, key: :commit2)
|
|
522
|
+
args = args.extras
|
|
523
|
+
[commit1, commit2]
|
|
524
|
+
else
|
|
525
|
+
range, opts, refs = choice_commit(multiple: flag == :view ? true : 2,
|
|
526
|
+
values: %w[Options Pathspec])
|
|
527
|
+
args = OptionPartition.strip(opts)
|
|
528
|
+
args.concat(refs.shellsplit) if refs
|
|
529
|
+
range.reverse
|
|
530
|
+
end
|
|
557
531
|
__send__(action == 'log' ? :log! : :diff, flag, args, range: range)
|
|
558
532
|
end
|
|
559
533
|
end
|
|
@@ -566,7 +540,11 @@ module Squared
|
|
|
566
540
|
index = choice_commit(multiple: true)
|
|
567
541
|
else
|
|
568
542
|
index = []
|
|
569
|
-
args.each
|
|
543
|
+
args.each do |val|
|
|
544
|
+
break unless (sha = commithead(val) || commithash(val))
|
|
545
|
+
|
|
546
|
+
index << sha
|
|
547
|
+
end
|
|
570
548
|
args = args.drop(index.size)
|
|
571
549
|
end
|
|
572
550
|
diff(flag, args, index: index)
|
|
@@ -578,36 +556,36 @@ module Squared
|
|
|
578
556
|
diff(flag, args.extras, branch: branch)
|
|
579
557
|
end
|
|
580
558
|
when :files
|
|
581
|
-
format_desc action, flag, 'path1,path2'
|
|
582
|
-
task flag, [:path1, :path2] do |_, args|
|
|
559
|
+
format_desc action, flag, 'path1,path2,patch?'
|
|
560
|
+
task flag, [:path1, :path2, :patch] do |_, args|
|
|
583
561
|
path1 = param_guard(action, flag, args: args, key: :path1)
|
|
584
562
|
path2 = param_guard(action, flag, args: args, key: :path2)
|
|
585
|
-
diff(flag, refs: [path1, path2])
|
|
563
|
+
diff(flag, refs: [path1, path2, args.patch])
|
|
586
564
|
end
|
|
587
565
|
end
|
|
588
566
|
when 'checkout'
|
|
589
567
|
case flag
|
|
590
568
|
when :branch
|
|
591
|
-
format_desc action, flag, 'name,create?=[bB],commit?,
|
|
569
|
+
format_desc action, flag, 'name,create?=[bB],commit?,d/etach?'
|
|
592
570
|
task flag, [:name, :create, :commit, :detach] do |_, args|
|
|
593
571
|
if (branch = args.name)
|
|
594
572
|
branch = param_guard(action, flag, args: args, key: :name)
|
|
595
573
|
create = args.create
|
|
596
|
-
if args.commit == 'd'
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
574
|
+
detach = if args.commit == 'd'
|
|
575
|
+
commit = nil
|
|
576
|
+
'd'
|
|
577
|
+
elsif create == 'd'
|
|
578
|
+
create = nil
|
|
579
|
+
commit = nil
|
|
580
|
+
'd'
|
|
581
|
+
elsif create && create.size > 1
|
|
582
|
+
commit = commithead create
|
|
583
|
+
create = nil
|
|
584
|
+
args.commit
|
|
585
|
+
else
|
|
586
|
+
commit = commithead args.commit
|
|
587
|
+
args.detach
|
|
588
|
+
end
|
|
611
589
|
param_guard(action, flag, args: { create: create }, key: :create, pat: /\A[Bb]\z/) if create
|
|
612
590
|
else
|
|
613
591
|
branch = choice_refs 'Choose a branch to switch'
|
|
@@ -620,7 +598,7 @@ module Squared
|
|
|
620
598
|
if (origin = args.origin)
|
|
621
599
|
branch = args.name
|
|
622
600
|
else
|
|
623
|
-
origin, branch = choice_refs('Choose a remote', 'remotes', values:
|
|
601
|
+
origin, branch = choice_refs('Choose a remote', 'remotes', values: 'Enter branch name')
|
|
624
602
|
end
|
|
625
603
|
checkout(flag, branch: branch, origin: origin)
|
|
626
604
|
end
|
|
@@ -631,7 +609,7 @@ module Squared
|
|
|
631
609
|
args = if commit
|
|
632
610
|
args.extras
|
|
633
611
|
else
|
|
634
|
-
commit, opts = choice_commit(values:
|
|
612
|
+
commit, opts = choice_commit(values: 'Options')
|
|
635
613
|
OptionPartition.strip(opts)
|
|
636
614
|
end
|
|
637
615
|
checkout(flag, args, commit: commit)
|
|
@@ -641,7 +619,7 @@ module Squared
|
|
|
641
619
|
task flag, [:commit] do |_, args|
|
|
642
620
|
commit = commithead args.commit
|
|
643
621
|
unless commit
|
|
644
|
-
commit, merge = choice_commit(values:
|
|
622
|
+
commit, merge = choice_commit(values: 'Merge? [y/N]')
|
|
645
623
|
merge = merge&.upcase == 'Y'
|
|
646
624
|
end
|
|
647
625
|
checkout(flag, commit: commit, merge: merge)
|
|
@@ -655,11 +633,13 @@ module Squared
|
|
|
655
633
|
when 'branch'
|
|
656
634
|
case flag
|
|
657
635
|
when :create
|
|
658
|
-
format_desc action, flag, 'name,ref
|
|
636
|
+
format_desc action, flag, 'name,ref?|:'
|
|
659
637
|
task flag, [:name, :ref] do |_, args|
|
|
660
638
|
target = param_guard(action, flag, args: args, key: :name)
|
|
661
639
|
ref = commithead args.ref
|
|
662
|
-
|
|
640
|
+
if ref == ':'
|
|
641
|
+
ref, remote = choice_refs('Choose a remote', 'remotes', accept: [accept_b('Push?')])
|
|
642
|
+
end
|
|
663
643
|
branch(flag, target: target, ref: ref, remote: remote)
|
|
664
644
|
end
|
|
665
645
|
when :track
|
|
@@ -669,18 +649,18 @@ module Squared
|
|
|
669
649
|
target = args.name
|
|
670
650
|
remote = true if ref.delete_prefix!('~')
|
|
671
651
|
else
|
|
672
|
-
ref, remote, target = choice_refs('Choose a remote', 'remotes', accept: [
|
|
673
|
-
values:
|
|
652
|
+
ref, remote, target = choice_refs('Choose a remote', 'remotes', accept: [accept_b('Push?')],
|
|
653
|
+
values: 'Enter branch name')
|
|
674
654
|
end
|
|
675
655
|
branch(flag, target: target, ref: ref, remote: remote)
|
|
676
656
|
end
|
|
677
657
|
when :delete
|
|
678
|
-
format_desc action, flag, '
|
|
658
|
+
format_desc action, flag, '(^~)name*,:?'
|
|
679
659
|
task flag do |_, args|
|
|
680
660
|
refs = args.to_a
|
|
681
661
|
if refs.empty? || (r = refs.last == ':')
|
|
682
662
|
accept = ['Delete?']
|
|
683
|
-
accept <<
|
|
663
|
+
accept << accept_b('Force?') unless r
|
|
684
664
|
remote = choice_refs('Choose a branch', r ? 'remotes' : 'heads', multiple: true,
|
|
685
665
|
accept: accept)
|
|
686
666
|
if r
|
|
@@ -718,15 +698,15 @@ module Squared
|
|
|
718
698
|
when 'switch'
|
|
719
699
|
case flag
|
|
720
700
|
when :create
|
|
721
|
-
format_desc action, flag, '(^)name,ref
|
|
701
|
+
format_desc action, flag, '(^)name,ref?|:'
|
|
722
702
|
task flag, [:name, :commit] do |_, args|
|
|
723
703
|
branch = param_guard(action, flag, args: args, key: :name)
|
|
724
704
|
commit = commithead args.commit
|
|
725
|
-
commit, track = choice_commit(values:
|
|
705
|
+
commit, track = choice_commit(force: false, values: 'Track? [Y/n]') if commit == ':'
|
|
726
706
|
switch(flag, branch: branch, commit: commit, track: track)
|
|
727
707
|
end
|
|
728
708
|
when :detach
|
|
729
|
-
format_desc action, flag, 'ref
|
|
709
|
+
format_desc action, flag, 'ref?'
|
|
730
710
|
task flag, [:commit] do |_, args|
|
|
731
711
|
commit = commithead(args.commit) || choice_commit(force: false)
|
|
732
712
|
switch(flag, commit: commit)
|
|
@@ -734,12 +714,12 @@ module Squared
|
|
|
734
714
|
when :branch
|
|
735
715
|
format_desc action, flag, 'name|:,opts*'
|
|
736
716
|
task flag, [:name] do |_, args|
|
|
737
|
-
if (branch = args.name)
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
717
|
+
args = if (branch = args.name)
|
|
718
|
+
branch = nil if branch == ':'
|
|
719
|
+
args.extras
|
|
720
|
+
else
|
|
721
|
+
[]
|
|
722
|
+
end
|
|
743
723
|
switch(flag, args, branch: branch || choice_refs('Choose a branch'))
|
|
744
724
|
end
|
|
745
725
|
end
|
|
@@ -749,26 +729,26 @@ module Squared
|
|
|
749
729
|
format_desc action, flag, 'ref|:,opts*'
|
|
750
730
|
task flag, [:commit] do |_, args|
|
|
751
731
|
commit = commithead args.commit
|
|
752
|
-
if commit && commit != ':'
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
732
|
+
args = if commit && commit != ':'
|
|
733
|
+
args.extras
|
|
734
|
+
else
|
|
735
|
+
commit, mode = choice_commit(values: ['Mode [mixed|soft|hard|N]'])
|
|
736
|
+
args.extras.concat(case mode&.downcase
|
|
757
737
|
when 'h', 'hard' then ['hard']
|
|
758
738
|
when 's', 'soft' then ['soft']
|
|
759
|
-
when 'n', 'N' then [
|
|
739
|
+
when 'n', 'N' then %w[mixed N]
|
|
760
740
|
else ['mixed']
|
|
761
741
|
end)
|
|
762
|
-
|
|
763
|
-
|
|
742
|
+
end
|
|
743
|
+
success?(reset(flag, args, commit: commit))
|
|
764
744
|
end
|
|
765
745
|
when :index, :undo
|
|
766
|
-
format_desc(action, flag,
|
|
746
|
+
format_desc(action, flag, ('opts*,pathspec*' if flag == :index))
|
|
767
747
|
task flag do |_, args|
|
|
768
748
|
reset(flag, flag == :index ? args.to_a : [])
|
|
769
749
|
end
|
|
770
750
|
when :mode
|
|
771
|
-
format_desc action, flag, 'mode,ref
|
|
751
|
+
format_desc action, flag, 'mode,ref?|:'
|
|
772
752
|
task flag, [:mode, :ref] do |_, args|
|
|
773
753
|
mode = param_guard(action, flag, args: args, key: :mode)
|
|
774
754
|
ref = commithead args.ref
|
|
@@ -776,7 +756,7 @@ module Squared
|
|
|
776
756
|
reset(flag, mode: mode, ref: ref)
|
|
777
757
|
end
|
|
778
758
|
when :patch
|
|
779
|
-
format_desc action, flag, 'ref
|
|
759
|
+
format_desc action, flag, 'ref?|:,pathspec*'
|
|
780
760
|
task flag, [:ref] do |_, args|
|
|
781
761
|
ref = commithead args.ref
|
|
782
762
|
ref = choice_commit(reflog: false) unless ref && ref != ':'
|
|
@@ -805,18 +785,18 @@ module Squared
|
|
|
805
785
|
when 'rebase', 'merge'
|
|
806
786
|
case flag
|
|
807
787
|
when :branch
|
|
808
|
-
format_desc action, flag, 'upstream,branch
|
|
788
|
+
format_desc action, flag, 'upstream,branch?,opts*'
|
|
809
789
|
task flag, [:upstream] do |_, args|
|
|
810
790
|
args = if (upstream = args.upstream)
|
|
811
791
|
args.extras
|
|
812
792
|
else
|
|
813
|
-
upstream, opts = choice_refs('Choose upstream branch', values:
|
|
793
|
+
upstream, opts = choice_refs('Choose upstream branch', values: 'Options')
|
|
814
794
|
OptionPartition.strip(opts)
|
|
815
795
|
end
|
|
816
796
|
rebase(flag, args, upstream: upstream)
|
|
817
797
|
end
|
|
818
798
|
when :onto
|
|
819
|
-
format_desc action, flag, 'ref,upstream,branch
|
|
799
|
+
format_desc action, flag, 'ref,upstream,branch?'
|
|
820
800
|
task flag, [:commit, :upstream, :branch] do |_, args|
|
|
821
801
|
commit = commithead args.commit
|
|
822
802
|
args = if commit
|
|
@@ -825,7 +805,7 @@ module Squared
|
|
|
825
805
|
[]
|
|
826
806
|
else
|
|
827
807
|
commit = choice_refs 'Choose "onto" branch'
|
|
828
|
-
target, opts = choice_commit(reflog: false, multiple: 2, values:
|
|
808
|
+
target, opts = choice_commit(reflog: false, multiple: 2, values: 'Options')
|
|
829
809
|
branch, upstream = target
|
|
830
810
|
OptionPartition.strip(opts)
|
|
831
811
|
end
|
|
@@ -837,7 +817,7 @@ module Squared
|
|
|
837
817
|
args = args.to_a
|
|
838
818
|
if args.empty?
|
|
839
819
|
accept = "Merge with #{`#{git_output('branch --show-current')}`.chomp}?"
|
|
840
|
-
branch, opts = choice_refs('Choose a branch', values:
|
|
820
|
+
branch, opts = choice_refs('Choose a branch', values: 'Options', accept: accept)
|
|
841
821
|
args = OptionPartition.strip(opts)
|
|
842
822
|
end
|
|
843
823
|
merge(flag, args, branch: branch)
|
|
@@ -853,7 +833,7 @@ module Squared
|
|
|
853
833
|
when 'rev'
|
|
854
834
|
case flag
|
|
855
835
|
when :commit
|
|
856
|
-
format_desc action, flag, 'ref
|
|
836
|
+
format_desc action, flag, 'ref?,size?'
|
|
857
837
|
task flag, [:ref, :size] do |_, args|
|
|
858
838
|
ref = commithead args.ref
|
|
859
839
|
size = args.size
|
|
@@ -881,7 +861,7 @@ module Squared
|
|
|
881
861
|
ls_remote(flag, args.extras, remote: args.remote)
|
|
882
862
|
end
|
|
883
863
|
else
|
|
884
|
-
format_desc(action, flag, 'opts*,pattern*', after: action == 'files'
|
|
864
|
+
format_desc(action, flag, 'opts*,pattern*', after: ('pathspec*' if action == 'files'))
|
|
885
865
|
task flag do |_, args|
|
|
886
866
|
__send__(action == 'refs' ? :ls_remote : :ls_files, flag, args.to_a)
|
|
887
867
|
end
|
|
@@ -922,16 +902,22 @@ module Squared
|
|
|
922
902
|
end
|
|
923
903
|
when 'git'
|
|
924
904
|
before = case flag
|
|
925
|
-
when :blame
|
|
926
|
-
|
|
927
|
-
when :
|
|
905
|
+
when :blame
|
|
906
|
+
'file'
|
|
907
|
+
when :mv
|
|
908
|
+
'source+,destination'
|
|
909
|
+
when :revert
|
|
910
|
+
'commit+'
|
|
928
911
|
end
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
912
|
+
after = case flag
|
|
913
|
+
when :add
|
|
914
|
+
'pathspec*,pattern*'
|
|
915
|
+
when :grep
|
|
916
|
+
'tree*,pathspec*'
|
|
917
|
+
when :clean, :rm, :status
|
|
918
|
+
'pathspec*'
|
|
919
|
+
end
|
|
920
|
+
format_desc(action, flag, 'opts*', before: before, after: after)
|
|
935
921
|
task flag do |_, args|
|
|
936
922
|
__send__(flag == :status ? :status : :git, flag, args.to_a)
|
|
937
923
|
end
|
|
@@ -996,10 +982,10 @@ module Squared
|
|
|
996
982
|
cur ||= line.delete_prefix!('* ')
|
|
997
983
|
heads << line if matchany?(line, reg)
|
|
998
984
|
end
|
|
999
|
-
raise_error
|
|
985
|
+
raise_error 'head not found', hint: 'for-each-ref' unless cur
|
|
1000
986
|
opts << 'ff-only' if opts.empty? && !option('ff-only', equals: '0')
|
|
1001
|
-
(heads.dup << cur).each_with_index do |branch,
|
|
1002
|
-
next unless (
|
|
987
|
+
(heads.dup << cur).each_with_index do |branch, i|
|
|
988
|
+
next unless (i < heads.size && cur != branch) || i == heads.size
|
|
1003
989
|
|
|
1004
990
|
git_spawn 'switch --quiet', force && '--force', shell_quote(branch)
|
|
1005
991
|
pull(nil, opts, sync: false, hint: branch) if heads.include?(branch)
|
|
@@ -1013,8 +999,8 @@ module Squared
|
|
|
1013
999
|
no: OPT_GIT[:no][:pull] + OPT_GIT[:no][:fetch][:pull], remote: remote, flag: flag, from: :pull)
|
|
1014
1000
|
source(sync: sync, sub: if stdout?
|
|
1015
1001
|
[
|
|
1016
|
-
|
|
1017
|
-
|
|
1002
|
+
opt_style(color(:red), /^(.+)(\|\s+\d+\s+)([^-]*)(-+)(.*)$/, 4),
|
|
1003
|
+
opt_style(color(:green), /^(.+)(\|\s+\d+\s+)(\++)(.*)$/, 3)
|
|
1018
1004
|
]
|
|
1019
1005
|
end, hint: hint, **threadargs)
|
|
1020
1006
|
end
|
|
@@ -1030,7 +1016,7 @@ module Squared
|
|
|
1030
1016
|
|
|
1031
1017
|
op = OptionPartition.new(opts, OPT_GIT[:rebase], cmd, project: self, no: OPT_GIT[:no][:rebase])
|
|
1032
1018
|
op << upstream
|
|
1033
|
-
append_head op.shift
|
|
1019
|
+
append_head op.shift&.delete_prefix(':')
|
|
1034
1020
|
op.clear(pass: false)
|
|
1035
1021
|
when :onto
|
|
1036
1022
|
return unless upstream
|
|
@@ -1042,7 +1028,7 @@ module Squared
|
|
|
1042
1028
|
else
|
|
1043
1029
|
unless gitpath('REBASE_HEAD').exist?
|
|
1044
1030
|
puts log_message(Logger::INFO, name, 'no rebase in progress', hint: command) if stdout?
|
|
1045
|
-
|
|
1031
|
+
exit 1
|
|
1046
1032
|
end
|
|
1047
1033
|
return unless VAL_GIT[:rebase][:send].include?(command)
|
|
1048
1034
|
|
|
@@ -1097,17 +1083,28 @@ module Squared
|
|
|
1097
1083
|
|
|
1098
1084
|
def stash(flag = nil, opts = [], sync: invoked_sync?('stash', flag))
|
|
1099
1085
|
if flag
|
|
1100
|
-
|
|
1086
|
+
case flag
|
|
1087
|
+
when :all
|
|
1101
1088
|
opts << 'include-untracked'
|
|
1102
1089
|
flag = :push
|
|
1090
|
+
when :staged
|
|
1091
|
+
opts << 'staged'
|
|
1092
|
+
flag = :push
|
|
1093
|
+
when :worktree
|
|
1094
|
+
opts << 'keep-index'
|
|
1095
|
+
flag = :push
|
|
1096
|
+
end
|
|
1097
|
+
unless (file = gitpath('logs/refs/stash')).exist? || flag == :push
|
|
1098
|
+
puts log_message(Logger::INFO, name, 'no stashes were found', hint: flag) if stdout?
|
|
1099
|
+
exit 1
|
|
1103
1100
|
end
|
|
1104
1101
|
cmd, opts = git_session('stash', flag, opts: opts)
|
|
1105
1102
|
list = OPT_GIT[:stash][:common] + OPT_GIT[:stash].fetch(flag, [])
|
|
1106
1103
|
if flag == :list
|
|
1107
|
-
list
|
|
1104
|
+
list.concat(collect_hash(OPT_GIT[:log]))
|
|
1108
1105
|
no = collect_hash OPT_GIT[:no][:log]
|
|
1109
1106
|
end
|
|
1110
|
-
op = OptionPartition.new(opts, list, cmd, project: self, no: no, first: flag == :push
|
|
1107
|
+
op = OptionPartition.new(opts, list, cmd, project: self, no: no, first: (matchpathspec if flag == :push))
|
|
1111
1108
|
case flag
|
|
1112
1109
|
when :push
|
|
1113
1110
|
op.append?('message', readline('Enter message', force: true), force: true) if op.remove(':')
|
|
@@ -1118,24 +1115,26 @@ module Squared
|
|
|
1118
1115
|
if op.empty?
|
|
1119
1116
|
values = [['Branch name', true]]
|
|
1120
1117
|
else
|
|
1121
|
-
op
|
|
1118
|
+
op.add_first(prefix: ':')
|
|
1122
1119
|
end
|
|
1123
1120
|
end
|
|
1124
1121
|
out = choice_index('Choose a stash', git_spawn('stash list', stdout: false),
|
|
1125
|
-
values: values, column: /^[^@]+@\{(\d+)
|
|
1122
|
+
values: values, column: /^[^@]+@\{(\d+)}/, force: true)
|
|
1126
1123
|
if values
|
|
1127
1124
|
op.merge(out.reverse)
|
|
1128
1125
|
else
|
|
1129
1126
|
op << out
|
|
1130
1127
|
end
|
|
1131
1128
|
elsif !op.empty?
|
|
1132
|
-
op
|
|
1129
|
+
op.add_first(prefix: ':')
|
|
1133
1130
|
elsif flag == :branch
|
|
1134
|
-
raise_error 'no branch name'
|
|
1131
|
+
raise_error ArgumentError, 'no branch name'
|
|
1135
1132
|
end
|
|
1136
1133
|
op.clear
|
|
1137
1134
|
when :clear
|
|
1138
|
-
|
|
1135
|
+
n = sub_style(file.read.lines.size, styles: theme[:inline])
|
|
1136
|
+
s = sub_style(name, styles: theme[:active])
|
|
1137
|
+
source(stdout: true) if confirm("Remove #{n} stash entries from #{s}?", 'N')
|
|
1139
1138
|
return
|
|
1140
1139
|
when :list
|
|
1141
1140
|
op.clear
|
|
@@ -1179,13 +1178,13 @@ module Squared
|
|
|
1179
1178
|
g = color(:green)
|
|
1180
1179
|
sub = if session_arg?('short')
|
|
1181
1180
|
[
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1181
|
+
opt_style(r, /^(.)([A-Z?!])(.+)$/, 2),
|
|
1182
|
+
opt_style(g, /^([A-Z?!])(.+)$/),
|
|
1183
|
+
opt_style(r, /^(\?\?)(.+)$/),
|
|
1184
|
+
opt_style([nil, g, nil, r], /^(## )((?~\.{3}))(\.{3})(.+)$/, -1)
|
|
1186
1185
|
]
|
|
1187
1186
|
else
|
|
1188
|
-
|
|
1187
|
+
opt_style(r, /^(\t+)([a-z]+: +.+)$/, 2)
|
|
1189
1188
|
end
|
|
1190
1189
|
end
|
|
1191
1190
|
out, banner, from = source(io: true)
|
|
@@ -1219,26 +1218,24 @@ module Squared
|
|
|
1219
1218
|
op.clear(append: true)
|
|
1220
1219
|
args = op.to_a
|
|
1221
1220
|
else
|
|
1222
|
-
args = [
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1221
|
+
args = [
|
|
1222
|
+
option('untracked-files', prefix: 'git') { |val| basic_option('untracked-files', val) },
|
|
1223
|
+
option('ignore-submodules', prefix: 'git') { |val| basic_option('ignore-submodules', val) },
|
|
1224
|
+
option('ignored', prefix: 'git') { |val| basic_option('ignored', val) }
|
|
1225
|
+
].compact
|
|
1226
1226
|
end
|
|
1227
1227
|
if (cur = workspace.rev_entry(name)) && cur['revision'] == sha && !env('REVBUILD_FORCE')
|
|
1228
1228
|
files = status_digest(*args, **kwargs)
|
|
1229
1229
|
if cur['files'].size == files.size && cur['files'].find { |key, val| files[key] != val }.nil?
|
|
1230
|
+
workspace.rev_timeutc(name, 'build') unless (since = workspace.rev_timesince(name, 'build'))
|
|
1230
1231
|
if stdout?
|
|
1231
|
-
|
|
1232
|
-
puts log_message(Logger::INFO, name, 'no changes', subject: 'revbuild', hint: "#{since} ago")
|
|
1233
|
-
else
|
|
1234
|
-
workspace.rev_timeutc(name, 'build')
|
|
1235
|
-
end
|
|
1232
|
+
puts log_message(Logger::INFO, name, 'no changes', subject: 'revbuild', hint: since && "#{since} ago")
|
|
1236
1233
|
end
|
|
1237
1234
|
return
|
|
1238
1235
|
end
|
|
1239
1236
|
end
|
|
1240
1237
|
start = time_epoch
|
|
1241
|
-
build(
|
|
1238
|
+
build(@output, sync: sync, from: :'git:revbuild')
|
|
1242
1239
|
rescue StandardError => e
|
|
1243
1240
|
print_error(e, pass: true)
|
|
1244
1241
|
else
|
|
@@ -1251,9 +1248,8 @@ module Squared
|
|
|
1251
1248
|
cmd, opts = git_session('reset', opts: opts)
|
|
1252
1249
|
case flag
|
|
1253
1250
|
when :commit, :index
|
|
1254
|
-
op = OptionPartition.new(opts, OPT_GIT[:reset] + VAL_GIT[:reset], cmd,
|
|
1255
|
-
project: self, no: OPT_GIT[:no][:reset],
|
|
1256
|
-
first: flag == :index ? matchpathspec : nil)
|
|
1251
|
+
op = OptionPartition.new(opts, OPT_GIT[:reset] + VAL_GIT[:reset] + OPT_GIT[:log][:diff_context], cmd,
|
|
1252
|
+
project: self, no: OPT_GIT[:no][:reset], first: (matchpathspec if flag == :index))
|
|
1257
1253
|
if flag == :commit
|
|
1258
1254
|
op.append(commit)
|
|
1259
1255
|
.clear(pass: false)
|
|
@@ -1284,7 +1280,7 @@ module Squared
|
|
|
1284
1280
|
|
|
1285
1281
|
def checkout(flag, opts = [], branch: nil, origin: nil, create: nil, commit: nil, detach: nil, merge: false)
|
|
1286
1282
|
cmd, opts = git_session('checkout', opts: opts)
|
|
1287
|
-
append_option '
|
|
1283
|
+
append_option 'f', 'force', 'merge'
|
|
1288
1284
|
case flag
|
|
1289
1285
|
when :branch
|
|
1290
1286
|
cmd << '--detach' if detach == 'd' || option('detach')
|
|
@@ -1297,13 +1293,13 @@ module Squared
|
|
|
1297
1293
|
cmd << '-m' if merge
|
|
1298
1294
|
cmd << '--detach' << commit
|
|
1299
1295
|
else
|
|
1300
|
-
|
|
1301
|
-
|
|
1296
|
+
list = OPT_GIT[:checkout] + OPT_GIT[:log][:diff_context]
|
|
1297
|
+
op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GIT[:no][:checkout],
|
|
1298
|
+
first: (matchpathspec if flag == :path))
|
|
1302
1299
|
if flag == :path
|
|
1303
1300
|
append_head
|
|
1304
1301
|
append_pathspec(op.extras, pass: false)
|
|
1305
|
-
|
|
1306
|
-
return
|
|
1302
|
+
return success?(source)
|
|
1307
1303
|
end
|
|
1308
1304
|
op.append(commit)
|
|
1309
1305
|
.clear(pass: false)
|
|
@@ -1320,7 +1316,7 @@ module Squared
|
|
|
1320
1316
|
elsif !session_arg?('s', 'sign', 'u', 'local-user')
|
|
1321
1317
|
cmd << '--annotate'
|
|
1322
1318
|
end
|
|
1323
|
-
cmd << '--force' if option('
|
|
1319
|
+
cmd << '--force' if option('f', 'force')
|
|
1324
1320
|
if !commit && message && (sha = commithash(message))
|
|
1325
1321
|
commit = sha
|
|
1326
1322
|
message = nil
|
|
@@ -1339,9 +1335,12 @@ module Squared
|
|
|
1339
1335
|
list_result(ret, 'tags', from: from, grep: op.extras)
|
|
1340
1336
|
return
|
|
1341
1337
|
end
|
|
1342
|
-
remote ||= option
|
|
1343
|
-
source
|
|
1344
|
-
|
|
1338
|
+
remote ||= option('remote')
|
|
1339
|
+
source.tap do |ret|
|
|
1340
|
+
next unless ret && remote
|
|
1341
|
+
|
|
1342
|
+
git_spawn('push', ('-d' if flag == :delete), remote, *refs.map! { |val| shell_quote(val) })
|
|
1343
|
+
end
|
|
1345
1344
|
end
|
|
1346
1345
|
|
|
1347
1346
|
def log!(flag, opts = [], range: [], index: [])
|
|
@@ -1362,9 +1361,11 @@ module Squared
|
|
|
1362
1361
|
|
|
1363
1362
|
def diff(flag, opts = [], refs: [], branch: nil, range: [], index: [])
|
|
1364
1363
|
cmd, opts = git_session('diff', opts: opts)
|
|
1365
|
-
op = OptionPartition.new(opts,
|
|
1364
|
+
op = OptionPartition.new(opts,
|
|
1365
|
+
collect_hash(OPT_GIT[:diff]) + OPT_GIT[:log][:diff] + OPT_GIT[:log][:diff_context],
|
|
1366
|
+
cmd,
|
|
1366
1367
|
project: self, no: OPT_GIT[:no][:log][:diff],
|
|
1367
|
-
first: flag == :files
|
|
1368
|
+
first: (matchpathspec unless flag == :files))
|
|
1368
1369
|
case flag
|
|
1369
1370
|
when :files, :view, :between, :contain
|
|
1370
1371
|
op.delete('--cached')
|
|
@@ -1372,7 +1373,16 @@ module Squared
|
|
|
1372
1373
|
append_nocolor
|
|
1373
1374
|
if flag == :files
|
|
1374
1375
|
op << '--no-index'
|
|
1376
|
+
patch = refs.pop
|
|
1375
1377
|
append_pathspec(refs, parent: true)
|
|
1378
|
+
if patch
|
|
1379
|
+
patch = basepath patch
|
|
1380
|
+
exit 1 if patch.exist? && !confirm_basic('Overwrite?', patch)
|
|
1381
|
+
op << '>' << shell_quote(patch)
|
|
1382
|
+
source(banner: false)
|
|
1383
|
+
puts patch.read if patch.exist? && (stdin? || verbose?)
|
|
1384
|
+
return
|
|
1385
|
+
end
|
|
1376
1386
|
else
|
|
1377
1387
|
op << '--merge-base' if option('merge-base')
|
|
1378
1388
|
case flag
|
|
@@ -1385,7 +1395,7 @@ module Squared
|
|
|
1385
1395
|
op.add_quote(branch) if branch
|
|
1386
1396
|
if !index.empty?
|
|
1387
1397
|
if op.arg?('cached')
|
|
1388
|
-
raise_error
|
|
1398
|
+
raise_error "single commit: #{index.join(', ')}", hint: 'cached' unless index.size == 1
|
|
1389
1399
|
op << index.first
|
|
1390
1400
|
else
|
|
1391
1401
|
op.merge(index)
|
|
@@ -1401,7 +1411,7 @@ module Squared
|
|
|
1401
1411
|
|
|
1402
1412
|
def commit(flag, opts = [], refs: [], ref: nil, squash: nil, pick: nil, message: nil, pass: false)
|
|
1403
1413
|
fixup = flag == :fixup
|
|
1404
|
-
amend =
|
|
1414
|
+
amend = flag.match?(/^amend/) && !fixup
|
|
1405
1415
|
unless flag == :add || pick == 'reword'
|
|
1406
1416
|
pathspec = if flag == :all || ((fixup || amend) && refs.size == 1 && refs.first == '*')
|
|
1407
1417
|
'--all'
|
|
@@ -1412,9 +1422,9 @@ module Squared
|
|
|
1412
1422
|
end
|
|
1413
1423
|
end
|
|
1414
1424
|
if fixup
|
|
1415
|
-
source
|
|
1416
|
-
source git_output('rebase --autosquash', squash) if squash.is_a?(String)
|
|
1417
|
-
return
|
|
1425
|
+
ret = source(git_session('commit', basic_option('fixup', pick ? "#{pick}:#{ref}" : ref), pathspec))
|
|
1426
|
+
source git_output('rebase --autosquash', squash) if ret && squash.is_a?(String)
|
|
1427
|
+
return ret
|
|
1418
1428
|
end
|
|
1419
1429
|
message ||= messageopt
|
|
1420
1430
|
if !message && !amend
|
|
@@ -1426,7 +1436,8 @@ module Squared
|
|
|
1426
1436
|
origin = nil
|
|
1427
1437
|
upstream = nil
|
|
1428
1438
|
cmd, opts = git_session('add', opts: opts)
|
|
1429
|
-
op = OptionPartition.new(opts, OPT_GIT[:add]
|
|
1439
|
+
op = OptionPartition.new(opts, OPT_GIT[:add] + OPT_GIT[:log][:diff_context], cmd,
|
|
1440
|
+
project: self, no: OPT_GIT[:no][:add], first: matchpathspec)
|
|
1430
1441
|
op << '--verbose' if verbose
|
|
1431
1442
|
format = '%(if)%(HEAD)%(then)%(refname:short)...%(upstream:short)...%(upstream:track)%(end)'
|
|
1432
1443
|
git_spawn 'fetch --no-tags --quiet'
|
|
@@ -1435,10 +1446,9 @@ module Squared
|
|
|
1435
1446
|
|
|
1436
1447
|
branch, origin, hint = line.split('...')
|
|
1437
1448
|
if hint && !hint.match?(/^\[(\D+0,\D+0)\]$/)
|
|
1438
|
-
raise_error
|
|
1439
|
-
elsif !origin || origin.empty?
|
|
1449
|
+
raise_error 'work tree is not usable', hint: hint[1..-2]
|
|
1450
|
+
elsif (!origin || origin.empty?) && !dryrun?
|
|
1440
1451
|
return nil if pass
|
|
1441
|
-
break if dryrun?
|
|
1442
1452
|
|
|
1443
1453
|
unless (origin = option('upstream', prefix: 'git', ignore: false))
|
|
1444
1454
|
if (origin = choice_refs('Choose an upstream', 'remotes', attempts: 1, force: false))
|
|
@@ -1447,6 +1457,7 @@ module Squared
|
|
|
1447
1457
|
end
|
|
1448
1458
|
origin = readline('Enter an upstream', force: true)
|
|
1449
1459
|
end
|
|
1460
|
+
raise_error ArgumentError, 'missing remote name', hint: origin unless origin.include?('/')
|
|
1450
1461
|
upstream = true
|
|
1451
1462
|
end
|
|
1452
1463
|
break
|
|
@@ -1481,10 +1492,13 @@ module Squared
|
|
|
1481
1492
|
end
|
|
1482
1493
|
source co
|
|
1483
1494
|
source pu
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1495
|
+
else
|
|
1496
|
+
if banner?
|
|
1497
|
+
puts 'Nothing to commit'
|
|
1498
|
+
elsif stdout?
|
|
1499
|
+
puts log_message(Logger::INFO, name, 'nothing to commit', hint: flag)
|
|
1500
|
+
end
|
|
1501
|
+
exit 1
|
|
1488
1502
|
end
|
|
1489
1503
|
end
|
|
1490
1504
|
|
|
@@ -1499,20 +1513,20 @@ module Squared
|
|
|
1499
1513
|
op << branch
|
|
1500
1514
|
op.clear(pass: false)
|
|
1501
1515
|
else
|
|
1502
|
-
raise_error 'no branch/commit' if op.empty?
|
|
1516
|
+
raise_error ArgumentError, 'no branch/commit' if op.empty?
|
|
1503
1517
|
append_commit(*op.extras)
|
|
1504
1518
|
end
|
|
1505
1519
|
else
|
|
1506
1520
|
unless gitpath('MERGE_HEAD').exist?
|
|
1507
1521
|
puts log_message(Logger::INFO, name, 'no merge in progress', hint: command) if stdout?
|
|
1508
|
-
|
|
1522
|
+
exit 1
|
|
1509
1523
|
end
|
|
1510
1524
|
return unless VAL_GIT[:merge][:send].include?(command)
|
|
1511
1525
|
|
|
1512
1526
|
cmd << "--#{command}"
|
|
1513
1527
|
display = command == 'abort'
|
|
1514
1528
|
end
|
|
1515
|
-
|
|
1529
|
+
success?(source, display)
|
|
1516
1530
|
end
|
|
1517
1531
|
|
|
1518
1532
|
def branch(flag = nil, opts = [], refs: [], ref: nil, target: nil, remote: nil)
|
|
@@ -1530,11 +1544,11 @@ module Squared
|
|
|
1530
1544
|
'--track'
|
|
1531
1545
|
end
|
|
1532
1546
|
end
|
|
1533
|
-
cmd << '--force' if option('
|
|
1547
|
+
cmd << '--force' if option('f', 'force')
|
|
1534
1548
|
cmd << shell_quote(target)
|
|
1535
1549
|
cmd << shell_quote(ref) if ref
|
|
1536
1550
|
when :track
|
|
1537
|
-
raise_error
|
|
1551
|
+
raise_error 'invalid upstream', hint: ref unless ref.include?('/')
|
|
1538
1552
|
if ref.delete_prefix!('^')
|
|
1539
1553
|
cmd << '--unset-upstream' << shell_quote(ref)
|
|
1540
1554
|
remote = false
|
|
@@ -1545,7 +1559,7 @@ module Squared
|
|
|
1545
1559
|
end
|
|
1546
1560
|
when :delete
|
|
1547
1561
|
remote&.each do |val|
|
|
1548
|
-
source git_output('push --delete', *val.split('/', 2).map { |s| shell_quote(s) })
|
|
1562
|
+
source git_output('push --delete', *val.split('/', 2).map! { |s| shell_quote(s) })
|
|
1549
1563
|
end
|
|
1550
1564
|
force, list = refs.partition { |val| val.start_with?(/[~^]/) }
|
|
1551
1565
|
force.each do |val|
|
|
@@ -1559,13 +1573,13 @@ module Squared
|
|
|
1559
1573
|
remote = nil
|
|
1560
1574
|
when :move, :copy
|
|
1561
1575
|
s = +"-#{flag.to_s[0]}"
|
|
1562
|
-
s.upcase! if option('
|
|
1576
|
+
s.upcase! if option('f', 'force')
|
|
1563
1577
|
cmd << s
|
|
1564
1578
|
refs.compact.each { |val| cmd << shell_quote(val) }
|
|
1565
1579
|
stdout = true
|
|
1566
1580
|
when :current
|
|
1567
1581
|
cmd << '--show-current'
|
|
1568
|
-
source(banner:
|
|
1582
|
+
source(banner: verbose?, stdout: true)
|
|
1569
1583
|
return
|
|
1570
1584
|
when :list
|
|
1571
1585
|
op = OptionPartition.new(opts, OPT_GIT[:branch], cmd << '--list',
|
|
@@ -1574,8 +1588,8 @@ module Squared
|
|
|
1574
1588
|
out, banner, from = source(io: true)
|
|
1575
1589
|
print_item banner
|
|
1576
1590
|
ret = write_lines(out, sub: [
|
|
1577
|
-
|
|
1578
|
-
|
|
1591
|
+
opt_style(color(:green), /^(\*\s+)(\S+)(.*)$/, 2),
|
|
1592
|
+
opt_style(color(:red), %r{^(\s*)(remotes/\S+)(.*)$}, 2)
|
|
1579
1593
|
])
|
|
1580
1594
|
list_result(ret, 'branches', from: from)
|
|
1581
1595
|
return
|
|
@@ -1600,7 +1614,7 @@ module Squared
|
|
|
1600
1614
|
r3 = write.call($4, $5)
|
|
1601
1615
|
end
|
|
1602
1616
|
r1 = nil if r1 == "origin/#{data[0]}"
|
|
1603
|
-
[" Branch: #{a
|
|
1617
|
+
[" Branch: #{a.subhint(r1)}", r2, r3, " Commit: #{b}", "Message: #{r[2]}"]
|
|
1604
1618
|
.compact
|
|
1605
1619
|
.join("\n")
|
|
1606
1620
|
end
|
|
@@ -1609,21 +1623,17 @@ module Squared
|
|
|
1609
1623
|
print_error(name, 'no ref found', subject: 'branch', hint: 'head', pass: true) if ret == 0
|
|
1610
1624
|
return
|
|
1611
1625
|
end
|
|
1612
|
-
return unless success?(source(stdout: stdout))
|
|
1626
|
+
return unless success?(source(stdout: stdout), !ref && flag == :create) && !ref && remote && target
|
|
1613
1627
|
|
|
1614
|
-
|
|
1615
|
-
print_success if flag == :create
|
|
1616
|
-
elsif remote && target
|
|
1617
|
-
source git_output('push -u', shell_quote(ref.split('/', 2).first), shell_quote(target))
|
|
1618
|
-
end
|
|
1628
|
+
source git_output('push -u', shell_quote(ref.split('/', 2).first), shell_quote(target))
|
|
1619
1629
|
end
|
|
1620
1630
|
|
|
1621
1631
|
def switch(flag, opts = [], branch: nil, commit: nil, track: nil)
|
|
1622
1632
|
cmd, opts = git_session('switch', opts: opts)
|
|
1623
|
-
cmd << '--force' if option('
|
|
1633
|
+
cmd << '--force' if option('f', 'force')
|
|
1624
1634
|
if flag == :branch
|
|
1625
|
-
|
|
1626
|
-
|
|
1635
|
+
OptionPartition.new(opts, OPT_GIT[:switch], cmd, project: self, no: OPT_GIT[:no][:switch])
|
|
1636
|
+
.add_quote(branch)
|
|
1627
1637
|
else
|
|
1628
1638
|
case flag
|
|
1629
1639
|
when :create
|
|
@@ -1653,16 +1663,18 @@ module Squared
|
|
|
1653
1663
|
op.add_quote(branch, '--', path, url)
|
|
1654
1664
|
else
|
|
1655
1665
|
op.adjoin(flag)
|
|
1656
|
-
op << '--recursive' if option('
|
|
1666
|
+
op << '--recursive' if option('r', 'recursive')
|
|
1657
1667
|
op.splice(path: true)
|
|
1658
1668
|
end
|
|
1659
|
-
|
|
1669
|
+
source.tap { |ret| success?(ret, flag == :branch) }
|
|
1660
1670
|
end
|
|
1661
1671
|
|
|
1662
1672
|
def restore(flag, opts = [], commit: nil, files: nil)
|
|
1663
1673
|
cmd, opts = git_session('restore', shell_option(flag, commit, escape: false, force: false), opts: opts)
|
|
1664
|
-
op = OptionPartition.new(opts,
|
|
1665
|
-
|
|
1674
|
+
op = OptionPartition.new(opts,
|
|
1675
|
+
OPT_GIT[:restore] + OPT_GIT[:log][:diff_context],
|
|
1676
|
+
cmd,
|
|
1677
|
+
project: self, no: OPT_GIT[:no][:restore], first: matchpathspec)
|
|
1666
1678
|
append_pathspec(op.extras + (files || []), pass: false)
|
|
1667
1679
|
source(sync: false, stderr: true)
|
|
1668
1680
|
end
|
|
@@ -1688,9 +1700,9 @@ module Squared
|
|
|
1688
1700
|
else
|
|
1689
1701
|
opts << format if format
|
|
1690
1702
|
end
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1703
|
+
list = OPT_GIT[:show] + OPT_GIT[:diff][:show] + OPT_GIT[:log][:diff] + OPT_GIT[:log][:diff_context]
|
|
1704
|
+
op = OptionPartition.new(opts, list, cmd, project: self, pass: [:base],
|
|
1705
|
+
no: OPT_GIT[:no][:show] + collect_hash(OPT_GIT[:no][:log]))
|
|
1694
1706
|
op.append(delim: true)
|
|
1695
1707
|
source(exception: false, banner: flag != :oneline)
|
|
1696
1708
|
end
|
|
@@ -1709,15 +1721,14 @@ module Squared
|
|
|
1709
1721
|
cmd << '--sq-quote'
|
|
1710
1722
|
args = true
|
|
1711
1723
|
end
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
op.append(escape: args)
|
|
1724
|
+
OptionPartition.new(opts, OPT_GIT[:rev_parse], cmd, project: self, no: OPT_GIT[:no][:rev_parse], args: args)
|
|
1725
|
+
.append(escape: args)
|
|
1715
1726
|
end
|
|
1716
|
-
source(banner:
|
|
1727
|
+
source(banner: verbose?)
|
|
1717
1728
|
end
|
|
1718
1729
|
|
|
1719
1730
|
def ls_remote(flag, opts = [], remote: nil)
|
|
1720
|
-
cmd, opts = git_session('ls-remote
|
|
1731
|
+
cmd, opts = git_session('ls-remote --refs', opts: opts)
|
|
1721
1732
|
cmd << "--#{flag}" unless flag == :remote
|
|
1722
1733
|
op = OptionPartition.new(opts, OPT_GIT[:ls_remote], cmd, project: self)
|
|
1723
1734
|
op.add_quote(remote) if remote
|
|
@@ -1728,7 +1739,7 @@ module Squared
|
|
|
1728
1739
|
end
|
|
1729
1740
|
|
|
1730
1741
|
def ls_files(flag, opts = [])
|
|
1731
|
-
cmd, opts = git_session(
|
|
1742
|
+
cmd, opts = git_session("ls-files --#{flag}", opts: opts)
|
|
1732
1743
|
op = OptionPartition.new(opts, OPT_GIT[:ls_files], cmd, project: self)
|
|
1733
1744
|
op.splice(path: true, pattern: true)
|
|
1734
1745
|
out, banner, from = source(io: true)
|
|
@@ -1739,29 +1750,30 @@ module Squared
|
|
|
1739
1750
|
|
|
1740
1751
|
def git(flag, opts = [])
|
|
1741
1752
|
cmd, opts = git_session(flag, opts: opts)
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1753
|
+
list = OPT_GIT[:git].fetch(flag, []) + OPT_GIT.fetch(flag, [])
|
|
1754
|
+
list.concat(OPT_GIT[:log][:diff_context]) if flag == :add
|
|
1755
|
+
op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GIT[:no][flag], single: /\A\d+\z/,
|
|
1756
|
+
first: case flag
|
|
1757
|
+
when :blame, :revert then nil
|
|
1758
|
+
else matchpathspec
|
|
1759
|
+
end)
|
|
1748
1760
|
case flag
|
|
1749
1761
|
when :blame
|
|
1750
|
-
raise_error 'no file
|
|
1751
|
-
op
|
|
1752
|
-
|
|
1762
|
+
raise_error Errno::ENOENT, 'no file target' unless (n = op.index { |s| basepath(s).file? })
|
|
1763
|
+
op.append(basepath(op.remove_at(n)), delim: true)
|
|
1764
|
+
.clear
|
|
1753
1765
|
when :revert
|
|
1754
1766
|
if VAL_GIT[:rebase][:send].any? { |val| op.arg?(val) }
|
|
1755
1767
|
op.clear
|
|
1756
1768
|
elsif op.empty?
|
|
1757
|
-
raise_error 'no commit
|
|
1769
|
+
raise_error 'no commit target'
|
|
1758
1770
|
else
|
|
1759
1771
|
append_commit(*op.extras)
|
|
1760
1772
|
end
|
|
1761
1773
|
when :add
|
|
1762
1774
|
if flag == :add && !op.arg?('pathspec-from-file')
|
|
1763
|
-
grep,
|
|
1764
|
-
unless grep.empty? && !
|
|
1775
|
+
grep, pathspec = op.partition { |val| OptionPartition.pattern?(val) }
|
|
1776
|
+
unless grep.empty? && !pathspec.empty?
|
|
1765
1777
|
grep.map! { |val| Regexp.new(val[1..-2]) }
|
|
1766
1778
|
files = [].tap do |out|
|
|
1767
1779
|
status_data.each do |a, b|
|
|
@@ -1772,23 +1784,37 @@ module Squared
|
|
|
1772
1784
|
end
|
|
1773
1785
|
unless files.empty?
|
|
1774
1786
|
files = choice_index('Select files', files, multiple: true, force: true, trim: /^\S+\s/,
|
|
1775
|
-
accept: [
|
|
1787
|
+
accept: [accept_y('Add?')])
|
|
1776
1788
|
end
|
|
1777
|
-
op.swap(
|
|
1789
|
+
op.swap(pathspec + files)
|
|
1778
1790
|
end
|
|
1779
1791
|
end
|
|
1780
1792
|
return source(git_session('status -s'), banner: false) unless append_pathspec(op.extras)
|
|
1781
|
-
|
|
1782
|
-
print_success if success?(source, flag == :add && !op.arg?('verbose'))
|
|
1783
|
-
return
|
|
1793
|
+
return success?(source) if flag == :add && !op.arg?('verbose')
|
|
1784
1794
|
when :mv
|
|
1785
1795
|
refs = projectmap op.extras
|
|
1786
1796
|
raise_error 'no source/destination' unless refs.size > 1
|
|
1787
1797
|
op.merge(refs)
|
|
1788
1798
|
when :rm, :clean
|
|
1789
1799
|
append_pathspec(op.extras, expect: flag == :rm)
|
|
1800
|
+
when :grep
|
|
1801
|
+
op.each do |val|
|
|
1802
|
+
if op.include?('--')
|
|
1803
|
+
op.add_path(val)
|
|
1804
|
+
elsif op.exist?(val, glob: true)
|
|
1805
|
+
op << '--'
|
|
1806
|
+
op.add_path(val)
|
|
1807
|
+
else
|
|
1808
|
+
op.add_quote(val)
|
|
1809
|
+
end
|
|
1810
|
+
end
|
|
1811
|
+
end
|
|
1812
|
+
case flag
|
|
1813
|
+
when :revert, :mv, :rm
|
|
1814
|
+
source(sync: false, stderr: true)
|
|
1815
|
+
else
|
|
1816
|
+
source
|
|
1790
1817
|
end
|
|
1791
|
-
source(sync: false, stderr: true)
|
|
1792
1818
|
end
|
|
1793
1819
|
|
|
1794
1820
|
def clone?
|
|
@@ -1816,20 +1842,15 @@ module Squared
|
|
|
1816
1842
|
banner = nil unless banner? && !multiple
|
|
1817
1843
|
args = true
|
|
1818
1844
|
end
|
|
1819
|
-
if cmd.
|
|
1820
|
-
|
|
1821
|
-
from = :"git:#{from}"
|
|
1822
|
-
end
|
|
1823
|
-
banner &&= cmd.temp { |val| val.start_with?(/--(?:work-tree|git-dir)/) }
|
|
1845
|
+
if from.nil? && (from = cmd.drop(1).find { |val| val.match?(/\A[a-z]{1,2}[a-z-]*\z/) })
|
|
1846
|
+
from = :"git:#{from}"
|
|
1824
1847
|
end
|
|
1848
|
+
banner &&= cmd.temp { |val| val.start_with?(/--(?:work-tree|git-dir)/) } if cmd.respond_to?(:temp)
|
|
1825
1849
|
from = nil if from == false
|
|
1826
1850
|
end
|
|
1827
1851
|
cmd = session_done cmd
|
|
1828
1852
|
log&.info cmd
|
|
1829
|
-
banner = if banner
|
|
1830
|
-
banner = (banner.is_a?(String) ? banner : cmd).gsub(File.join(path, ''), '')
|
|
1831
|
-
format_banner(hint ? "#{banner} (#{hint})" : banner)
|
|
1832
|
-
end
|
|
1853
|
+
banner = format_banner(banner.is_a?(String) ? banner : cmd, hint: hint, strip: true) if banner
|
|
1833
1854
|
on :first, from
|
|
1834
1855
|
begin
|
|
1835
1856
|
if io
|
|
@@ -1839,10 +1860,12 @@ module Squared
|
|
|
1839
1860
|
elsif stdin? ? sync : stdout
|
|
1840
1861
|
print_item banner unless multiple
|
|
1841
1862
|
ret = `#{cmd}`
|
|
1842
|
-
|
|
1863
|
+
raise(ret.chomp.empty? ? $?.to_s : ret) unless $?.success?
|
|
1864
|
+
|
|
1865
|
+
if ret.empty?
|
|
1866
|
+
success?(nil, !banner.nil?)
|
|
1867
|
+
else
|
|
1843
1868
|
puts ret
|
|
1844
|
-
elsif success?(!banner.nil?)
|
|
1845
|
-
print_success
|
|
1846
1869
|
end
|
|
1847
1870
|
elsif !kwargs[:sub] && (sync || (!exception && !stderr))
|
|
1848
1871
|
print_item banner unless multiple
|
|
@@ -1854,7 +1877,7 @@ module Squared
|
|
|
1854
1877
|
n = write_lines(out, banner: banner, pass: true, **kwargs)
|
|
1855
1878
|
if n == 0
|
|
1856
1879
|
n = write_lines(err, banner: banner)
|
|
1857
|
-
|
|
1880
|
+
success?(nil, n == 0 && !banner.nil?)
|
|
1858
1881
|
else
|
|
1859
1882
|
write_lines(err, loglevel: Logger::DEBUG)
|
|
1860
1883
|
end
|
|
@@ -1873,17 +1896,14 @@ module Squared
|
|
|
1873
1896
|
end
|
|
1874
1897
|
|
|
1875
1898
|
def write_lines(data, grep: [], prefix: nil, sub: nil, banner: nil, loglevel: nil, pass: false, first: false)
|
|
1876
|
-
grep =
|
|
1877
|
-
sub =
|
|
1899
|
+
grep = (matchmap(grep, prefix) unless grep.empty?)
|
|
1900
|
+
sub = (as_a sub unless stdin?)
|
|
1878
1901
|
ret = 0
|
|
1879
1902
|
out = []
|
|
1880
1903
|
data.each do |line|
|
|
1881
1904
|
next if grep&.none? { |pat| pat.match?(line) }
|
|
1905
|
+
next if block_given? && !(line = yield line)
|
|
1882
1906
|
|
|
1883
|
-
if block_given?
|
|
1884
|
-
line = yield line
|
|
1885
|
-
next unless line
|
|
1886
|
-
end
|
|
1887
1907
|
if loglevel
|
|
1888
1908
|
log&.add loglevel, line
|
|
1889
1909
|
else
|
|
@@ -1908,7 +1928,7 @@ module Squared
|
|
|
1908
1928
|
styles = theme.fetch(:banner, []).reject { |s| s.to_s.end_with?('!') }
|
|
1909
1929
|
styles << :bold if styles.size <= 1
|
|
1910
1930
|
puts print_footer("#{size} #{size == 1 ? type.sub(/(?:(?<!l)e)?s\z/, '') : type}",
|
|
1911
|
-
sub:
|
|
1931
|
+
sub: opt_style(styles, /^(\d+)(.+)$/))
|
|
1912
1932
|
end
|
|
1913
1933
|
on :last, from
|
|
1914
1934
|
end
|
|
@@ -1967,7 +1987,7 @@ module Squared
|
|
|
1967
1987
|
end
|
|
1968
1988
|
|
|
1969
1989
|
def append_pull(opts, list, target: @session, flag: nil, no: nil, remote: nil, from: nil)
|
|
1970
|
-
target << '--force' if option('
|
|
1990
|
+
target << '--force' if option('f', 'force', target: target)
|
|
1971
1991
|
append_submodules(target: target, from: from)
|
|
1972
1992
|
return if !remote && opts.empty?
|
|
1973
1993
|
|
|
@@ -1979,6 +1999,7 @@ module Squared
|
|
|
1979
1999
|
when 'rebase'
|
|
1980
2000
|
op << basic_option($1, $2) if VAL_GIT[:rebase][:value].include?($2)
|
|
1981
2001
|
when 'shallow-since'
|
|
2002
|
+
require 'date'
|
|
1982
2003
|
op.append?($1) { Date.parse($2).strftime('%F %T') }
|
|
1983
2004
|
when 'recurse-submodules'
|
|
1984
2005
|
op.append?($1, $2, type: :basic)
|
|
@@ -2056,9 +2077,7 @@ module Squared
|
|
|
2056
2077
|
when '1', 'true'
|
|
2057
2078
|
target << '--recurse-submodules'
|
|
2058
2079
|
else
|
|
2059
|
-
projectmap(split_escape(val)).each
|
|
2060
|
-
target << basic_option('recurse-submodules', path)
|
|
2061
|
-
end
|
|
2080
|
+
projectmap(split_escape(val)).each { |path| target << basic_option('recurse-submodules', path) }
|
|
2062
2081
|
end
|
|
2063
2082
|
else
|
|
2064
2083
|
target << case val
|
|
@@ -2105,28 +2124,24 @@ module Squared
|
|
|
2105
2124
|
stdout: stdout, banner: banner, **kwargs)
|
|
2106
2125
|
end
|
|
2107
2126
|
|
|
2108
|
-
def dryrun?(*, target: @session,
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
target.include?('--dry-run') || !option('dry-run', target: target).nil?
|
|
2127
|
+
def dryrun?(*, target: @session, prefix: target&.first)
|
|
2128
|
+
Array(target).include?('--dry-run') || !option('dry-run', target: target, prefix: prefix).nil?
|
|
2112
2129
|
end
|
|
2113
2130
|
|
|
2114
2131
|
def quiet?(*, target: @session, **)
|
|
2115
2132
|
return false unless target
|
|
2116
2133
|
|
|
2117
|
-
target.include?('--quiet') || (target.include?('-q') &&
|
|
2134
|
+
target.include?('--quiet') || (target.include?('-q') && target.first.stripext == 'git')
|
|
2118
2135
|
end
|
|
2119
2136
|
|
|
2120
2137
|
def gitpath(*args)
|
|
2121
|
-
|
|
2138
|
+
basepath('.git', *args)
|
|
2122
2139
|
end
|
|
2123
2140
|
|
|
2124
2141
|
def repotrack(origin, branch, quote: true)
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
branch = "#{branch}:#{origin[(i + 1)..-1]}" unless origin.end_with?("/#{branch}")
|
|
2129
|
-
[origin[0..(i - 1)], branch].tap { |ret| ret.map! { |val| shell_quote(val) } if quote }
|
|
2142
|
+
i = origin.index('/')
|
|
2143
|
+
branch = "#{branch}:#{origin[i.succ..-1]}" unless origin.end_with?("/#{branch}")
|
|
2144
|
+
[origin[0..i.pred], branch].tap { |ret| ret.map! { |val| shell_quote(val) } if quote }
|
|
2130
2145
|
end
|
|
2131
2146
|
|
|
2132
2147
|
def commithash(val)
|