git_curate 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 354154ef2b612e1b4831e2c42296317782e313286ea8686e039d8a96b406c4bc
4
- data.tar.gz: ec34593d4e28187ab7d6e9aa45dbf5aa9e5689e2075427034e19738cb70e3357
3
+ metadata.gz: e1c8358c5021c6985ce3e6d701d607a2df341cc4ed2ba20dac43c13912a1fe44
4
+ data.tar.gz: c30b0e19d28f7ae48e5fb59372da44158940b8b79008c9d2a07f3b3e8d7d6534
5
5
  SHA512:
6
- metadata.gz: 8fbb8bfce7b43df4eafc43933fe88fdaf283940475f3c2b6fb665f8c62d1ce2a044e6938850e10e789b9df757662d8353535411eedf7caa1842d4a1e0c837fff
7
- data.tar.gz: 1bb25f41bb89503970202c6169dfeac3c5f7e957fb5227347f8fd0ca665d480f43846205316b1ea21c03cad76241e64a9b7c8681984e225417275000881aff3d
6
+ metadata.gz: 2a872d7d0555cab6a4d4df1d33c96cda3cce1952c09cda057816065e81a7af65c033196365ed0207a255c5cf9c0b190cd500376ca8620b9738084b683064e88c
7
+ data.tar.gz: 8e842c8f27654e625bcc9b895064a49764c6d67fd0c0b340c8ba900bcd6ad0850b66c836158e08fab0f04d03a3cd98b6dba6c38e84472ab7aa6c97c1db80b72c
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### v0.4.0
4
+
5
+ * Add "Status vs upstream" column.
6
+
3
7
  ### v0.3.0
4
8
 
5
9
  * Add "Merged into HEAD?" column.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git_curate (0.3.0)
4
+ git_curate (0.4.0)
5
5
  highline (= 2.0.0)
6
6
  tabulo (= 1.2.0)
7
7
 
data/README.md CHANGED
@@ -12,9 +12,15 @@ can't always remember which branches I want to keep from the branch names alone;
12
12
  one at a time and _then_ running `git branch -D` in a separate step, is painful.
13
13
 
14
14
  `git curate` is intended to ease this pain. It steps you through the local branches of a repo one at
15
- a time, outputting a small amount of information about each branch (last commit date, author and
16
- summary, and whether the branch has been merged into the current HEAD), and prompting you either to
17
- keep or to delete each branch as you go.
15
+ a time, outputting the following information about each:
16
+
17
+ * Last commit date
18
+ * Last commit author
19
+ * Last commit subject
20
+ * Whether the branch has been merged into the current HEAD
21
+ * The status of the branch relative to the upstream branch it is tracking (if any)
22
+
23
+ You can then select whether to delete or keep each branch as you go.
18
24
 
19
25
  ## Installation
20
26
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
Binary file
@@ -1,5 +1,9 @@
1
1
  module GitCurate
2
2
 
3
+ # Regexes for unpacking the output of `git branch -vv`
4
+ BRANCH_NAME_REGEX = /\s+/
5
+ REMOTE_INFO_REGEX = /^[^\s]+\s+[^\s]+\s+\[(.+?)\]/
6
+
3
7
  class Runner
4
8
 
5
9
  def run
@@ -10,6 +14,7 @@ module GitCurate
10
14
 
11
15
  branches = command_to_a("git branch").reject { |b| current_branch?(b) }
12
16
  merged_branches = command_to_a("git branch --merged").reject { |b| current_branch?(b) }.to_set
17
+ upstreams = upstream_branches
13
18
 
14
19
  table = Tabulo::Table.new(branches, vertical_rule_character: " ", intersection_character: " ",
15
20
  horizontal_rule_character: "-", column_padding: 0) do |t|
@@ -28,17 +33,21 @@ module GitCurate
28
33
  `git log -n1 --format='format:%s' #{branch}`
29
34
  end
30
35
 
31
- t.add_column("Merged into HEAD?", align_header: :left) do |branch|
36
+ t.add_column("Merged\ninto HEAD?", align_header: :left) do |branch|
32
37
  merged_branches.include?(branch) ? "Merged" : "Not merged"
33
38
  end
39
+
40
+ t.add_column("Status vs\nupstream", align_header: :left) do |branch|
41
+ upstreams.fetch(branch, "No upstream")
42
+ end
34
43
  end
35
44
 
36
- table.shrinkwrap!(max_table_width: 125)
45
+ table.shrinkwrap!(max_table_width: 150)
37
46
 
38
47
  branches_to_delete = []
39
48
 
40
49
  table.each_with_index do |row, index|
41
- case HighLine.ask("#{row} Mark for deletion? [y/n/done/abort/help] ")
50
+ case HighLine.ask("#{row} Delete? [y/n/done/abort/help] ")
42
51
  when "y"
43
52
  branches_to_delete << row.to_h[:branch]
44
53
  when "n"
@@ -69,6 +78,27 @@ module GitCurate
69
78
  branch =~ /^\s*\*/
70
79
  end
71
80
 
81
+ # Returns a Hash containing, as keys, all local branches that have upstream branches (excluding
82
+ # the current branch) and, as values, a brief description of each branch's status relative
83
+ # to its upstream branch (up to date, or ahead/behind)
84
+ def upstream_branches
85
+ command_to_a("git branch -vv").map do |line|
86
+ branch_name = line.split(BRANCH_NAME_REGEX)[0]
87
+ remote_info = line[REMOTE_INFO_REGEX, 1]
88
+ if remote_info.nil?
89
+ nil
90
+ else
91
+ comparison_raw = remote_info.split(":")
92
+ comparison = if comparison_raw.length < 2
93
+ "Up to date"
94
+ else
95
+ comparison_raw[1].strip.capitalize
96
+ end
97
+ [branch_name, comparison]
98
+ end
99
+ end.compact.to_h
100
+ end
101
+
72
102
  def finalize(branches_to_delete)
73
103
  if branches_to_delete.size != 0
74
104
  puts
@@ -1,3 +1,3 @@
1
1
  module GitCurate
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_curate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Harvey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-10 00:00:00.000000000 Z
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline