squared 0.6.2 → 0.6.3

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.
@@ -21,14 +21,17 @@ module Squared
21
21
  end
22
22
  elsif uri
23
23
  data[name.to_s] = uri
24
- elsif name.is_a?(Enumerable)
25
- data = name.to_h
26
- elsif name.is_a?(String) && name.match?(GIT_PROTO)
27
- base = name
28
- @project.each_value { |proj| repo << proj if !proj.parent && check.call(proj) }
29
24
  else
30
- warn log_message(Logger::WARN, name, subject: 'git', hint: 'invalid') if warning
31
- return self
25
+ case name
26
+ when Enumerable
27
+ data = name.to_h
28
+ when GIT_PROTO
29
+ base = name.to_s
30
+ each { |proj| repo << proj if !proj.parent && check.call(proj) }
31
+ else
32
+ warn log_message(Logger::WARN, name, subject: 'git', hint: 'invalid') if warning
33
+ return self
34
+ end
32
35
  end
33
36
  if base
34
37
  base = base.match?(GIT_PROTO) ? "#{base.chomp('/')}/" : rootpath(base)
@@ -144,6 +147,7 @@ module Squared
144
147
  @revlock = false
145
148
  end
146
149
  end
150
+
147
151
  Application.include Git
148
152
 
149
153
  module Project
@@ -323,7 +327,7 @@ module Squared
323
327
  'fetch' => %i[origin remote all].freeze,
324
328
  'files' => %i[cached modified deleted others].freeze,
325
329
  'git' => %i[add blame clean grep mv revert rm status].freeze,
326
- 'log' => %i[view between contain].freeze,
330
+ 'log' => %i[view grep between contain].freeze,
327
331
  'merge' => %i[commit no-commit send].freeze,
328
332
  'pull' => %i[origin remote all].freeze,
329
333
  'rebase' => %i[branch onto send].freeze,
@@ -566,6 +570,37 @@ module Squared
566
570
  path2 = param_guard(action, flag, args: args, key: :path2)
567
571
  diff(flag, refs: [path1, path2, args.patch])
568
572
  end
573
+ when :grep
574
+ format_desc action, flag, 'pattern+,a/ll-match?,in/vert-grep?,i/E/F/P?,max-count?=i,f/ormat?=s'
575
+ task flag do |_, args|
576
+ grep = args.to_a
577
+ opts = ['oneline']
578
+ while (last = grep.pop)
579
+ case last
580
+ when '--'
581
+ grep << '--' if grep.empty?
582
+ break
583
+ when 'a', 'all-match'
584
+ opts << 'all-match'
585
+ when 'in', 'invert-grep'
586
+ opts << 'invert-grep'
587
+ when 'i', 'E', 'F', 'P'
588
+ opts << last
589
+ else
590
+ if last =~ /^(?:f(?:-ormat)?)=(.+)$/
591
+ opts.shift
592
+ opts << "format=#{$1}"
593
+ elsif last =~ /^(?:max(?:-count)?)=(\d+)$/
594
+ opts << "max-count=#{$1}"
595
+ else
596
+ grep << last
597
+ break
598
+ end
599
+ end
600
+ end
601
+ param_guard(action, flag, args: grep)
602
+ log!(flag, opts, grep: grep)
603
+ end
569
604
  end
570
605
  when 'checkout'
571
606
  case flag
@@ -659,7 +694,7 @@ module Squared
659
694
  branch(flag, target: target, ref: ref, remote: remote)
660
695
  end
661
696
  when :delete
662
- format_desc action, flag, '(^~)name*,:?'
697
+ format_desc action, flag, '[^~]name*,:?'
663
698
  task flag do |_, args|
664
699
  refs = args.to_a
665
700
  if refs.empty? || (r = refs.last == ':')
@@ -1078,9 +1113,18 @@ module Squared
1078
1113
  end
1079
1114
  option('local', strict: true) { |val| opts[:local] = val != '0' }
1080
1115
  option('bare') { |val| opts[:bare] = val }
1116
+ option('single-branch', ignore: false) do |val|
1117
+ opts[:'single-branch'] = val != '0' && val != 'false'
1118
+ opts.delete(:'no-single-branch')
1119
+ end
1120
+ option('no-checkout') do
1121
+ opts[:'no-checkout'] = true
1122
+ opts.delete(:n)
1123
+ end
1124
+ option('no-tags') { opts[:'no-tags'] = true }
1081
1125
  opts.delete(:'recurse-submodules') || opts.delete(:'no-recurse-submodules') if append_submodules(from: :clone)
1082
1126
  append_hash opts
1083
- cmd << '--quiet' unless verbose
1127
+ cmd << '--quiet' if option('quiet') || !verbose
1084
1128
  append_value(data[0], path, delim: true)
1085
1129
  source(banner: sync && !quiet?, multiple: !sync || quiet?)
1086
1130
  end
@@ -1136,8 +1180,8 @@ module Squared
1136
1180
  end
1137
1181
  op.clear
1138
1182
  when :clear
1139
- n = sub_style(file.read.lines.size, styles: theme[:inline])
1140
- s = sub_style(name, styles: theme[:active])
1183
+ n = sub_style file.read.lines.size, theme[:inline]
1184
+ s = sub_style name, theme[:active]
1141
1185
  source(stdout: true) if confirm("Remove #{n} stash entries from #{s}?", 'N')
1142
1186
  return
1143
1187
  when :list
@@ -1197,7 +1241,7 @@ module Squared
1197
1241
  end
1198
1242
 
1199
1243
  def revbuild(flag = nil, opts = [], sync: nil, **kwargs)
1200
- statusargs = lambda do
1244
+ kw = lambda do
1201
1245
  {
1202
1246
  include: relativepath(Array(kwargs[:include]), all: true),
1203
1247
  exclude: relativepath(Array(kwargs[:exclude]), all: true)
@@ -1205,9 +1249,9 @@ module Squared
1205
1249
  end
1206
1250
  unless workspace.closed
1207
1251
  if @revbuild
1208
- statusargs.call.each { |key, val| @revbuild[key] += val }
1252
+ kw.call.each { |key, val| @revbuild[key] += val }
1209
1253
  else
1210
- @revbuild = statusargs.call
1254
+ @revbuild = kw.call
1211
1255
  end
1212
1256
  return
1213
1257
  end
@@ -1215,7 +1259,7 @@ module Squared
1215
1259
  return if sha.empty?
1216
1260
 
1217
1261
  sync = invoked_sync?('revbuild', flag) if sync.nil?
1218
- kwargs = kwargs.key?(:include) || kwargs.key?(:exclude) ? statusargs.call : @revbuild || {}
1262
+ kwargs = kwargs.key?(:include) || kwargs.key?(:exclude) ? kw.call : @revbuild || {}
1219
1263
  case flag
1220
1264
  when :build
1221
1265
  op = OptionPartition.new(opts, VAL_GIT[:revbuild].map { |key| "#{key}=b?" }, project: self)
@@ -1239,7 +1283,7 @@ module Squared
1239
1283
  end
1240
1284
  end
1241
1285
  start = time_epoch
1242
- build(@output, sync: sync, from: :'git:revbuild')
1286
+ build(*@output, sync: sync, from: :'git:revbuild')
1243
1287
  rescue StandardError => e
1244
1288
  print_error(e, pass: true)
1245
1289
  else
@@ -1347,7 +1391,7 @@ module Squared
1347
1391
  end
1348
1392
  end
1349
1393
 
1350
- def log!(flag, opts = [], range: [], index: [])
1394
+ def log!(flag, opts = [], range: [], index: [], grep: [])
1351
1395
  cmd, opts = git_session('log', opts: opts)
1352
1396
  op = OptionPartition.new(opts, collect_hash(OPT_GIT[:log]), cmd, project: self,
1353
1397
  no: collect_hash(OPT_GIT[:no][:log]),
@@ -1355,6 +1399,8 @@ module Squared
1355
1399
  case flag
1356
1400
  when :between, :contain
1357
1401
  op.add_quote(range.join(flag == :between ? '..' : '...'))
1402
+ when :grep
1403
+ op.merge(grep.map { |val| quote_option('grep', val) })
1358
1404
  else
1359
1405
  op.merge(index)
1360
1406
  end
@@ -1442,7 +1488,7 @@ module Squared
1442
1488
  cmd, opts = git_session('add', opts: opts)
1443
1489
  op = OptionPartition.new(opts, OPT_GIT[:add] + OPT_GIT[:log][:diff_context], cmd,
1444
1490
  project: self, no: OPT_GIT[:no][:add], first: matchpathspec)
1445
- op << '--verbose' if verbose
1491
+ op << '--verbose' unless silent?
1446
1492
  format = '%(if)%(HEAD)%(then)%(refname:short)...%(upstream:short)...%(upstream:track)%(end)'
1447
1493
  git_spawn 'fetch --no-tags --quiet'
1448
1494
  foreachref('heads', format: format).each do |line|
@@ -1461,7 +1507,6 @@ module Squared
1461
1507
  end
1462
1508
  origin = readline('Enter an upstream', force: true)
1463
1509
  end
1464
- raise_error ArgumentError, 'missing remote name', hint: origin unless origin.include?('/')
1465
1510
  upstream = true
1466
1511
  end
1467
1512
  break
@@ -1608,11 +1653,11 @@ module Squared
1608
1653
  next line if stdin?
1609
1654
 
1610
1655
  data = line.sub(/^\*\s+/, '').split(/\s+/)
1611
- a = sub_style(data[0], styles: theme[:inline])
1612
- b = sub_style(data[1], styles: theme[:extra])
1656
+ a = sub_style data[0], theme[:inline]
1657
+ b = sub_style data[1], theme[:extra]
1613
1658
  r = /\A(?:\[((?~\]\s))\]\s)?(.+)\z/m.match(data[2..-1].join(' '))
1614
1659
  if (r1 = r[1]) && r1 =~ /^(.+):(?: ([a-z]+) (\d+),)? ([a-z]+) (\d+)$/
1615
- write = ->(s1, s2) { "#{s1.capitalize.rjust(7)}: #{sub_style(s2, styles: theme[:warn])}" }
1660
+ write = ->(s1, s2) { "#{s1.capitalize.rjust(7)}: #{sub_style(s2, theme[:warn])}" }
1616
1661
  r1 = $1
1617
1662
  r2 = $2 && write.call($2, $3)
1618
1663
  r3 = write.call($4, $5)
@@ -1788,7 +1833,7 @@ module Squared
1788
1833
  status_data.each do |a, b|
1789
1834
  next if b.strip.empty? || (!grep.empty? && grep.none? { |pat| pat.match?(a) })
1790
1835
 
1791
- out << "#{sub_style(b, styles: color(:red))} #{a}"
1836
+ out << "#{sub_style(b, color(:red))} #{a}"
1792
1837
  end
1793
1838
  end
1794
1839
  unless files.empty?
@@ -1917,7 +1962,7 @@ module Squared
1917
1962
  if loglevel
1918
1963
  log&.add loglevel, line
1919
1964
  else
1920
- sub&.each { |h| line = sub_style(line, **h) }
1965
+ sub&.each { |h| sub_style!(line, **h) }
1921
1966
  if banner
1922
1967
  out << line
1923
1968
  else
@@ -1946,7 +1991,7 @@ module Squared
1946
1991
  def choice_refs(msg, *type, format: nil, sort: '-creatordate', count: true, short: true, **kwargs)
1947
1992
  type << 'heads' if type.empty?
1948
1993
  unless format
1949
- format = +"%(refname#{short ? ':short' : ''})"
1994
+ format = +"%(refname#{':short' if short})"
1950
1995
  if type.include?('heads') || type.include?('tags')
1951
1996
  format += '%(if)%(HEAD)%(then) *%(end)'
1952
1997
  trim = /\s+\*\z/
@@ -2149,7 +2194,9 @@ module Squared
2149
2194
  end
2150
2195
 
2151
2196
  def repotrack(origin, branch, quote: true)
2152
- i = origin.index('/')
2197
+ unless origin && branch && (i = origin.index('/'))
2198
+ raise_error(ArgumentError, "missing #{origin ? 'branch' : 'remote'} name", hint: origin)
2199
+ end
2153
2200
  branch = "#{branch}:#{origin[i.succ..-1]}" unless origin.end_with?("/#{branch}")
2154
2201
  [origin[0..i.pred], branch].tap { |ret| ret.map! { |val| shell_quote(val) } if quote }
2155
2202
  end