squared 0.5.23 → 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.
@@ -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
- uri = val.fetch(:uri, '')
46
- opts = val.fetch(:options, {})
47
- else
48
- uri = val.is_a?(String) ? val : key.to_s
49
- opts = options
50
- end
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 key
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
@@ -134,22 +139,10 @@ module Squared
134
139
  File.write(@revfile, JSON.pretty_generate(@revdoc))
135
140
  rescue StandardError => e
136
141
  log&.debug e
137
- warn log_message(Logger::WARN, e, pass: true) if warning
142
+ warn log_message(Logger::WARN, e, pass: true) if warning?
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|all e|edit f|force ignore-errors ignore-missing ignore-removal i|interactive no-all
163
- no-ignore-removal n|dry-run p|patch pathspec-file-nul renormalize sparse u|update v|verbose
164
- chmod=b pathspec-from-file=p].freeze,
165
- branch: %w[a|all create-reflog i|ignore-case omit-empty q|quiet r|remotes v|verbose abbrev=i color=b
166
- column=b contains=b format=q merged=b no-contains=b no-merged=b points-at=b u|set-upstream-to=b
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
- set-upstream unshallow update-shallow v|verbose deepen=i depth=i j|jobs=i negotiation-tip=q
179
- recurse-submodules=v refmap=q o|server-option=q shallow-exclude=b shallow-since=v
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
- contents=p date=q encoding=b ignore-rev=b ignore-revs-file=p reverse=q].freeze,
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 U=im binary check compact-summary cumulative
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? inter-hunk-context=i
215
- line-prefix=q output=p output-indicator-context=q output-indicator-new=q output-indicator-old=q
216
- relative=p rotate-to=p skip-to=p src-prefix=q stat=b? stat-count=i stat-width=i stat-name-width=i
217
- submodule=b? unified=i word-diff=b? word-diff-regex=q ws-error-highlight=b].freeze
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 gpg-sign=b?
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? s|strategy=b
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
- p|patch S|staged m|message=q pathspec-from-file=p].freeze,
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 = basepath('.gitmodules').exist?
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
- args = args.extras
394
- else
395
- remote = choice_remote
396
- args = args.to_a
397
- end
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' ? 'pattern*' : nil)
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 ? 'opts*' : nil)
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: [['Auto squash?', true]], reflog: false,
442
- values: ['Pick [amend|reword]'])
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?', series: true)
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(values: [['Enter tag name', true], 'Enter message'],
498
- series: true, reflog: false)
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
- ret = tag(flag, refs: [name], message: message, commit: commit, remote: remote)
502
- print_success if success?(ret, !remote)
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
- view = flag == :view
519
- if view && action == 'log'
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
- commit2 = commithead param_guard(action, flag, args: args, key: :commit2)
549
- args = args.extras
550
- range = [commit1, commit2]
551
- else
552
- range, opts, refs = choice_commit(multiple: view ? true : 2, values: %w[Options Pathspec])
553
- range = range.reverse
554
- args = OptionPartition.strip(opts)
555
- args.concat(refs.shellsplit) if refs
556
- end
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 { |val| index << (commithead(val) || commithash(val) || break) }
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?,detach?=d'
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
- detach = 'd'
598
- commit = nil
599
- elsif create == 'd'
600
- create = nil
601
- commit = nil
602
- detach = 'd'
603
- elsif create && create.size > 1
604
- commit = commithead create
605
- create = nil
606
- detach = args.commit
607
- else
608
- detach = args.detach
609
- commit = commithead args.commit
610
- end
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: ['Enter branch name'])
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: ['Options'])
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: ['Merge? [y/N]'])
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?=HEAD|:'
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
- ref, remote = choice_refs('Choose a remote', 'remotes', accept: [['Push?', true]]) if ref == ':'
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: [['Push?', true]],
673
- values: ['Enter branch name'])
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, '[^~]name*,:?'
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 << ['Force?', true] unless r
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?=HEAD|:'
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: ['Track? [Y/n]'], force: false) if commit == ':'
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?=HEAD'
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
- args = args.extras
739
- branch = nil if branch == ':'
740
- else
741
- args = []
742
- end
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
- args = args.extras
754
- else
755
- commit, mode = choice_commit(values: ['Mode [mixed|soft|hard|N]'])
756
- args = args.extras.concat(case mode&.downcase
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 ['mixed', 'N']
739
+ when 'n', 'N' then %w[mixed N]
760
740
  else ['mixed']
761
741
  end)
762
- end
763
- print_success if success?(reset(flag, args, commit: commit))
742
+ end
743
+ success?(reset(flag, args, commit: commit))
764
744
  end
765
745
  when :index, :undo
766
- format_desc(action, flag, flag == :index ? 'opts*,pathspec*' : nil)
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?=HEAD|:'
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?=HEAD|:,pathspec*'
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?=HEAD,opts*'
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: ['Options'])
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?=HEAD'
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: ['Options'])
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: ['Options'], accept: accept)
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?=HEAD,size?'
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
@@ -864,8 +844,6 @@ module Squared
864
844
  rev_parse(flag, ref: ref, size: size)
865
845
  end
866
846
  when :build
867
- next unless build?
868
-
869
847
  format_desc action, flag, 'opts*'
870
848
  task flag do |_, args|
871
849
  revbuild flag, args.to_a
@@ -883,7 +861,7 @@ module Squared
883
861
  ls_remote(flag, args.extras, remote: args.remote)
884
862
  end
885
863
  else
886
- format_desc(action, flag, 'opts*,pattern*', after: action == 'files' ? 'pathspec*' : nil)
864
+ format_desc(action, flag, 'opts*,pattern*', after: ('pathspec*' if action == 'files'))
887
865
  task flag do |_, args|
888
866
  __send__(action == 'refs' ? :ls_remote : :ls_files, flag, args.to_a)
889
867
  end
@@ -924,16 +902,22 @@ module Squared
924
902
  end
925
903
  when 'git'
926
904
  before = case flag
927
- when :blame then 'file'
928
- when :mv then 'source+,destination'
929
- when :revert then 'commit+'
905
+ when :blame
906
+ 'file'
907
+ when :mv
908
+ 'source+,destination'
909
+ when :revert
910
+ 'commit+'
930
911
  end
931
- format_desc(action, flag, 'opts*', before: before, after: case flag
932
- when :add
933
- 'pathspec*,pattern*'
934
- when :clean, :rm, :status
935
- 'pathspec*'
936
- end)
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)
937
921
  task flag do |_, args|
938
922
  __send__(flag == :status ? :status : :git, flag, args.to_a)
939
923
  end
@@ -984,8 +968,12 @@ module Squared
984
968
  printsucc
985
969
  end
986
970
  op = OptionPartition.new(opts, OPT_GIT[:pull], cmd, project: self, no: OPT_GIT[:no][:pull])
987
- opts -= op.extras
988
- reg = matchmap op
971
+ reg = if op.empty?
972
+ []
973
+ else
974
+ opts = op.uniq(opts)
975
+ matchmap op
976
+ end
989
977
  session_done op.target
990
978
  heads = []
991
979
  cur = nil
@@ -994,10 +982,10 @@ module Squared
994
982
  cur ||= line.delete_prefix!('* ')
995
983
  heads << line if matchany?(line, reg)
996
984
  end
997
- raise_error('head not found', hint: 'for-each-ref') unless cur
985
+ raise_error 'head not found', hint: 'for-each-ref' unless cur
998
986
  opts << 'ff-only' if opts.empty? && !option('ff-only', equals: '0')
999
- (heads.dup << cur).each_with_index do |branch, index|
1000
- next unless (index < heads.size && cur != branch) || index == heads.size
987
+ (heads.dup << cur).each_with_index do |branch, i|
988
+ next unless (i < heads.size && cur != branch) || i == heads.size
1001
989
 
1002
990
  git_spawn 'switch --quiet', force && '--force', shell_quote(branch)
1003
991
  pull(nil, opts, sync: false, hint: branch) if heads.include?(branch)
@@ -1011,8 +999,8 @@ module Squared
1011
999
  no: OPT_GIT[:no][:pull] + OPT_GIT[:no][:fetch][:pull], remote: remote, flag: flag, from: :pull)
1012
1000
  source(sync: sync, sub: if stdout?
1013
1001
  [
1014
- { pat: /^(.+)(\|\s+\d+\s+)([^-]*)(-+)(.*)$/, styles: color(:red), index: 4 },
1015
- { pat: /^(.+)(\|\s+\d+\s+)(\++)(.*)$/, styles: color(:green), index: 3 }
1002
+ opt_style(color(:red), /^(.+)(\|\s+\d+\s+)([^-]*)(-+)(.*)$/, 4),
1003
+ opt_style(color(:green), /^(.+)(\|\s+\d+\s+)(\++)(.*)$/, 3)
1016
1004
  ]
1017
1005
  end, hint: hint, **threadargs)
1018
1006
  end
@@ -1028,7 +1016,7 @@ module Squared
1028
1016
 
1029
1017
  op = OptionPartition.new(opts, OPT_GIT[:rebase], cmd, project: self, no: OPT_GIT[:no][:rebase])
1030
1018
  op << upstream
1031
- append_head op.shift
1019
+ append_head op.shift&.delete_prefix(':')
1032
1020
  op.clear(pass: false)
1033
1021
  when :onto
1034
1022
  return unless upstream
@@ -1040,13 +1028,13 @@ module Squared
1040
1028
  else
1041
1029
  unless gitpath('REBASE_HEAD').exist?
1042
1030
  puts log_message(Logger::INFO, name, 'no rebase in progress', hint: command) if stdout?
1043
- return
1031
+ exit 1
1044
1032
  end
1045
1033
  return unless VAL_GIT[:rebase][:send].include?(command)
1046
1034
 
1047
1035
  cmd << "--#{command}"
1048
1036
  end
1049
- source(sync: sync)
1037
+ source
1050
1038
  end
1051
1039
 
1052
1040
  def autostash(*, sync: invoked_sync?('autostash'), **)
@@ -1090,22 +1078,33 @@ module Squared
1090
1078
  append_hash opts
1091
1079
  cmd << '--quiet' unless verbose
1092
1080
  append_value(data[0], path, delim: true)
1093
- source(sync: sync, banner: sync && !quiet?, multiple: !sync || quiet?)
1081
+ source(banner: sync && !quiet?, multiple: !sync || quiet?)
1094
1082
  end
1095
1083
 
1096
1084
  def stash(flag = nil, opts = [], sync: invoked_sync?('stash', flag))
1097
1085
  if flag
1098
- if flag == :all
1086
+ case flag
1087
+ when :all
1099
1088
  opts << 'include-untracked'
1100
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
1101
1100
  end
1102
1101
  cmd, opts = git_session('stash', flag, opts: opts)
1103
1102
  list = OPT_GIT[:stash][:common] + OPT_GIT[:stash].fetch(flag, [])
1104
1103
  if flag == :list
1105
- list += collect_hash OPT_GIT[:log]
1104
+ list.concat(collect_hash(OPT_GIT[:log]))
1106
1105
  no = collect_hash OPT_GIT[:no][:log]
1107
1106
  end
1108
- op = OptionPartition.new(opts, list, cmd, project: self, no: no, first: flag == :push ? matchpathspec : nil)
1107
+ op = OptionPartition.new(opts, list, cmd, project: self, no: no, first: (matchpathspec if flag == :push))
1109
1108
  case flag
1110
1109
  when :push
1111
1110
  op.append?('message', readline('Enter message', force: true), force: true) if op.remove(':')
@@ -1116,24 +1115,26 @@ module Squared
1116
1115
  if op.empty?
1117
1116
  values = [['Branch name', true]]
1118
1117
  else
1119
- op << op.shift
1118
+ op.add_first(prefix: ':')
1120
1119
  end
1121
1120
  end
1122
1121
  out = choice_index('Choose a stash', git_spawn('stash list', stdout: false),
1123
- values: values, column: /^[^@]+@\{(\d+)\}/)
1122
+ values: values, column: /^[^@]+@\{(\d+)}/, force: true)
1124
1123
  if values
1125
1124
  op.merge(out.reverse)
1126
1125
  else
1127
1126
  op << out
1128
1127
  end
1129
1128
  elsif !op.empty?
1130
- op << op.shift
1129
+ op.add_first(prefix: ':')
1131
1130
  elsif flag == :branch
1132
- raise_error 'no branch name'
1131
+ raise_error ArgumentError, 'no branch name'
1133
1132
  end
1134
1133
  op.clear
1135
1134
  when :clear
1136
- source(stdout: true) if confirm("Remove #{sub_style('all', styles: theme[:active])} stash entries?", 'N')
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')
1137
1138
  return
1138
1139
  when :list
1139
1140
  op.clear
@@ -1177,13 +1178,13 @@ module Squared
1177
1178
  g = color(:green)
1178
1179
  sub = if session_arg?('short')
1179
1180
  [
1180
- { pat: /^(.)([A-Z?!])(.+)$/, styles: r, index: 2 },
1181
- { pat: /^([A-Z?!])(.+)$/, styles: g },
1182
- { pat: /^(\?\?)(.+)$/, styles: r },
1183
- { pat: /^(## )((?~\.{3}))(\.{3})(.+)$/, styles: [nil, g, nil, r], index: -1 }
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)
1184
1185
  ]
1185
1186
  else
1186
- [{ pat: /^(\t+)([a-z]+: +.+)$/, styles: r, index: 2 }]
1187
+ opt_style(r, /^(\t+)([a-z]+: +.+)$/, 2)
1187
1188
  end
1188
1189
  end
1189
1190
  out, banner, from = source(io: true)
@@ -1217,26 +1218,24 @@ module Squared
1217
1218
  op.clear(append: true)
1218
1219
  args = op.to_a
1219
1220
  else
1220
- args = []
1221
- option('untracked-files', prefix: 'git') { |val| args << basic_option('untracked-files', val) }
1222
- option('ignore-submodules', prefix: 'git') { |val| args << basic_option('ignore-submodules', val) }
1223
- option('ignored', prefix: 'git') { |val| args << basic_option('ignored', val) }
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
1224
1226
  end
1225
1227
  if (cur = workspace.rev_entry(name)) && cur['revision'] == sha && !env('REVBUILD_FORCE')
1226
1228
  files = status_digest(*args, **kwargs)
1227
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'))
1228
1231
  if stdout?
1229
- if (since = workspace.rev_timesince(name, 'build'))
1230
- puts log_message(Logger::INFO, name, 'no changes', subject: 'revbuild', hint: "#{since} ago")
1231
- else
1232
- workspace.rev_timeutc(name, 'build')
1233
- end
1232
+ puts log_message(Logger::INFO, name, 'no changes', subject: 'revbuild', hint: since && "#{since} ago")
1234
1233
  end
1235
1234
  return
1236
1235
  end
1237
1236
  end
1238
1237
  start = time_epoch
1239
- build(*@output, sync: sync, from: :'git:revbuild')
1238
+ build(@output, sync: sync, from: :'git:revbuild')
1240
1239
  rescue StandardError => e
1241
1240
  print_error(e, pass: true)
1242
1241
  else
@@ -1249,9 +1248,8 @@ module Squared
1249
1248
  cmd, opts = git_session('reset', opts: opts)
1250
1249
  case flag
1251
1250
  when :commit, :index
1252
- op = OptionPartition.new(opts, OPT_GIT[:reset] + VAL_GIT[:reset], cmd,
1253
- project: self, no: OPT_GIT[:no][:reset],
1254
- 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))
1255
1253
  if flag == :commit
1256
1254
  op.append(commit)
1257
1255
  .clear(pass: false)
@@ -1282,7 +1280,7 @@ module Squared
1282
1280
 
1283
1281
  def checkout(flag, opts = [], branch: nil, origin: nil, create: nil, commit: nil, detach: nil, merge: false)
1284
1282
  cmd, opts = git_session('checkout', opts: opts)
1285
- append_option 'force', 'f', 'merge'
1283
+ append_option 'f', 'force', 'merge'
1286
1284
  case flag
1287
1285
  when :branch
1288
1286
  cmd << '--detach' if detach == 'd' || option('detach')
@@ -1295,13 +1293,13 @@ module Squared
1295
1293
  cmd << '-m' if merge
1296
1294
  cmd << '--detach' << commit
1297
1295
  else
1298
- op = OptionPartition.new(opts, OPT_GIT[:checkout], cmd, project: self, no: OPT_GIT[:no][:checkout],
1299
- first: flag == :path ? matchpathspec : nil)
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))
1300
1299
  if flag == :path
1301
1300
  append_head
1302
1301
  append_pathspec(op.extras, pass: false)
1303
- print_success if success?(source)
1304
- return
1302
+ return success?(source)
1305
1303
  end
1306
1304
  op.append(commit)
1307
1305
  .clear(pass: false)
@@ -1318,7 +1316,7 @@ module Squared
1318
1316
  elsif !session_arg?('s', 'sign', 'u', 'local-user')
1319
1317
  cmd << '--annotate'
1320
1318
  end
1321
- cmd << '--force' if option('force', 'f')
1319
+ cmd << '--force' if option('f', 'force')
1322
1320
  if !commit && message && (sha = commithash(message))
1323
1321
  commit = sha
1324
1322
  message = nil
@@ -1337,9 +1335,12 @@ module Squared
1337
1335
  list_result(ret, 'tags', from: from, grep: op.extras)
1338
1336
  return
1339
1337
  end
1340
- remote ||= option 'remote'
1341
- source
1342
- git_spawn('push', flag == :delete ? '-d' : nil, remote, *refs.map { |val| shell_quote(val) }) if remote
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
1343
1344
  end
1344
1345
 
1345
1346
  def log!(flag, opts = [], range: [], index: [])
@@ -1360,9 +1361,11 @@ module Squared
1360
1361
 
1361
1362
  def diff(flag, opts = [], refs: [], branch: nil, range: [], index: [])
1362
1363
  cmd, opts = git_session('diff', opts: opts)
1363
- op = OptionPartition.new(opts, collect_hash(OPT_GIT[:diff]) + OPT_GIT[:log][:diff], cmd,
1364
+ op = OptionPartition.new(opts,
1365
+ collect_hash(OPT_GIT[:diff]) + OPT_GIT[:log][:diff] + OPT_GIT[:log][:diff_context],
1366
+ cmd,
1364
1367
  project: self, no: OPT_GIT[:no][:log][:diff],
1365
- first: flag == :files ? nil : matchpathspec)
1368
+ first: (matchpathspec unless flag == :files))
1366
1369
  case flag
1367
1370
  when :files, :view, :between, :contain
1368
1371
  op.delete('--cached')
@@ -1370,7 +1373,16 @@ module Squared
1370
1373
  append_nocolor
1371
1374
  if flag == :files
1372
1375
  op << '--no-index'
1376
+ patch = refs.pop
1373
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
1374
1386
  else
1375
1387
  op << '--merge-base' if option('merge-base')
1376
1388
  case flag
@@ -1383,7 +1395,7 @@ module Squared
1383
1395
  op.add_quote(branch) if branch
1384
1396
  if !index.empty?
1385
1397
  if op.arg?('cached')
1386
- raise_error("one commit only: #{index.join(', ')}", hint: 'cached') if index.size > 1
1398
+ raise_error "single commit: #{index.join(', ')}", hint: 'cached' unless index.size == 1
1387
1399
  op << index.first
1388
1400
  else
1389
1401
  op.merge(index)
@@ -1399,7 +1411,7 @@ module Squared
1399
1411
 
1400
1412
  def commit(flag, opts = [], refs: [], ref: nil, squash: nil, pick: nil, message: nil, pass: false)
1401
1413
  fixup = flag == :fixup
1402
- amend = !fixup && flag.to_s.start_with?('amend')
1414
+ amend = flag.match?(/^amend/) && !fixup
1403
1415
  unless flag == :add || pick == 'reword'
1404
1416
  pathspec = if flag == :all || ((fixup || amend) && refs.size == 1 && refs.first == '*')
1405
1417
  '--all'
@@ -1410,9 +1422,9 @@ module Squared
1410
1422
  end
1411
1423
  end
1412
1424
  if fixup
