squared 0.5.19 → 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
@@ -998,10 +982,10 @@ module Squared
998
982
  cur ||= line.delete_prefix!('* ')
999
983
  heads << line if matchany?(line, reg)
1000
984
  end
1001
- raise_error('head not found', hint: 'for-each-ref') unless cur
985
+ raise_error 'head not found', hint: 'for-each-ref' unless cur
1002
986
  opts << 'ff-only' if opts.empty? && !option('ff-only', equals: '0')
1003
- (heads.dup << cur).each_with_index do |branch, index|
1004
- 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
1005
989
 
1006
990
  git_spawn 'switch --quiet', force && '--force', shell_quote(branch)
1007
991
  pull(nil, opts, sync: false, hint: branch) if heads.include?(branch)
@@ -1015,8 +999,8 @@ module Squared
1015
999
  no: OPT_GIT[:no][:pull] + OPT_GIT[:no][:fetch][:pull], remote: remote, flag: flag, from: :pull)
1016
1000
  source(sync: sync, sub: if stdout?
1017
1001
  [
1018
- { pat: /^(.+)(\|\s+\d+\s+)([^-]*)(-+)(.*)$/, styles: color(:red), index: 4 },
1019
- { 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)
1020
1004
  ]
1021
1005
  end, hint: hint, **threadargs)
1022
1006
  end
@@ -1032,7 +1016,7 @@ module Squared
1032
1016
 
1033
1017
  op = OptionPartition.new(opts, OPT_GIT[:rebase], cmd, project: self, no: OPT_GIT[:no][:rebase])
1034
1018
  op << upstream
1035
- append_head op.shift
1019
+ append_head op.shift&.delete_prefix(':')
1036
1020
  op.clear(pass: false)
1037
1021
  when :onto
1038
1022
  return unless upstream
@@ -1044,7 +1028,7 @@ module Squared
1044
1028
  else
1045
1029
  unless gitpath('REBASE_HEAD').exist?
1046
1030
  puts log_message(Logger::INFO, name, 'no rebase in progress', hint: command) if stdout?
1047
- return
1031
+ exit 1
1048
1032
  end
1049
1033
  return unless VAL_GIT[:rebase][:send].include?(command)
1050
1034
 
@@ -1099,17 +1083,28 @@ module Squared
1099
1083
 
1100
1084
  def stash(flag = nil, opts = [], sync: invoked_sync?('stash', flag))
1101
1085
  if flag
1102
- if flag == :all
1086
+ case flag
1087
+ when :all
1103
1088
  opts << 'include-untracked'
1104
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
1105
1100
  end
1106
1101
  cmd, opts = git_session('stash', flag, opts: opts)
1107
1102
  list = OPT_GIT[:stash][:common] + OPT_GIT[:stash].fetch(flag, [])
1108
1103
  if flag == :list
1109
- list += collect_hash OPT_GIT[:log]
1104
+ list.concat(collect_hash(OPT_GIT[:log]))
1110
1105
  no = collect_hash OPT_GIT[:no][:log]
1111
1106
  end
1112
- 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))
1113
1108
  case flag
1114
1109
  when :push
1115
1110
  op.append?('message', readline('Enter message', force: true), force: true) if op.remove(':')
@@ -1120,24 +1115,26 @@ module Squared
1120
1115
  if op.empty?
1121
1116
  values = [['Branch name', true]]
1122
1117
  else
1123
- op << op.shift
1118
+ op.add_first(prefix: ':')
1124
1119
  end
1125
1120
  end
1126
1121
  out = choice_index('Choose a stash', git_spawn('stash list', stdout: false),
1127
- values: values, column: /^[^@]+@\{(\d+)\}/)
1122
+ values: values, column: /^[^@]+@\{(\d+)}/, force: true)
1128
1123
  if values
1129
1124
  op.merge(out.reverse)
1130
1125
  else
1131
1126
  op << out
1132
1127
  end
1133
1128
  elsif !op.empty?
1134
- op << op.shift
1129
+ op.add_first(prefix: ':')
1135
1130
  elsif flag == :branch
1136
- raise_error 'no branch name'
1131
+ raise_error ArgumentError, 'no branch name'
1137
1132
  end
1138
1133
  op.clear
1139
1134
  when :clear
1140
- 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')
1141
1138
  return
1142
1139
  when :list
1143
1140
  op.clear
@@ -1181,13 +1178,13 @@ module Squared
1181
1178
  g = color(:green)
1182
1179
  sub = if session_arg?('short')
1183
1180
  [
1184
- { pat: /^(.)([A-Z?!])(.+)$/, styles: r, index: 2 },
1185
- { pat: /^([A-Z?!])(.+)$/, styles: g },
1186
- { pat: /^(\?\?)(.+)$/, styles: r },
1187
- { 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)
1188
1185
  ]
1189
1186
  else
1190
- [pat: /^(\t+)([a-z]+: +.+)$/, styles: r, index: 2]
1187
+ opt_style(r, /^(\t+)([a-z]+: +.+)$/, 2)
1191
1188
  end
1192
1189
  end
1193
1190
  out, banner, from = source(io: true)
@@ -1221,26 +1218,24 @@ module Squared
1221
1218
  op.clear(append: true)
1222
1219
  args = op.to_a
1223
1220
  else
1224
- args = []
1225
- option('untracked-files', prefix: 'git') { |val| args << basic_option('untracked-files', val) }
1226
- option('ignore-submodules', prefix: 'git') { |val| args << basic_option('ignore-submodules', val) }
1227
- 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
1228
1226
  end
1229
1227
  if (cur = workspace.rev_entry(name)) && cur['revision'] == sha && !env('REVBUILD_FORCE')
1230
1228
  files = status_digest(*args, **kwargs)
1231
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'))
1232
1231
  if stdout?
1233
- if (since = workspace.rev_timesince(name, 'build'))
1234
- puts log_message(Logger::INFO, name, 'no changes', subject: 'revbuild', hint: "#{since} ago")
1235
- else
1236
- workspace.rev_timeutc(name, 'build')
1237
- end
1232
+ puts log_message(Logger::INFO, name, 'no changes', subject: 'revbuild', hint: since && "#{since} ago")
1238
1233
  end
1239
1234
  return
1240
1235
  end
1241
1236
  end
1242
1237
  start = time_epoch
1243
- build(*@output, sync: sync, from: :'git:revbuild')
1238
+ build(@output, sync: sync, from: :'git:revbuild')
1244
1239
  rescue StandardError => e
1245
1240
  print_error(e, pass: true)
1246
1241
  else
@@ -1253,9 +1248,8 @@ module Squared
1253
1248
  cmd, opts = git_session('reset', opts: opts)
1254
1249
  case flag
1255
1250
  when :commit, :index
1256
- op = OptionPartition.new(opts, OPT_GIT[:reset] + VAL_GIT[:reset], cmd,
1257
- project: self, no: OPT_GIT[:no][:reset],
1258
- 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))
1259
1253
  if flag == :commit
1260
1254
  op.append(commit)
1261
1255
  .clear(pass: false)
@@ -1286,7 +1280,7 @@ module Squared
1286
1280
 
1287
1281
  def checkout(flag, opts = [], branch: nil, origin: nil, create: nil, commit: nil, detach: nil, merge: false)
1288
1282
  cmd, opts = git_session('checkout', opts: opts)
1289
- append_option 'force', 'f', 'merge'
1283
+ append_option 'f', 'force', 'merge'
1290
1284
  case flag
1291
1285
  when :branch
1292
1286
  cmd << '--detach' if detach == 'd' || option('detach')
@@ -1299,13 +1293,13 @@ module Squared
1299
1293
  cmd << '-m' if merge
1300
1294
  cmd << '--detach' << commit
1301
1295
  else
1302
- op = OptionPartition.new(opts, OPT_GIT[:checkout], cmd, project: self, no: OPT_GIT[:no][:checkout],
1303
- 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))
1304
1299
  if flag == :path
1305
1300
  append_head
1306
1301
  append_pathspec(op.extras, pass: false)
1307
- print_success if success?(source)
1308
- return
1302
+ return success?(source)
1309
1303
  end
1310
1304
  op.append(commit)
1311
1305
  .clear(pass: false)
@@ -1322,7 +1316,7 @@ module Squared
1322
1316
  elsif !session_arg?('s', 'sign', 'u', 'local-user')
1323
1317
  cmd << '--annotate'
1324
1318
  end
1325
- cmd << '--force' if option('force', 'f')
1319
+ cmd << '--force' if option('f', 'force')
1326
1320
  if !commit && message && (sha = commithash(message))
1327
1321
  commit = sha
1328
1322
  message = nil
@@ -1341,9 +1335,12 @@ module Squared
1341
1335
  list_result(ret, 'tags', from: from, grep: op.extras)
1342
1336
  return
1343
1337
  end
1344
- remote ||= option 'remote'
1345
- source
1346
- 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
1347
1344
  end
1348
1345
 
1349
1346
  def log!(flag, opts = [], range: [], index: [])
@@ -1364,9 +1361,11 @@ module Squared
1364
1361
 
1365
1362
  def diff(flag, opts = [], refs: [], branch: nil, range: [], index: [])
1366
1363
  cmd, opts = git_session('diff', opts: opts)
1367
- 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,
1368
1367
  project: self, no: OPT_GIT[:no][:log][:diff],
1369
- first: flag == :files ? nil : matchpathspec)
1368
+ first: (matchpathspec unless flag == :files))
1370
1369
  case flag
1371
1370
  when :files, :view, :between, :contain
1372
1371
  op.delete('--cached')
@@ -1374,7 +1373,16 @@ module Squared
1374
1373
  append_nocolor
1375
1374
  if flag == :files
1376
1375
  op << '--no-index'
1376
+ patch = refs.pop
1377
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
1378
1386
  else
1379
1387
  op << '--merge-base' if option('merge-base')
1380
1388
  case flag
@@ -1387,7 +1395,7 @@ module Squared
1387
1395
  op.add_quote(branch) if branch
1388
1396
  if !index.empty?
1389
1397
  if op.arg?('cached')
1390
- 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
1391
1399
  op << index.first
1392
1400
  else
1393
1401
  op.merge(index)
@@ -1403,7 +1411,7 @@ module Squared
1403
1411
 
1404
1412
  def commit(flag, opts = [], refs: [], ref: nil, squash: nil, pick: nil, message: nil, pass: false)
1405
1413
  fixup = flag == :fixup
1406
- amend = !fixup && flag.to_s.start_with?('amend')
1414
+ amend = flag.match?(/^amend/) && !fixup
1407
1415
  unless flag == :add || pick == 'reword'
1408
1416
  pathspec = if flag == :all || ((fixup || amend) && refs.size == 1 && refs.first == '*')
1409
1417
  '--all'
@@ -1414,9 +1422,9 @@ module Squared
1414
1422
  end
1415
1423
  end
1416
1424
  if fixup
1417
- source git_session('commit', basic_option('fixup', "#{pick ? "#{pick}:" : ''}#{ref}"), pathspec)
1418
- source git_output('rebase --autosquash', squash) if squash.is_a?(String)
1419
- 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
1420
1428
  end
1421
1429
  message ||= messageopt
1422
1430
  if !message && !amend
@@ -1428,7 +1436,8 @@ module Squared
1428
1436
  origin = nil
1429
1437
  upstream = nil
1430
1438
  cmd, opts = git_session('add', opts: opts)
1431
- 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)
1432
1441
  op << '--verbose' if verbose
1433
1442
  format = '%(if)%(HEAD)%(then)%(refname:short)...%(upstream:short)...%(upstream:track)%(end)'
1434
1443
  git_spawn 'fetch --no-tags --quiet'
@@ -1437,10 +1446,9 @@ module Squared
1437
1446
 
1438
1447
  branch, origin, hint = line.split('...')
1439
1448
  if hint && !hint.match?(/^\[(\D+0,\D+0)\]$/)
1440
- raise_error('work tree is not usable', hint: hint[1..-2])
1441
- elsif !origin || origin.empty?
1449
+ raise_error 'work tree is not usable', hint: hint[1..-2]
1450
+ elsif (!origin || origin.empty?) && !dryrun?
1442
1451
  return nil if pass
1443
- break if dryrun?
1444
1452
 
1445
1453
  unless (origin = option('upstream', prefix: 'git', ignore: false))
1446
1454
  if (origin = choice_refs('Choose an upstream', 'remotes', attempts: 1, force: false))
@@ -1449,6 +1457,7 @@ module Squared
1449
1457
  end
1450
1458
  origin = readline('Enter an upstream', force: true)
1451
1459
  end
1460
+ raise_error ArgumentError, 'missing remote name', hint: origin unless origin.include?('/')
1452
1461
  upstream = true
1453
1462
  end
1454
1463
  break
@@ -1459,14 +1468,13 @@ module Squared
1459
1468
  append_pathspec op.extras
1460
1469
  end
1461
1470
  co = git_session('commit', options: false)
1462
- pu = git_output 'push'
1463
- co << '--amend' if amend
1464
- pu << '--set-upstream' if upstream
1471
+ pu = git_output 'push', upstream && '--set-upstream'
1465
1472
  if dryrun?
1466
- op.adjoin('--dry-run')
1473
+ op.delete('--dry-run')
1467
1474
  co << '--dry-run'
1468
1475
  pu << '--dry-run'
1469
1476
  end
1477
+ co << '--amend' if amend
1470
1478
  if message
1471
1479
  append_message message
1472
1480
  elsif flag == :'amend-orig' || option('edit', equals: '0')
@@ -1474,6 +1482,7 @@ module Squared
1474
1482
  end
1475
1483
  pu << '--force-with-lease' if amend
1476
1484
  pu.merge(repotrack(origin, branch))
1485
+ puts if pass
1477
1486
  adding = git_spawn 'diff --name-only --no-color'
1478
1487
  source op
1479
1488
  cached = git_spawn 'diff --cached --name-only --no-color'
@@ -1483,10 +1492,13 @@ module Squared
1483
1492
  end
1484
1493
  source co
1485
1494
  source pu
1486
- elsif banner?
1487
- puts 'Nothing to commit'
1488
- elsif stdout?
1489
- 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
1490
1502
  end
1491
1503
  end
1492
1504
 
@@ -1496,26 +1508,25 @@ module Squared
1496
1508
  case flag
1497
1509
  when :commit, :'no-commit'
1498
1510
  op = OptionPartition.new(opts, OPT_GIT[:merge], cmd, project: self, no: OPT_GIT[:no][:merge])
1499
- op << "--#{flag}"
1500
- op.delim
1511
+ op << "--#{flag}" << '--'
1501
1512
  if branch
1502
1513
  op << branch
1503
1514
  op.clear(pass: false)
1504
1515
  else
1505
- raise_error 'no branch/commit' if op.empty?
1516
+ raise_error ArgumentError, 'no branch/commit' if op.empty?
1506
1517
  append_commit(*op.extras)
1507
1518
  end
1508
1519
  else
1509
1520
  unless gitpath('MERGE_HEAD').exist?
1510
1521
  puts log_message(Logger::INFO, name, 'no merge in progress', hint: command) if stdout?
1511
- return
1522
+ exit 1
1512
1523
  end
1513
1524
  return unless VAL_GIT[:merge][:send].include?(command)
1514
1525
 
1515
1526
  cmd << "--#{command}"
1516
1527
  display = command == 'abort'
1517
1528
  end
1518
- print_success if success?(source, display)
1529
+ success?(source, display)
1519
1530
  end
1520
1531
 
1521
1532
  def branch(flag = nil, opts = [], refs: [], ref: nil, target: nil, remote: nil)
@@ -1533,11 +1544,11 @@ module Squared
1533
1544
  '--track'
1534
1545
  end
1535
1546
  end
1536
- cmd << '--force' if option('force', 'f')
1547
+ cmd << '--force' if option('f', 'force')
1537
1548
  cmd << shell_quote(target)
1538
1549
  cmd << shell_quote(ref) if ref
1539
1550
  when :track
1540
- raise_error('invalid upstream', hint: ref) unless ref.include?('/')
1551
+ raise_error 'invalid upstream', hint: ref unless ref.include?('/')
1541
1552
  if ref.delete_prefix!('^')
1542
1553
  cmd << '--unset-upstream' << shell_quote(ref)
1543
1554
  remote = false
@@ -1548,7 +1559,7 @@ module Squared
1548
1559
  end
1549
1560
  when :delete
1550
1561
  remote&.each do |val|
1551
- 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) })
1552
1563
  end
1553
1564
  force, list = refs.partition { |val| val.start_with?(/[~^]/) }
1554
1565
  force.each do |val|
@@ -1562,13 +1573,13 @@ module Squared
1562
1573
  remote = nil
1563
1574
  when :move, :copy
1564
1575
  s = +"-#{flag.to_s[0]}"
1565
- s.upcase! if option('force', 'f')
1576
+ s.upcase! if option('f', 'force')
1566
1577
  cmd << s
1567
1578
  refs.compact.each { |val| cmd << shell_quote(val) }
1568
1579
  stdout = true
1569
1580
  when :current
1570
1581
  cmd << '--show-current'
1571
- source(banner: verbosetype > 1, stdout: true)
1582
+ source(banner: verbose?, stdout: true)
1572
1583
  return
1573
1584
  when :list
1574
1585
  op = OptionPartition.new(opts, OPT_GIT[:branch], cmd << '--list',
@@ -1577,8 +1588,8 @@ module Squared
1577
1588
  out, banner, from = source(io: true)
1578
1589
  print_item banner
1579
1590
  ret = write_lines(out, sub: [
1580
- { pat: /^(\*\s+)(\S+)(.*)$/, styles: color(:green), index: 2 },
1581
- { 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)
1582
1593
  ])
1583
1594
  list_result(ret, 'branches', from: from)
1584
1595
  return
@@ -1603,7 +1614,7 @@ module Squared
1603
1614
  r3 = write.call($4, $5)
1604
1615
  end
1605
1616
  r1 = nil if r1 == "origin/#{data[0]}"
1606
- [" Branch: #{a + (r1 ? " (#{r1})" : '')}", r2, r3, " Commit: #{b}", "Message: #{r[2]}"]
1617
+ [" Branch: #{a.subhint(r1)}", r2, r3, " Commit: #{b}", "Message: #{r[2]}"]
1607
1618
  .compact
1608
1619
  .join("\n")
1609
1620
  end
@@ -1612,21 +1623,17 @@ module Squared
1612
1623
  print_error(name, 'no ref found', subject: 'branch', hint: 'head', pass: true) if ret == 0
1613
1624
  return
1614
1625
  end
1615
- return unless success?(source(stdout: stdout))
1626
+ return unless success?(source(stdout: stdout), !ref && flag == :create) && !ref && remote && target
1616
1627
 
1617
- if !ref
1618
- print_success if flag == :create
1619
- elsif remote && target
1620
- source git_output('push -u', shell_quote(ref.split('/', 2).first), shell_quote(target))
1621
- end
1628
+ source git_output('push -u', shell_quote(ref.split('/', 2).first), shell_quote(target))
1622
1629
  end
1623
1630
 
1624
1631
  def switch(flag, opts = [], branch: nil, commit: nil, track: nil)
1625
1632
  cmd, opts = git_session('switch', opts: opts)
1626
- cmd << '--force' if option('force', 'f')
1633
+ cmd << '--force' if option('f', 'force')
1627
1634
  if flag == :branch
1628
- op = OptionPartition.new(opts, OPT_GIT[:switch], cmd, project: self, no: OPT_GIT[:no][:switch])
1629
- op.add_quote(branch)
1635
+ OptionPartition.new(opts, OPT_GIT[:switch], cmd, project: self, no: OPT_GIT[:no][:switch])
1636
+ .add_quote(branch)
1630
1637
  else
1631
1638
  case flag
1632
1639
  when :create
@@ -1656,16 +1663,18 @@ module Squared
1656
1663
  op.add_quote(branch, '--', path, url)
1657
1664
  else
1658
1665
  op.adjoin(flag)
1659
- op << '--recursive' if option('recursive', 'r')
1666
+ op << '--recursive' if option('r', 'recursive')
1660
1667
  op.splice(path: true)
1661
1668
  end
1662
- print_success if success?(source, flag == :branch)
1669
+ source.tap { |ret| success?(ret, flag == :branch) }
1663
1670
  end
1664
1671
 
1665
1672
  def restore(flag, opts = [], commit: nil, files: nil)
1666
1673
  cmd, opts = git_session('restore', shell_option(flag, commit, escape: false, force: false), opts: opts)
1667
- op = OptionPartition.new(opts, OPT_GIT[:restore], cmd, project: self, no: OPT_GIT[:no][:restore],
1668
- 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)
1669
1678
  append_pathspec(op.extras + (files || []), pass: false)
1670
1679
  source(sync: false, stderr: true)
1671
1680
  end
@@ -1691,9 +1700,9 @@ module Squared
1691
1700
  else
1692
1701
  opts << format if format
1693
1702
  end
1694
- op = OptionPartition.new(opts, OPT_GIT[:show] + OPT_GIT[:diff][:show] + OPT_GIT[:log][:diff], cmd,
1695
- project: self,
1696
- 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]))
1697
1706
  op.append(delim: true)
1698
1707
  source(exception: false, banner: flag != :oneline)
1699
1708
  end
@@ -1702,7 +1711,7 @@ module Squared
1702
1711
  cmd, opts = git_session('rev-parse', opts: opts)
1703
1712
  case flag
1704
1713
  when :commit
1705
- 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')
1706
1715
  append_commit(ref, head: true)
1707
1716
  when :branch
1708
1717
  cmd << '--abbrev-ref'
@@ -1712,15 +1721,14 @@ module Squared
1712
1721
  cmd << '--sq-quote'
1713
1722
  args = true
1714
1723
  end
1715
- op = OptionPartition.new(opts, OPT_GIT[:rev_parse], cmd, project: self, no: OPT_GIT[:no][:rev_parse],
1716
- args: args)
1717
- 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)
1718
1726
  end
