squared 0.6.4 → 0.6.6

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.
@@ -29,7 +29,7 @@ module Squared
29
29
  base = name.to_s
30
30
  each { |proj| repo << proj if !proj.parent && check.call(proj) }
31
31
  else
32
- warn log_message(Logger::WARN, name, subject: 'git', hint: 'invalid') if warning
32
+ warn log_warn(name, subject: 'git', hint: 'invalid') if warning
33
33
  return self
34
34
  end
35
35
  end
@@ -86,7 +86,7 @@ module Squared
86
86
  @revdoc = JSON.parse(@revfile.read) if @revfile.exist?
87
87
  rescue StandardError => e
88
88
  @revfile = nil
89
- warn log_message(Logger::WARN, e, pass: true)
89
+ warn log_warn(e, pass: true)
90
90
  self
91
91
  else
92
92
  @revdoc = {} unless @revdoc.is_a?(Hash)
@@ -142,7 +142,7 @@ module Squared
142
142
  File.write(@revfile, JSON.pretty_generate(@revdoc))
143
143
  rescue StandardError => e
144
144
  log&.debug e
145
- warn log_message(Logger::WARN, e, pass: true) if warning?
145
+ warn log_warn(e, pass: true) if warning
146
146
  ensure
147
147
  @revlock = false
148
148
  end
@@ -489,7 +489,7 @@ module Squared
489
489
  when :push then 'pathspec*,:'
490
490
  when :branch then 'name,stash/:'
491
491
  when :clear, :list, :all then nil
492
- else 'stash/:'
492
+ else 'stash?|:'
493
493
  end)
494
494
  task flag do |_, args|
495
495
  stash flag, args.to_a
@@ -580,17 +580,17 @@ module Squared
580
580
  when '--'
581
581
  grep << '--' if grep.empty?
582
582
  break
583
- when 'a', 'all-match'
583
+ when /^a(ll-match)?$/
584
584
  opts << 'all-match'
585
- when 'in', 'invert-grep'
585
+ when /^in(vert-grep)?$/
586
586
  opts << 'invert-grep'
587
587
  when 'i', 'E', 'F', 'P'
588
588
  opts << last
589
589
  else
590
- if last =~ /^(?:f(?:-ormat)?)=(.+)$/
590
+ if last =~ /^(f(-ormat)?)=(.+)$/
591
591
  opts.shift
592
592
  opts << "format=#{$1}"
593
- elsif last =~ /^(?:max(?:-count)?)=(\d+)$/
593
+ elsif last =~ /^(max(-count)?)=(\d+)$/
594
594
  opts << "max-count=#{$1}"
595
595
  else
596
596
  grep << last
@@ -751,7 +751,7 @@ module Squared
751
751
  switch(flag, commit: commit)
752
752
  end
753
753
  when :branch
754
- format_desc action, flag, 'name|:,opts*'
754
+ format_desc action, flag, 'name/:,opts*'
755
755
  task flag, [:name] do |_, args|
756
756
  args = if (branch = args.name)
757
757
  branch = nil if branch == ':'
@@ -765,7 +765,7 @@ module Squared
765
765
  when 'reset'
766
766
  case flag
767
767
  when :commit
768
- format_desc action, flag, 'ref|:,opts*'
768
+ format_desc action, flag, 'ref/:,opts*'
769
769
  task flag, [:commit] do |_, args|
770
770
  commit = commithead args.commit
771
771
  args = if commit && commit != ':'
@@ -921,7 +921,7 @@ module Squared
921
921
  restore(flag, args, commit: commit, files: files)
922
922
  end
923
923
  when :staged, :worktree
924
- format_desc action, flag, 'opts*,pathspec*,:?'
924
+ format_desc action, flag, 'opts*,pathspec*|:'
925
925
  task flag do |_, args|
926
926
  args = args.to_a
927
927
  if args.empty? || args.last == ':'
@@ -1167,7 +1167,7 @@ module Squared
1167
1167
  end
1168
1168
  end
1169
1169
  out = choice_index('Choose a stash', git_spawn('stash list', stdout: false),
1170
- values: values, column: /^[^@]+@\{(\d+)}/, force: true)
1170
+ values: values, column: /^[^@]+@\{(\d+)\}/)
1171
1171
  if values
1172
1172
  op.merge(out.reverse)
1173
1173
  else
@@ -1243,8 +1243,8 @@ module Squared
1243
1243
  def revbuild(flag = nil, opts = [], sync: nil, **kwargs)
1244
1244
  kw = lambda do
1245
1245
  {
1246
- include: relativepath(Array(kwargs[:include]), all: true),
1247
- exclude: relativepath(Array(kwargs[:exclude]), all: true)
1246
+ include: relativepath(*Array(kwargs[:include]), all: true),
1247
+ exclude: relativepath(*Array(kwargs[:exclude]), all: true)
1248
1248
  }
1249
1249
  end
1250
1250
  unless workspace.closed
@@ -1276,9 +1276,7 @@ module Squared
1276
1276
  files = status_digest(*args, **kwargs)
1277
1277
  if cur['files'].size == files.size && cur['files'].find { |key, val| files[key] != val }.nil?
1278
1278
  workspace.rev_timeutc(name, 'build') unless (since = workspace.rev_timesince(name, 'build'))
1279
- if stdout?
1280
- puts log_message(['revbuild', 'no changes'], subject: name, hint: ("#{since} ago" if since))
1281
- end
1279
+ puts log_message(['revbuild', 'no changes'], subject: name, hint: ("#{since} ago" if since)) if stdout?
1282
1280
  return
1283
1281
  end
1284
1282
  end
@@ -1513,13 +1511,14 @@ module Squared
1513
1511
  append_pathspec op.extras
1514
1512
  end
1515
1513
  co = git_session('commit', options: false)
1516
- pu = git_output 'push', upstream && '--set-upstream'
1514
+ pu = git_output 'push'
1515
+ co << '--amend' if amend
1516
+ pu << '--set-upstream' if upstream
1517
1517
  if dryrun?
1518
- op.delete('--dry-run')
1518
+ op.adjoin('--dry-run')
1519
1519
  co << '--dry-run'
1520
1520
  pu << '--dry-run'
1521
1521
  end
1522
- co << '--amend' if amend
1523
1522
  if message
1524
1523
  append_message message
1525
1524
  elsif flag == :'amend-orig' || option('edit', equals: '0')
@@ -1527,13 +1526,12 @@ module Squared
1527
1526
  end
1528
1527
  pu << '--force-with-lease' if amend
1529
1528
  pu.merge(repotrack(origin, branch))
1530
- puts if pass
1531
1529
  adding = git_spawn 'diff --name-only --no-color'
1532
1530
  source op
1533
1531
  cached = git_spawn 'diff --cached --name-only --no-color'
1534
1532
  if amend || !cached.empty? || dryrun?
1535
1533
  if adding.empty? && !cached.empty? && banner?
1536
- puts(cached.lines.map! { |val| "cached #{shell_quote(val.chomp)}" })
1534
+ puts(cached.lines(chomp: true).map! { |val| "cached #{shell_quote(val)}" })
1537
1535
  end
1538
1536
  source co
1539
1537
  source pu
@@ -1553,7 +1551,8 @@ module Squared
1553
1551
  case flag
1554
1552
  when :commit, :'no-commit'
1555
1553
  op = OptionPartition.new(opts, OPT_GIT[:merge], cmd, project: self, no: OPT_GIT[:no][:merge])
1556
- op << "--#{flag}" << '--'
1554
+ op << "--#{flag}"
1555
+ op.delim
1557
1556
  if branch
1558
1557
  op << branch
1559
1558
  op.clear(pass: false)
@@ -1643,13 +1642,15 @@ module Squared
1643
1642
  git_spawn 'fetch --all --prune --quiet' if option('sync')
1644
1643
  cmd << '-vv --no-abbrev --list'
1645
1644
  out, banner, from = source(io: true)