1413
- source git_session('commit', basic_option('fixup', "#{pick ? "#{pick}:" : ''}#{ref}"), pathspec)
1414
- source git_output('rebase --autosquash', squash) if squash.is_a?(String)
1415
- 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
1416
1428
  end
1417
1429
  message ||= messageopt
1418
1430
  if !message && !amend
@@ -1424,7 +1436,8 @@ module Squared
1424
1436
  origin = nil
1425
1437
  upstream = nil
1426
1438
  cmd, opts = git_session('add', opts: opts)
1427
- op = OptionPartition.new(opts, OPT_GIT[:add], cmd, project: self, first: matchpathspec)
1439
+ op = OptionPartition.new(opts, OPT_GIT[:add] + OPT_GIT[:log][:diff_context], cmd,
1440
+ project: self, no: OPT_GIT[:no][:add], first: matchpathspec)
1428
1441
  op << '--verbose' if verbose
1429
1442
  format = '%(if)%(HEAD)%(then)%(refname:short)...%(upstream:short)...%(upstream:track)%(end)'
1430
1443
  git_spawn 'fetch --no-tags --quiet'
@@ -1433,10 +1446,9 @@ module Squared
1433
1446
 
1434
1447
  branch, origin, hint = line.split('...')
1435
1448
  if hint && !hint.match?(/^\[(\D+0,\D+0)\]$/)
1436
- raise_error('work tree is not usable', hint: hint[1..-2])
1437
- elsif !origin || origin.empty?
1449
+ raise_error 'work tree is not usable', hint: hint[1..-2]
1450
+ elsif (!origin || origin.empty?) && !dryrun?
1438
1451
  return nil if pass
1439
- break if dryrun?
1440
1452
 
1441
1453
  unless (origin = option('upstream', prefix: 'git', ignore: false))
1442
1454
  if (origin = choice_refs('Choose an upstream', 'remotes', attempts: 1, force: false))
@@ -1445,6 +1457,7 @@ module Squared
1445
1457
  end
1446
1458
  origin = readline('Enter an upstream', force: true)
1447
1459
  end
1460
+ raise_error ArgumentError, 'missing remote name', hint: origin unless origin.include?('/')
1448
1461
  upstream = true
1449
1462
  end
1450
1463
  break
@@ -1455,14 +1468,13 @@ module Squared
1455
1468
  append_pathspec op.extras
1456
1469
  end
1457
1470
  co = git_session('commit', options: false)
1458
- pu = git_output 'push'
1459
- co << '--amend' if amend
1460
- pu << '--set-upstream' if upstream
1471
+ pu = git_output 'push', upstream && '--set-upstream'
1461
1472
  if dryrun?
1462
- op.adjoin('--dry-run')
1473
+ op.delete('--dry-run')
1463
1474
  co << '--dry-run'
1464
1475
  pu << '--dry-run'
1465
1476
  end
1477
+ co << '--amend' if amend
1466
1478
  if message
1467
1479
  append_message message
1468
1480
  elsif flag == :'amend-orig' || option('edit', equals: '0')
@@ -1470,6 +1482,7 @@ module Squared
1470
1482
  end
1471
1483
  pu << '--force-with-lease' if amend
1472
1484
  pu.merge(repotrack(origin, branch))
1485
+ puts if pass
1473
1486
  adding = git_spawn 'diff --name-only --no-color'
1474
1487
  source op
1475
1488
  cached = git_spawn 'diff --cached --name-only --no-color'
@@ -1479,10 +1492,13 @@ module Squared
1479
1492
  end
1480
1493
  source co
1481
1494
  source pu
1482
- elsif banner?
1483
- puts 'Nothing to commit'
1484
- elsif stdout?
1485
- puts log_message(Logger::INFO, name, 'nothing to commit', hint: flag)
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
1486
1502
  end
1487
1503
  end
1488
1504
 
@@ -1492,26 +1508,25 @@ module Squared
1492
1508
  case flag
1493
1509
  when :commit, :'no-commit'
1494
1510
  op = OptionPartition.new(opts, OPT_GIT[:merge], cmd, project: self, no: OPT_GIT[:no][:merge])
1495
- op << "--#{flag}"
1496
- op.delim
1511
+ op << "--#{flag}" << '--'
1497
1512
  if branch
1498
1513
  op << branch
1499
1514
  op.clear(pass: false)
1500
1515
  else
1501
- raise_error 'no branch/commit' if op.empty?
1516
+ raise_error ArgumentError, 'no branch/commit' if op.empty?
1502
1517
  append_commit(*op.extras)
1503
1518
  end
1504
1519
  else
1505
1520
  unless gitpath('MERGE_HEAD').exist?
1506
1521
  puts log_message(Logger::INFO, name, 'no merge in progress', hint: command) if stdout?
1507
- return
1522
+ exit 1
1508
1523
  end
1509
1524
  return unless VAL_GIT[:merge][:send].include?(command)
1510
1525
 
1511
1526
  cmd << "--#{command}"
1512
1527
  display = command == 'abort'
1513
1528
  end
1514
- print_success if success?(source, display)
1529
+ success?(source, display)
1515
1530
  end
1516
1531
 
1517
1532
  def branch(flag = nil, opts = [], refs: [], ref: nil, target: nil, remote: nil)
@@ -1529,11 +1544,11 @@ module Squared
1529
1544
  '--track'
1530
1545
  end
1531
1546
  end
1532
- cmd << '--force' if option('force', 'f')
1547
+ cmd << '--force' if option('f', 'force')
1533
1548
  cmd << shell_quote(target)
1534
1549
  cmd << shell_quote(ref) if ref
1535
1550
  when :track
1536
- raise_error('invalid upstream', hint: ref) unless ref.include?('/')
1551
+ raise_error 'invalid upstream', hint: ref unless ref.include?('/')
1537
1552
  if ref.delete_prefix!('^')
1538
1553
  cmd << '--unset-upstream' << shell_quote(ref)
1539
1554
  remote = false
@@ -1544,7 +1559,7 @@ module Squared
1544
1559
  end
1545
1560
  when :delete
1546
1561
  remote&.each do |val|
1547
- 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) })
1548
1563
  end
1549
1564
  force, list = refs.partition { |val| val.start_with?(/[~^]/) }
1550
1565
  force.each do |val|
@@ -1558,13 +1573,13 @@ module Squared
1558
1573
  remote = nil
1559
1574
  when :move, :copy
1560
1575
  s = +"-#{flag.to_s[0]}"
1561
- s.upcase! if option('force', 'f')
1576
+ s.upcase! if option('f', 'force')
1562
1577
  cmd << s
1563
1578
  refs.compact.each { |val| cmd << shell_quote(val) }
1564
1579
  stdout = true
1565
1580
  when :current
1566
1581
  cmd << '--show-current'
1567
- source(banner: verbosetype > 1, stdout: true)
1582
+ source(banner: verbose?, stdout: true)
1568
1583
  return
1569
1584
  when :list