1719
- source(banner: verbosetype > 1)
1727
+ source(banner: verbose?)
1720
1728
  end
1721
1729
 
1722
1730
  def ls_remote(flag, opts = [], remote: nil)
1723
- cmd, opts = git_session('ls-remote', '--refs', opts: opts)
1731
+ cmd, opts = git_session('ls-remote --refs', opts: opts)
1724
1732
  cmd << "--#{flag}" unless flag == :remote
1725
1733
  op = OptionPartition.new(opts, OPT_GIT[:ls_remote], cmd, project: self)
1726
1734
  op.add_quote(remote) if remote
@@ -1731,7 +1739,7 @@ module Squared
1731
1739
  end
1732
1740
 
1733
1741
  def ls_files(flag, opts = [])
1734
- cmd, opts = git_session('ls-files', "--#{flag}", opts: opts)
1742
+ cmd, opts = git_session("ls-files --#{flag}", opts: opts)
1735
1743
  op = OptionPartition.new(opts, OPT_GIT[:ls_files], cmd, project: self)
1736
1744
  op.splice(path: true, pattern: true)
1737
1745
  out, banner, from = source(io: true)
@@ -1742,55 +1750,71 @@ module Squared
1742
1750
 
1743
1751
  def git(flag, opts = [])
1744
1752
  cmd, opts = git_session(flag, opts: opts)
1745
- op = OptionPartition.new(opts, OPT_GIT[:git].fetch(flag, []) + OPT_GIT.fetch(flag, []), cmd,
1746
- project: self, no: OPT_GIT[:no][flag], first: case flag
1747
- when :blame, :revert
1748
- nil
1749
- else matchpathspec
1750
- 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)
1751
1760
  case flag
1752
1761
  when :blame
1753
- raise_error 'no file found' unless (n = op.index { |s| basepath(s).file? })
1754
- op.delim << shell_quote(basepath(op.delete_at(n)))
1755
- 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
1756
1765
  when :revert
1757
1766
  if VAL_GIT[:rebase][:send].any? { |val| op.arg?(val) }
1758
1767
  op.clear
1759
1768
  elsif op.empty?
1760
- raise_error 'no commit given'
1769
+ raise_error 'no commit target'
1761
1770
  else
1762
1771
  append_commit(*op.extras)
1763
1772
  end
1764
1773
  when :add
1765
1774
  if flag == :add && !op.arg?('pathspec-from-file')
1766
- grep, list = op.partition { |val| OptionPartition.pattern?(val) }
1767
- unless grep.empty? && !list.empty?
1775
+ grep, pathspec = op.partition { |val| OptionPartition.pattern?(val) }
1776
+ unless grep.empty? && !pathspec.empty?
1768
1777
  grep.map! { |val| Regexp.new(val[1..-2]) }
1769
- files = []
1770
- status_data.each do |a, b|
1771
- 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) })
1772
1781
 
1773
- files << "#{sub_style(b, styles: color(:red))} #{a}"
1782
+ out << "#{sub_style(b, styles: color(:red))} #{a}"
1783
+ end
1774
1784
  end
1775
1785
  unless files.empty?
1776
- files = choice_index('Select files', files, multiple: true, trim: /^\S+\s/,
1777
- accept: [['Add?', false, true]])
1786
+ files = choice_index('Select files', files, multiple: true, force: true, trim: /^\S+\s/,
1787
+ accept: [accept_y('Add?')])
1778
1788
  end
1779
- op.swap(list + files)
1789
+ op.swap(pathspec + files)
1780
1790
  end
1781
1791
  end
1782
1792
  return source(git_session('status -s'), banner: false) unless append_pathspec(op.extras)