1646
- ret = write_lines(out, grep: [/^\*\s+#{Regexp.escape(head)}\s/], banner: banner, first: true) do |line|
1645
+ first = workspace.size > 1
1646
+ grep = first ? [/^\*\s+#{Regexp.escape(head)}\s/] : []
1647
+ ret = write_lines(out, grep: grep, banner: banner, first: first) do |line, index|
1647
1648
  next line if stdin?
1648
1649
 
1649
- data = line.sub(/^\*\s+/, '').split(/\s+/)
1650
- a = sub_style data[0], theme[:inline]
1651
- b = sub_style data[1], theme[:extra]
1652
- r = /\A(?:\[((?~\]\s))\]\s)?(.+)\z/m.match(data[2..-1].join(' '))
1650
+ data = line.sub(/^\*?\s+/, '').split(/\s+/, 3)
1651
+ a = sub_style(data[0], theme[:inline], styles: (:underline if !first && line.start_with?('*')))
1652
+ b = commitstyle data[1]
1653
+ r = /\A(?:\[((?~\]\s))\]\s)?(.+)\z/m.match(data[2])
1653
1654
  if (r1 = r[1]) && r1 =~ /^(.+):(?: ([a-z]+) (\d+),)? ([a-z]+) (\d+)$/
1654
1655
  write = ->(s1, s2) { "#{s1.capitalize.rjust(7)}: #{sub_style(s2, theme[:warn])}" }
1655
1656
  r1 = $1
@@ -1657,7 +1658,7 @@ module Squared
1657
1658
  r3 = write.call($4, $5)
1658
1659
  end
1659
1660
  r1 = nil if r1 == "origin/#{data[0]}"
1660
- [" Branch: #{a.subhint(r1)}", r2, r3, " Commit: #{b}", "Message: #{r[2]}"]
1661
+ ["#{"\n" unless index == 0} Branch: #{a.subhint(r1)}", r2, r3, " Commit: #{b}", "Message: #{r[2]}"]
1661
1662
  .compact
1662
1663
  .join("\n")
1663
1664
  end
@@ -1690,7 +1691,7 @@ module Squared
1690
1691
  basic_option 'track', track
1691
1692
  end
1692
1693
  when :detach
1693
- cmd << "--#{flag}"
1694
+ cmd << '--detach'
1694
1695
  end
1695
1696
  append_head commit
1696
1697
  end
@@ -1738,7 +1739,7 @@ module Squared
1738
1739
  case format
1739
1740
  when 'oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
1740
1741
  cmd << basic_option('format', format)
1741
- when /(?:^t?format:|%)/
1742
+ when /^t?format:|%/
1742
1743
  cmd << quote_option('pretty', format)
1743
1744
  else
1744
1745
  opts << format if format
@@ -1754,7 +1755,7 @@ module Squared
1754
1755
  cmd, opts = git_session('rev-parse', opts: opts)
1755
1756
  case flag
1756
1757
  when :commit
1757
- cmd << ((n = size.to_i) > 0 ? basic_option('short', [n, 5].max) : '--verify')
1758
+ cmd << (size.to_i.zero? ? '--verify' : basic_option('short', [size.to_i, 5].max))
1758
1759
  append_commit(ref, head: true)
1759
1760
  when :branch
1760
1761
  cmd << '--abbrev-ref'
@@ -1823,15 +1824,14 @@ module Squared
1823
1824
  grep, pathspec = op.partition { |val| OptionPartition.pattern?(val) }
1824
1825
  unless grep.empty? && !pathspec.empty?
1825
1826
  grep.map! { |val| Regexp.new(val[1..-2]) }
1826
- files = [].tap do |out|
1827
- status_data.each do |a, b|
1828
- next if b.strip.empty? || (!grep.empty? && grep.none? { |pat| pat.match?(a) })
1827
+ files = []
1828
+ status_data.each do |a, b|
1829
+ next if b.strip.empty? || (!grep.empty? && grep.none? { |pat| pat.match?(a) })
1829
1830
 
1830
- out << "#{sub_style(b, color(:red))} #{a}"
1831
- end
1831
+ files << "#{sub_style(b, color(:red))} #{a}"
1832
1832
  end
1833
1833
  unless files.empty?
1834
- files = choice_index('Select files', files, multiple: true, force: true, trim: /^\S+\s/,
1834
+ files = choice_index('Select files', files, multiple: true, trim: /^\S+\s/,
1835
1835
  accept: [accept_y('Add?')])
1836
1836
  end
1837
1837
  op.swap(pathspec + files)
@@ -1850,8 +1850,8 @@ module Squared
1850
1850
  if op.include?('--')
1851
1851
  op.add_path(val)
1852
1852
  elsif op.exist?(val, glob: true)
1853
- op << '--'
1854
- op.add_path(val)
1853
+ op.delim
1854
+ .add_path(val)
1855
1855
  else
1856
1856
  op.add_quote(val)
1857
1857
  end
@@ -1951,7 +1951,7 @@ module Squared
1951
1951
  out = []
1952
1952
  data.each do |line|
1953
1953
  next if grep&.none? { |pat| pat.match?(line) }
1954
- next if block_given? && !(line = yield line)
1954
+ next if block_given? && !(line = yield(line, ret))
1955
1955
 
1956
1956
  if loglevel
1957
1957
  log&.add loglevel, line
@@ -1993,16 +1993,24 @@ module Squared
1993
1993
  end
1994
1994
  args = []
1995
1995
  args << quote_option('sort', sort) if sort
1996
- args << shell_option('count', env('GIT_COUNT', ARG[:CHOICE])) if count
1996
+ args << basic_option('count', env('GIT_COUNT', ARG[:CHOICE])) if count
1997
1997
  choice_index(msg, foreachref(type, *args, format: format), trim: trim, **kwargs)
1998
1998
  end
1999
1999
 
2000
2000
  def choice_commit(count: true, reflog: true, force: true, **kwargs)
2001
2001
  kwargs[:attempts] ||= 1 unless force
2002
2002
  cmd = git_output(reflog && env('GIT_REFLOG') ? 'reflog' : 'log')
2003
- cmd << quote_option('format', '(%h) %s')
2003
+ cmd << quote_option('format', "#{commitstyle('%h')} %s")
2004
2004
  cmd << basic_option('max-count', env('GIT_COUNT', ARG[:CHOICE])) if count
2005
- choice_index('Choose a commit', git_spawn(cmd, stdout: false), column: /\((\w+)\)/, force: force, **kwargs)
2005
+ ret = choice_index('Choose a commit', git_spawn(cmd, stdout: false), column: /^(\S+)/, force: force, **kwargs)
2006
+ case ret
2007
+ when Array
2008
+ ret.map!(&:stripstyle)
2009
+ when String
2010
+ ret.stripstyle
2011
+ else
2012
+ ret
2013
+ end
2006
2014
  end
2007
2015
 
2008
2016
  def choice_remote(force: false, **kwargs)
@@ -2026,13 +2034,13 @@ module Squared
2026
2034
  end
2027
2035
 
2028
2036
  def status_data(*args)
2029
- [].tap do |ret|
2030
- git_spawn('status -z -uall', *args).split("\x0").each do |line|
2031
- next unless line =~ /^(.)(.) (.+)$/
2037
+ ret = []
2038
+ git_spawn('status -z -uall', *args).split("\x0").each do |line|
2039
+ next unless line =~ /^(.)(.) (.+)$/
2032
2040
 
2033
- ret << [$3, $2, $1]
2034
- end
2041
+ ret << [$3, $2, $1]
2035
2042
  end
2043
+ ret
2036
2044
  end
2037
2045
 
2038
2046
  def append_pull(opts, list, flag:, from:, target: @session, no: nil, remote: nil)
@@ -2108,7 +2116,9 @@ module Squared
2108
2116
 
2109
2117
  def append_message(val = nil, target: @session)
2110
2118
  val = messageopt if val.to_s.empty?
2111
- target << quote_option('message', val) if val
2119
+ return unless val
2120
+
2121
+ target << quote_option('message', val)
2112
2122
  end
2113
2123
 
2114
2124
  def append_head(val = nil, target: @session)
@@ -2205,6 +2215,10 @@ module Squared
2205
2215
  s.start_with?(/\d/) ? "@~#{s}" : "@#{s}"
2206
2216
  end
2207
2217
 
2218
+ def commitstyle(val)
2219
+ sub_style(val, theme[:extra] || color(:yellow))
2220
+ end
2221
+
2208
2222
  def matchhead(val)
2209
2223
  val =~ /^(?:(?:HEAD|@)([~^]\d*)?|H(\d+))$/ ? $2 || $1 || '' : nil
2210
2224
  end