1570
1585
  op = OptionPartition.new(opts, OPT_GIT[:branch], cmd << '--list',
@@ -1573,8 +1588,8 @@ module Squared
1573
1588
  out, banner, from = source(io: true)
1574
1589
  print_item banner
1575
1590
  ret = write_lines(out, sub: [
1576
- { pat: /^(\*\s+)(\S+)(.*)$/, styles: color(:green), index: 2 },
1577
- { pat: %r{^(\s*)(remotes/\S+)(.*)$}, styles: color(:red), index: 2 }
1591
+ opt_style(color(:green), /^(\*\s+)(\S+)(.*)$/, 2),
1592
+ opt_style(color(:red), %r{^(\s*)(remotes/\S+)(.*)$}, 2)
1578
1593
  ])
1579
1594
  list_result(ret, 'branches', from: from)
1580
1595
  return
@@ -1599,7 +1614,7 @@ module Squared
1599
1614
  r3 = write.call($4, $5)
1600
1615
  end
1601
1616
  r1 = nil if r1 == "origin/#{data[0]}"
1602
- [" Branch: #{a + (r1 ? " (#{r1})" : '')}", r2, r3, " Commit: #{b}", "Message: #{r[2]}"]
1617
+ [" Branch: #{a.subhint(r1)}", r2, r3, " Commit: #{b}", "Message: #{r[2]}"]
1603
1618
  .compact
1604
1619
  .join("\n")
1605
1620
  end
@@ -1608,21 +1623,17 @@ module Squared
1608
1623
  print_error(name, 'no ref found', subject: 'branch', hint: 'head', pass: true) if ret == 0
1609
1624
  return
1610
1625
  end
1611
- return unless success?(source(stdout: stdout))
1626
+ return unless success?(source(stdout: stdout), !ref && flag == :create) && !ref && remote && target
1612
1627
 
1613
- if !ref
1614
- print_success if flag == :create
1615
- elsif remote && target
1616
- source git_output('push -u', shell_quote(ref.split('/', 2).first), shell_quote(target))
1617
- end
1628
+ source git_output('push -u', shell_quote(ref.split('/', 2).first), shell_quote(target))
1618
1629
  end
1619
1630
 
1620
1631
  def switch(flag, opts = [], branch: nil, commit: nil, track: nil)
1621
1632
  cmd, opts = git_session('switch', opts: opts)
1622
- cmd << '--force' if option('force', 'f')
1633
+ cmd << '--force' if option('f', 'force')
1623
1634
  if flag == :branch
1624
- op = OptionPartition.new(opts, OPT_GIT[:switch], cmd, project: self, no: OPT_GIT[:no][:switch])
1625
- op.add_quote(branch)
1635
+ OptionPartition.new(opts, OPT_GIT[:switch], cmd, project: self, no: OPT_GIT[:no][:switch])
1636
+ .add_quote(branch)
1626
1637
  else
1627
1638
  case flag
1628
1639
  when :create
@@ -1652,16 +1663,18 @@ module Squared
1652
1663
  op.add_quote(branch, '--', path, url)
1653
1664
  else
1654
1665
  op.adjoin(flag)
1655
- op << '--recursive' if option('recursive', 'r')
1666
+ op << '--recursive' if option('r', 'recursive')
1656
1667
  op.splice(path: true)
1657
1668
  end
1658
- print_success if success?(source, flag == :branch)
1669
+ source.tap { |ret| success?(ret, flag == :branch) }
1659
1670
  end
1660
1671
 
1661
1672
  def restore(flag, opts = [], commit: nil, files: nil)
1662
1673
  cmd, opts = git_session('restore', shell_option(flag, commit, escape: false, force: false), opts: opts)
1663
- op = OptionPartition.new(opts, OPT_GIT[:restore], cmd, project: self, no: OPT_GIT[:no][:restore],
1664
- first: matchpathspec)
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)
1665
1678
  append_pathspec(op.extras + (files || []), pass: false)
1666
1679
  source(sync: false, stderr: true)
1667
1680
  end
@@ -1687,9 +1700,9 @@ module Squared
1687
1700
  else
1688
1701
  opts << format if format
1689
1702
  end
1690
- op = OptionPartition.new(opts, OPT_GIT[:show] + OPT_GIT[:diff][:show] + OPT_GIT[:log][:diff], cmd,
1691
- project: self,
1692
- no: OPT_GIT[:no][:show] + collect_hash(OPT_GIT[:no][:log], pass: [:base]))
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]))
1693
1706
  op.append(delim: true)
1694
1707
  source(exception: false, banner: flag != :oneline)
1695
1708
  end
@@ -1698,7 +1711,7 @@ module Squared
1698
1711
  cmd, opts = git_session('rev-parse', opts: opts)
1699
1712
  case flag
1700
1713
  when :commit
1701
- cmd << (size.to_i.zero? ? '--verify' : basic_option('short', [size.to_i, 5].max))
1714
+ cmd << ((n = size.to_i) > 0 ? basic_option('short', [n, 5].max) : '--verify')
1702
1715
  append_commit(ref, head: true)
1703
1716
  when :branch
1704
1717
  cmd << '--abbrev-ref'
@@ -1708,15 +1721,14 @@ module Squared
1708
1721
  cmd << '--sq-quote'
1709
1722
  args = true
1710
1723
  end
1711
- op = OptionPartition.new(opts, OPT_GIT[:rev_parse], cmd, project: self, no: OPT_GIT[:no][:rev_parse],
1712
- args: args)
1713
- 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)
1714
1726
  end
1715
- source(banner: verbosetype > 1)
1727
+ source(banner: verbose?)
1716
1728
  end
1717
1729
 
1718
1730
  def ls_remote(flag, opts = [], remote: nil)
1719
- cmd, opts = git_session('ls-remote', '--refs', opts: opts)
1731
+ cmd, opts = git_session('ls-remote --refs', opts: opts)
1720
1732
  cmd << "--#{flag}" unless flag == :remote
1721
1733
  op = OptionPartition.new(opts, OPT_GIT[:ls_remote], cmd, project: self)
1722
1734
  op.add_quote(remote) if remote
@@ -1727,7 +1739,7 @@ module Squared
1727
1739
  end
1728
1740
 
1729
1741
  def ls_files(flag, opts = [])
1730
- cmd, opts = git_session('ls-files', "--#{flag}", opts: opts)
1742
+ cmd, opts = git_session("ls-files --#{flag}", opts: opts)
1731
1743
  op = OptionPartition.new(opts, OPT_GIT[:ls_files], cmd, project: self)
1732
1744
  op.splice(path: true, pattern: true)
1733
1745
  out, banner, from = source(io: true)
@@ -1738,55 +1750,71 @@ module Squared
1738
1750
 
1739
1751
  def git(flag, opts = [])
1740
1752
  cmd, opts = git_session(flag, opts: opts)
1741
- op = OptionPartition.new(opts, OPT_GIT[:git].fetch(flag, []) + OPT_GIT.fetch(flag, []), cmd,
1742
- project: self, no: OPT_GIT[:no][flag], first: case flag
1743
- when :blame, :revert
1744
- nil
1745
- else matchpathspec
1746
- end)
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)
1747
1760
  case flag
1748
1761
  when :blame
1749
- raise_error 'no file found' unless (n = op.index { |s| basepath(s).file? })
1750
- op.delim << shell_quote(basepath(op.delete_at(n)))
1751
- op.clear
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
1752
1765
  when :revert
1753
1766
  if VAL_GIT[:rebase][:send].any? { |val| op.arg?(val) }
1754
1767
  op.clear
1755
1768
  elsif op.empty?
1756
- raise_error 'no commit given'
1769
+ raise_error 'no commit target'
1757
1770
  else
1758
1771
  append_commit(*op.extras)
1759
1772
  end
1760
1773
  when :add
1761
1774
  if flag == :add && !op.arg?('pathspec-from-file')
1762
- grep, list = op.partition { |val| OptionPartition.pattern?(val) }
1763
- unless grep.empty? && !list.empty?
1775
+ grep, pathspec = op.partition { |val| OptionPartition.pattern?(val) }
1776
+ unless grep.empty? && !pathspec.empty?
1764
1777
  grep.map! { |val| Regexp.new(val[1..-2]) }
1765
- files = []
1766
- status_data.each do |a, b|
1767
- next if b.strip.empty? || (!grep.empty? && grep.none? { |pat| pat.match?(a) })
1778
+ files = [].tap do |out|
1779
+ status_data.each do |a, b|
1780
+ next if b.strip.empty? || (!grep.empty? && grep.none? { |pat| pat.match?(a) })
1768
1781
 
1769
- files << "#{sub_style(b, styles: color(:red))} #{a}"
1782
+ out << "#{sub_style(b, styles: color(:red))} #{a}"
1783
+ end
1770
1784
  end
1771
1785
  unless files.empty?
1772
- files = choice_index('Select files', files, multiple: true, trim: /^\S+\s/,
1773
- accept: [['Add?', false, true]])
1786
+ files = choice_index('Select files', files, multiple: true, force: true, trim: /^\S+\s/,
1787
+ accept: [accept_y('Add?')])
1774
1788
  end
1775
- op.swap(list + files)
1789
+ op.swap(pathspec + files)
1776
1790
  end
1777
1791
  end
1778
1792
  return source(git_session('status -s'), banner: false) unless append_pathspec(op.extras)
1779
-
1780
- print_success if success?(source, flag == :add && !op.arg?('verbose'))
1781
- return
1793
+ return success?(source) if flag == :add && !op.arg?('verbose')
1782
1794
  when :mv
1783
1795
  refs = projectmap op.extras
1784
1796
  raise_error 'no source/destination' unless refs.size > 1
1785
1797
  op.merge(refs)
1786
1798
  when :rm, :clean
1787
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
1788
1817
  end
1789
- source(sync: false, stderr: true)
1790
1818
  end
1791
1819
 
1792
1820
  def clone?
@@ -1814,20 +1842,15 @@ module Squared
1814
1842
  banner = nil unless banner? && !multiple
1815
1843
  args = true
1816
1844
  end
1817
- if cmd.respond_to?(:done)
1818
- if from.nil? && (from = cmd.drop(1).find { |val| val.match?(/\A[a-z]{1,2}[a-z-]*\z/) })
1819
- from = :"git:#{from}"
1820
- end
1821
- 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}"
1822
1847
  end
1848
+ banner &&= cmd.temp { |val| val.start_with?(/--(?:work-tree|git-dir)/) } if cmd.respond_to?(:temp)
1823
1849
  from = nil if from == false
1824
1850
  end
1825
1851
  cmd = session_done cmd
1826
1852
  log&.info cmd
1827
- banner = if banner
1828
- banner = (banner.is_a?(String) ? banner : cmd).gsub(File.join(path, ''), '')
1829
- format_banner(hint ? "#{banner} (#{hint})" : banner)
1830
- end
1853
+ banner = format_banner(banner.is_a?(String) ? banner : cmd, hint: hint, strip: true) if banner
1831
1854
  on :first, from
1832
1855
  begin
1833
1856
  if io
@@ -1836,11 +1859,13 @@ module Squared
1836
1859
  return args ? [IO.popen(cmd), banner || '', from] : IO.popen(cmd)
1837
1860
  elsif stdin? ? sync : stdout
1838
1861
  print_item banner unless multiple