1783
-
1784
- print_success if success?(source, flag == :add && !op.arg?('verbose'))
1785
- return
1793
+ return success?(source) if flag == :add && !op.arg?('verbose')
1786
1794
  when :mv
1787
1795
  refs = projectmap op.extras
1788
1796
  raise_error 'no source/destination' unless refs.size > 1
1789
1797
  op.merge(refs)
1790
1798
  when :rm, :clean
1791
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
1792
1817
  end
1793
- source(sync: false, stderr: true)
1794
1818
  end
1795
1819
 
1796
1820
  def clone?
@@ -1818,20 +1842,15 @@ module Squared
1818
1842
  banner = nil unless banner? && !multiple
1819
1843
  args = true
1820
1844
  end
1821
- if cmd.respond_to?(:done)
1822
- if from.nil? && (from = cmd.drop(1).find { |val| val.match?(/\A[a-z]{1,2}[a-z-]*\z/) })
1823
- from = :"git:#{from}"
1824
- end
1825
- 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}"
1826
1847
  end
1848
+ banner &&= cmd.temp { |val| val.start_with?(/--(?:work-tree|git-dir)/) } if cmd.respond_to?(:temp)
1827
1849
  from = nil if from == false
1828
1850
  end
1829
1851
  cmd = session_done cmd
1830
1852
  log&.info cmd
1831
- banner = if banner
1832
- banner = (banner.is_a?(String) ? banner : cmd).gsub(File.join(path, ''), '')
1833
- format_banner(hint ? "#{banner} (#{hint})" : banner)
1834
- end
1853
+ banner = format_banner(banner.is_a?(String) ? banner : cmd, hint: hint, strip: true) if banner
1835
1854
  on :first, from
1836
1855
  begin
1837
1856
  if io
@@ -1841,10 +1860,12 @@ module Squared
1841
1860
  elsif stdin? ? sync : stdout
1842
1861
  print_item banner unless multiple
1843
1862
  ret = `#{cmd}`
1844
- if !ret.empty?
1863
+ raise(ret.chomp.empty? ? $?.to_s : ret) unless $?.success?
1864
+
1865
+ if ret.empty?
1866
+ success?(nil, !banner.nil?)
1867
+ else
1845
1868
  puts ret
1846
- elsif success?(!banner.nil?)
1847
- print_success
1848
1869
  end
1849
1870
  elsif !kwargs[:sub] && (sync || (!exception && !stderr))
1850
1871
  print_item banner unless multiple
@@ -1856,7 +1877,7 @@ module Squared
1856
1877
  n = write_lines(out, banner: banner, pass: true, **kwargs)
1857
1878
  if n == 0
1858
1879
  n = write_lines(err, banner: banner)
1859
- print_success if success?(n == 0 && !banner.nil?)
1880
+ success?(nil, n == 0 && !banner.nil?)
1860
1881
  else
1861
1882
  write_lines(err, loglevel: Logger::DEBUG)
1862
1883
  end
@@ -1875,17 +1896,14 @@ module Squared
1875
1896
  end
1876
1897
 
1877
1898
  def write_lines(data, grep: [], prefix: nil, sub: nil, banner: nil, loglevel: nil, pass: false, first: false)
1878
- grep = grep.empty? ? nil : matchmap(grep, prefix)
1879
- sub = nil if stdin?
1899
+ grep = (matchmap(grep, prefix) unless grep.empty?)
1900
+ sub = (as_a sub unless stdin?)
1880
1901
  ret = 0
1881
1902
  out = []
1882
1903
  data.each do |line|
1883
1904
  next if grep&.none? { |pat| pat.match?(line) }
1905
+ next if block_given? && !(line = yield line)
1884
1906
 
1885
- if block_given?
1886
- line = yield line
1887
- next unless line
1888
- end
1889
1907
  if loglevel
1890
1908
  log&.add loglevel, line
1891
1909
  else
@@ -1910,7 +1928,7 @@ module Squared
1910
1928
  styles = theme.fetch(:banner, []).reject { |s| s.to_s.end_with?('!') }
1911
1929
  styles << :bold if styles.size <= 1
1912
1930
  puts print_footer("#{size} #{size == 1 ? type.sub(/(?:(?<!l)e)?s\z/, '') : type}",
1913
- sub: [pat: /^(\d+)(.+)$/, styles: styles])
1931
+ sub: opt_style(styles, /^(\d+)(.+)$/))
1914
1932
  end
