git_topic 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17b7ec4e03f88c30a17b7bc3200226bbae89b918
4
- data.tar.gz: 3da57e5fa72a110885e67077c544052a1c1b2681
3
+ metadata.gz: a3a1fbd3275258c0fcffe1d33ebbfcc00e4560fb
4
+ data.tar.gz: e8e6eabf616a0fcfcd99cc7cf08753885237cccd
5
5
  SHA512:
6
- metadata.gz: cbe31c7efc9c451e4113e69d9c75a9c3b2d2fae52aad93d61c479a066f29c3212da6f329d3882712f6bda50e71e1ee96b611e3dc59215352490d7ff0171cbcc5
7
- data.tar.gz: 427344fb6beb0968645035d8da75aaac3ddce2f7461b1b51cfaeb9fdd573c8ec15f77b69a6d3d77f2615dab6a1176f1fea18b9868e5d7ef03f3c24a1b937420f
6
+ metadata.gz: e87fa603e0db2ebe0638cb187f9cb6c94c2b7bcd5c83eb4379fda312fb7508d895d2693640e0b569ab3ff134d195b9a8c8f981b3e603d76ad7e2ae58eb54ca52
7
+ data.tar.gz: 50e122a241ba983e2f869dc92f18bc3b888e6fc8341989481deaa0c420c64e21c7eb5d374957eb3f1a7aeae21c2bfc24da7f6f8f8e4edfc7b8f1759aaffc3919
data/.rubocop.yml CHANGED
@@ -1,8 +1,13 @@
1
1
  require: rubocop-rspec
2
2
  AllCops:
3
+ TargetRubyVersion: 2.3
3
4
  Exclude:
4
5
  - 'vendor/**/*'
5
6
  - 'bin/**/*'
6
7
  RSpec:
7
8
  Patterns:
8
9
  - '.+'
10
+
11
+ Metrics/BlockLength:
12
+ Exclude:
13
+ - 'spec/**/*'
data/lib/git_topic/cli.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
  require 'open3'
3
5
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module GitTopic
3
4
  module Commands
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'term/ansicolor'
2
4
 
3
5
  module GitTopic
@@ -6,27 +8,25 @@ module GitTopic
6
8
  class List
7
9
  include Term::ANSIColor
8
10
  def execute
9
- print_header
10
- print_contents
11
+ branches, current_branch = parse_branches
12
+ print_header(branches.first)
13
+ print_contents(branches, current_branch)
11
14
  end
12
15
 
13
16
  private
14
17
 
15
18
  Branch = Struct.new('Branch', :name, :rev)
16
19
 
17
- def print_header
18
- printf " %-20s %-7s %s\n", 'Branch', 'Rev', 'Summary'
20
+ def print_header(branch)
21
+ rev_length = branch.rev.length
22
+ header_format = " %-20s %-#{rev_length}s %s"
23
+ puts format(header_format, :Branch, :Rev, :Summary)
19
24
  puts '-' * 80
20
25
  end
21
26
 
22
- def print_contents
23
- branches, current_branch = parse_branches
27
+ def print_contents(branches, current_branch)
24
28
  branches.each do |branch|
25
- begin
26
- print_line(current_branch, branch)
27
- rescue EOFError => _ex
28
- # nop
29
- end
29
+ print_line(current_branch, branch)
30
30
  end
31
31
  end
32
32
 
@@ -42,33 +42,56 @@ module GitTopic
42
42
  [branches, current_branch]
43
43
  end
44
44
 
45
+ BRANCH_FORMAT = /
46
+ \s*(?<current_exp>\*\ )?
47
+ (?<branch_name>\S+)\s+
48
+ (?<rev>\S+)\s+(.*)
49
+ /x
50
+
45
51
  def parse_branch(line)
46
- matched = line.match(/\s*(\* )?(\S+)\s+(\S+)\s+(.*)/)
52
+ matched = line.match(BRANCH_FORMAT)
47
53
  raise 'cannot parse branch' unless matched
48
- branch_name = matched[2]
49
- current_branch = matched[1] ? branch_name : nil
50
- rev = matched[3]
54
+ branch_name = matched[:branch_name]
55
+ rev = matched[:rev]
56
+ current_branch = matched[:current_exp] ? branch_name : nil
51
57
  [branch_name, rev, current_branch]
52
58
  end
53
59
 
54
60
  def print_line(current_branch, branch)
55
61
  branch_name = branch.name
56
62
  rev = branch.rev
57
- description = get_description_of branch_name
58
- branch_format = if branch_name == current_branch
59
- "* #{green}#{bold}%-20s#{clear}"
60
- else
61
- " #{bold}%-20s#{clear}"
62
- end
63
- printf "#{branch_format} %s %s", branch_name, rev, description
63
+ description = get_description_of branch
64
+ return if description.nil?
65
+ branch_format = branch_format(branch_name, current_branch)
66
+ truncated_name = truncate(branch_name)
67
+ puts format("#{branch_format} %s %s", truncated_name, rev, description)
64
68
  end
65
69
 
66
70
  def get_description_of(branch)
67
- config_key = "branch.#{branch}.description"
71
+ config_key = "branch.#{branch.name}.description"
68
72
  command = "git config #{config_key}"
69
73
  _stdin, stdout, _stderr, _wait_thr = *Open3.popen3(command)
74
+ return nil if stdout.eof?
70
75
  stdout.readline
71
76
  end
77
+
78
+ def branch_format(branch_name, current_branch)
79
+ if branch_name == current_branch
80
+ "* #{green}#{bold}%-20s#{clear}"
81
+ else
82
+ " #{bold}%-20s#{clear}"
83
+ end
84
+ end
85
+
86
+ def truncate(str, truncate_at: 20)
87
+ omission = '...'
88
+ length_with_room_for_omission = truncate_at - omission.length
89
+ if str.length > truncate_at
90
+ "#{str[0, length_with_room_for_omission]}#{omission}"
91
+ else
92
+ str
93
+ end
94
+ end
72
95
  end
73
96
  end
74
97
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module GitTopic
3
4
  module Commands
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitTopic
2
- VERSION = '0.2.4'.freeze
4
+ VERSION = '0.2.5'
3
5
  end
data/lib/git_topic.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'git_topic/version'
2
4
  require 'git_topic/cli'
3
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_topic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroki Kondo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-25 00:00:00.000000000 Z
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor