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 +4 -4
- data/.rubocop.yml +5 -0
- data/lib/git_topic/cli.rb +2 -0
- data/lib/git_topic/commands/edit.rb +1 -0
- data/lib/git_topic/commands/list.rb +46 -23
- data/lib/git_topic/commands/show.rb +1 -0
- data/lib/git_topic/version.rb +3 -1
- data/lib/git_topic.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3a1fbd3275258c0fcffe1d33ebbfcc00e4560fb
|
4
|
+
data.tar.gz: e8e6eabf616a0fcfcd99cc7cf08753885237cccd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e87fa603e0db2ebe0638cb187f9cb6c94c2b7bcd5c83eb4379fda312fb7508d895d2693640e0b569ab3ff134d195b9a8c8f981b3e603d76ad7e2ae58eb54ca52
|
7
|
+
data.tar.gz: 50e122a241ba983e2f869dc92f18bc3b888e6fc8341989481deaa0c420c64e21c7eb5d374957eb3f1a7aeae21c2bfc24da7f6f8f8e4edfc7b8f1759aaffc3919
|
data/.rubocop.yml
CHANGED
data/lib/git_topic/cli.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
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
|
-
|
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
|
-
|
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(
|
52
|
+
matched = line.match(BRANCH_FORMAT)
|
47
53
|
raise 'cannot parse branch' unless matched
|
48
|
-
branch_name = matched[
|
49
|
-
|
50
|
-
|
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
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
data/lib/git_topic/version.rb
CHANGED
data/lib/git_topic.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2017-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|