1915
1933
  on :last, from
1916
1934
  end
@@ -1926,7 +1944,7 @@ module Squared
1926
1944
  end
1927
1945
  args = []
1928
1946
  args << quote_option('sort', sort) if sort
1929
- args << basic_option('count', env('GIT_COUNT', ARG[:CHOICE])) if count
1947
+ args << shell_option('count', env('GIT_COUNT', ARG[:CHOICE])) if count
1930
1948
  choice_index(msg, foreachref(type, *args, format: format), trim: trim, **kwargs)
1931
1949
  end
1932
1950
 
@@ -1959,17 +1977,17 @@ module Squared
1959
1977
  end
1960
1978
 
1961
1979
  def status_data(*args)
1962
- ret = []
1963
- git_spawn('status -z -uall', *args).split("\x0").each do |line|
1964
- next unless line =~ /^(.)(.) (.+)$/
1980
+ [].tap do |ret|
1981
+ git_spawn('status -z -uall', *args).split("\x0").each do |line|
1982
+ next unless line =~ /^(.)(.) (.+)$/
1965
1983
 
1966
- ret << [$3, $2, $1]
1984
+ ret << [$3, $2, $1]
1985
+ end
1967
1986
  end
1968
- ret
1969
1987
  end
1970
1988
 
1971
1989
  def append_pull(opts, list, target: @session, flag: nil, no: nil, remote: nil, from: nil)
1972
- target << '--force' if option('force', 'f', target: target)
1990
+ target << '--force' if option('f', 'force', target: target)
1973
1991
  append_submodules(target: target, from: from)
1974
1992
  return if !remote && opts.empty?
1975
1993
 
@@ -1981,6 +1999,7 @@ module Squared
1981
1999
  when 'rebase'
1982
2000
  op << basic_option($1, $2) if VAL_GIT[:rebase][:value].include?($2)
1983
2001
  when 'shallow-since'
2002
+ require 'date'
1984
2003
  op.append?($1) { Date.parse($2).strftime('%F %T') }
1985
2004
  when 'recurse-submodules'
1986
2005
  op.append?($1, $2, type: :basic)
@@ -2040,9 +2059,7 @@ module Squared
2040
2059
 
2041
2060
  def append_message(val = nil, target: @session)
2042
2061
  val = messageopt if val.to_s.empty?
2043
- return unless val
2044
-
2045
- target << quote_option('message', val)
2062
+ target << quote_option('message', val) if val
2046
2063
  end
2047
2064
 
2048
2065
  def append_head(val = nil, target: @session)
@@ -2060,9 +2077,7 @@ module Squared
2060
2077
  when '1', 'true'
2061
2078
  target << '--recurse-submodules'
2062
2079
  else
2063
- projectmap(split_escape(val)).each do |path|
2064
- target << basic_option('recurse-submodules', path)
2065
- end
2080
+ projectmap(split_escape(val)).each { |path| target << basic_option('recurse-submodules', path) }
2066
2081
  end
2067
2082
  else
2068
2083
  target << case val
@@ -2109,28 +2124,24 @@ module Squared
2109
2124
  stdout: stdout, banner: banner, **kwargs)
2110
2125
  end
2111
2126
 
2112
- def dryrun?(*, target: @session, **)
2113
- return false unless target
2114
-
2115
- 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?
2116
2129
  end
2117
2130
 
2118
2131
  def quiet?(*, target: @session, **)
2119
2132
  return false unless target
2120
2133
 
2121
- target.include?('--quiet') || (target.include?('-q') && stripext(target.first) == 'git')
2134
+ target.include?('--quiet') || (target.include?('-q') && target.first.stripext == 'git')
2122
2135
  end
2123
2136
 
2124
2137
  def gitpath(*args)
2125
- path.join('.git', *args)
2138
+ basepath('.git', *args)
2126
2139
  end
2127
2140
 
2128
2141
  def repotrack(origin, branch, quote: true)
2129
- unless origin && branch && (i = origin.index('/'))
2130
- raise_error(ArgumentError, "missing #{origin ? 'branch' : 'remote'} name", hint: origin)
2131
- end
2132
- branch = "#{branch}:#{origin[(i + 1)..-1]}" unless origin.end_with?("/#{branch}")
2133
- [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 }
2134
2145
  end
2135
2146
 
2136
2147
  def commithash(val)