1839
- ret = `#{cmd}`.chomp
1840
- if !ret.empty?
1862
+ ret = `#{cmd}`
1863
+ raise(ret.chomp.empty? ? $?.to_s : ret) unless $?.success?
1864
+
1865
+ if ret.empty?
1866
+ success?(nil, !banner.nil?)
1867
+ else
1841
1868
  puts ret
1842
- elsif success?(!banner.nil?)
1843
- print_success
1844
1869
  end
1845
1870
  elsif !kwargs[:sub] && (sync || (!exception && !stderr))
1846
1871
  print_item banner unless multiple
@@ -1852,7 +1877,7 @@ module Squared
1852
1877
  n = write_lines(out, banner: banner, pass: true, **kwargs)
1853
1878
  if n == 0
1854
1879
  n = write_lines(err, banner: banner)
1855
- print_success if success?(n == 0 && !banner.nil?)
1880
+ success?(nil, n == 0 && !banner.nil?)
1856
1881
  else
1857
1882
  write_lines(err, loglevel: Logger::DEBUG)
1858
1883
  end
@@ -1871,17 +1896,14 @@ module Squared
1871
1896
  end
1872
1897
 
1873
1898
  def write_lines(data, grep: [], prefix: nil, sub: nil, banner: nil, loglevel: nil, pass: false, first: false)
1874
- grep = grep.empty? ? nil : matchmap(grep, prefix)
1875
- sub = nil if stdin?
1899
+ grep = (matchmap(grep, prefix) unless grep.empty?)
1900
+ sub = (as_a sub unless stdin?)
1876
1901
  ret = 0
1877
1902
  out = []
1878
1903
  data.each do |line|
1879
1904
  next if grep&.none? { |pat| pat.match?(line) }
1905
+ next if block_given? && !(line = yield line)
1880
1906
 
1881
- if block_given?
1882
- line = yield line
1883
- next unless line
1884
- end
1885
1907
  if loglevel
1886
1908
  log&.add loglevel, line
1887
1909
  else
@@ -1906,7 +1928,7 @@ module Squared
1906
1928
  styles = theme.fetch(:banner, []).reject { |s| s.to_s.end_with?('!') }
1907
1929
  styles << :bold if styles.size <= 1
1908
1930
  puts print_footer("#{size} #{size == 1 ? type.sub(/(?:(?<!l)e)?s\z/, '') : type}",
1909
- sub: [{ pat: /^(\d+)(.+)$/, styles: styles }])
1931
+ sub: opt_style(styles, /^(\d+)(.+)$/))
1910
1932
  end
1911
1933
  on :last, from
1912
1934
  end
@@ -1922,7 +1944,7 @@ module Squared
1922
1944
  end
1923
1945
  args = []
1924
1946
  args << quote_option('sort', sort) if sort
1925
- args << basic_option('count', env('GIT_COUNT', ARG[:CHOICE])) if count
1947
+ args << shell_option('count', env('GIT_COUNT', ARG[:CHOICE])) if count
1926
1948
  choice_index(msg, foreachref(type, *args, format: format), trim: trim, **kwargs)
1927
1949
  end
1928
1950
 
@@ -1955,17 +1977,17 @@ module Squared
1955
1977
  end
1956
1978
 
1957
1979
  def status_data(*args)
1958
- ret = []
1959
- git_spawn('status -z -uall', *args).split("\x0").each do |line|
1960
- next unless line =~ /^(.)(.) (.+)$/
1980
+ [].tap do |ret|
1981
+ git_spawn('status -z -uall', *args).split("\x0").each do |line|
1982
+ next unless line =~ /^(.)(.) (.+)$/
1961
1983
 
1962
- ret << [$3, $2, $1]
1984
+ ret << [$3, $2, $1]
1985
+ end
1963
1986
  end
1964
- ret
1965
1987
  end
1966
1988
 
1967
1989
  def append_pull(opts, list, target: @session, flag: nil, no: nil, remote: nil, from: nil)
1968
- target << '--force' if option('force', 'f', target: target)
1990
+ target << '--force' if option('f', 'force', target: target)
1969
1991
  append_submodules(target: target, from: from)
1970
1992
  return if !remote && opts.empty?
1971
1993
 
@@ -1977,6 +1999,7 @@ module Squared
1977
1999
  when 'rebase'
1978
2000
  op << basic_option($1, $2) if VAL_GIT[:rebase][:value].include?($2)
1979
2001
  when 'shallow-since'
2002
+ require 'date'
1980
2003
  op.append?($1) { Date.parse($2).strftime('%F %T') }
1981
2004
  when 'recurse-submodules'
1982
2005
  op.append?($1, $2, type: :basic)
@@ -2036,9 +2059,7 @@ module Squared
2036
2059
 
2037
2060
  def append_message(val = nil, target: @session)
2038
2061
  val = messageopt if val.to_s.empty?
2039
- return unless val
2040
-
2041
- target << quote_option('message', val)
2062
+ target << quote_option('message', val) if val
2042
2063
  end
2043
2064
 
2044
2065
  def append_head(val = nil, target: @session)
@@ -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 do |path|
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
- return false unless target
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') && stripext(target.first) == 'git')
2134
+ target.include?('--quiet') || (target.include?('-q') && target.first.stripext == 'git')
2118
2135
  end
2119
2136
 
2120
2137
  def gitpath(*args)
2121
- path.join('.git', *args)
2138
+ basepath('.git', *args)
2122
2139
  end
2123
2140
 
2124
2141
  def repotrack(origin, branch, quote: true)
2125
- unless origin && branch && (i = origin.index('/'))
2126
- raise_error(ArgumentError, "missing #{origin ? 'branch' : 'remote'} name", hint: origin)
2127
- end
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)