git_curate 1.0.2 → 1.1.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: 50f00058b5232e499100bf5a03447ed891a640c3efb8b9c1ce9adae50bf84b02
4
- data.tar.gz: bb443922c86047f3356e01eb160e83cbed0eb3ff8038826d03d2de3baef81f7b
3
+ metadata.gz: 6aa1d8d2c88d0f8d13be7d60fe85d74eaeaf9dbb86e45405936fd00fc72dc538
4
+ data.tar.gz: f6e4249ab9a8dae3d505102785c6c946703486cbf730f67d0b120bd038b182ce
5
5
  SHA512:
6
- metadata.gz: 699f1b52fd674860eb71c8fc3c9eb4b43d8fbc884f5616d48781d965de50702ef910e6bea2d57b9bdd88a0f63c6aae976f497ab8de3a7a7819b1841edc0ef7a4
7
- data.tar.gz: 100ec40a8f8a23ebcef141c7ef7bd4df970719a7e0c9e76ebde4c8bf9d823a9c36a3010cc3732442e29bf2c714bb909eb9ff83f88ac5ba43063ebd0b8aa024fd
6
+ metadata.gz: f5f0452a0548356888aa03caec3638a8ea28d15bff2aca56fb18ff29908c00d13d7cc0df4e9c7ed1a76ef9f5fb20227a33b52f5a2e27c0fdf939eeba025e3005
7
+ data.tar.gz: 992422984592b999295f4d4ec09af8f97b5d0b02e3ee506506393344e88ad947344d5e09152780fe5969ee2dd8ee3caa28c291c6ad57c4ba7e462814a1349dbe
@@ -1,4 +1,3 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.4.9
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ### v1.1.0
4
+
5
+ #### Change that may be breaking for an obscure use case
6
+
7
+ * Output more helpful message in case there are no deletable branches when `git curate` run without `-l`/`--list` flag.
8
+
9
+ This will be a breaking change but only in the unlikely event that the output of `git curate` is being piped
10
+ through or processed by another program when run in _interactive_ (non-`--list`) mode.
11
+
12
+ _New behaviour when there are no deletable branches:_
13
+ Outputs `There are no local branches that can be deleted.`
14
+
15
+ _Old behaviour when there are no deletable branches:_
16
+ Outputs (irrelevantly and confusingly) the legend of interactive commands, followed by the message
17
+ `No branches deleted.`
18
+
19
+ ### v1.0.2
20
+
21
+ * Fix incorrect status-vs-upstream when commit subject begins with square-bracket-enclosed string.
22
+
3
23
  ### v1.0.1
4
24
 
5
25
  * Fix `fatal: bad revision '+'` error on encountering multiple worktrees.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.1.0
@@ -1,18 +1,15 @@
1
1
  module GitCurate
2
2
 
3
+ UpstreamInfo = Struct.new(:upstream, :status)
4
+
3
5
  class Branch
4
6
 
5
7
  # Regex for determining whether a "raw" branch name is the name of the current branch
6
8
  # on this or another worktree.
7
9
  CURRENT_BRANCH_REGEX = /^[+*]\s+/
8
10
 
9
- # Regexes for unpacking the output of `git branch -vv`
10
- BRANCH_NAME_REGEX = /\s+/
11
- LEADING_STAR_REGEX = /^\* /
12
- LEADING_PLUS_REGEX = /^\+ /
13
- REMOTE_INFO_REGEX = /^[^\s]+\s+[^\s]+\s+(\(.+\)\s+)?\[(?<remote_info>[^\]]+)\]/
14
-
15
- # Returns the branch name, with "* " prefixed if it's the current branch.
11
+ # Returns the branch name, with "* " prefixed if it's the current branch on the current
12
+ # worktree, or "+ " if it's the current branch on another worktree.
16
13
  attr_reader :raw_name
17
14
 
18
15
  # Returns a human-friendly string describing the status of the branch relative to the upstream branch
@@ -81,35 +78,29 @@ module GitCurate
81
78
  # a brief description of each branch's status relative to its upstream branch (up to
82
79
  # date, or ahead/behind).
83
80
  def self.branch_info
84
- command_0 = "git for-each-ref --format='%(refname:short) .. %(upstream:short)' refs/heads"
85
- command_1 = "git branch -vv"
86
-
87
- branches_with_remotes = Util.command_to_a(command_0).map do |line|
88
- parts = line.split(" .. ")
89
- [parts[0], parts[1] || nil]
81
+ # Double quotes around the format string to ensure Windows compatibility.
82
+ command = 'git for-each-ref --format="%(refname:short) .. %(upstream:short) .. %(upstream:track)" refs/heads'
83
+ branches_with_remotes = Util.command_to_a(command).map do |line|
84
+ parts = line.split("..", -1).map { |s| s.strip! ; s.empty? ? nil : s }
85
+ [parts[0], UpstreamInfo.new(parts[1], parts[2])]
90
86
  end.to_h
91
87
 
92
- info = Util.command_to_a(command_1).map do |line|
93
- line_is_current_branch = (line =~ CURRENT_BRANCH_REGEX)
94
- tidied_line = (line_is_current_branch ? line.gsub(CURRENT_BRANCH_REGEX, "") : line)
95
- proper_branch_name = tidied_line.split(BRANCH_NAME_REGEX)[0]
96
- raw_branch_name =
97
- if line =~ LEADING_STAR_REGEX
98
- "* #{proper_branch_name}"
99
- elsif line =~ LEADING_PLUS_REGEX
100
- "+ #{proper_branch_name}"
101
- else
102
- proper_branch_name
103
- end
104
- upstream_info =
105
- if branches_with_remotes[proper_branch_name]
106
- remote_info = tidied_line[REMOTE_INFO_REGEX, :remote_info]
107
- comparison_raw = remote_info.split(":")
108
- comparison_raw.length < 2 ? "Up to date" : comparison_raw[1].strip.capitalize
88
+ info = Util.command_to_a("git branch").map do |line|
89
+ raw_branch_name = line.strip
90
+ proper_branch_name = raw_branch_name.gsub(CURRENT_BRANCH_REGEX, "")
91
+ upstream_info = branches_with_remotes[proper_branch_name]
92
+ upstream_data =
93
+ if upstream_info.upstream
94
+ status = upstream_info.status
95
+ if status
96
+ status.gsub(/^\[/, "").gsub(/\]$/, "").capitalize
97
+ else
98
+ "Up to date"
99
+ end
109
100
  else
110
101
  "No upstream"
111
102
  end
112
- [raw_branch_name, upstream_info]
103
+ [raw_branch_name, upstream_data]
113
104
  end
114
105
 
115
106
  info.to_h
@@ -26,17 +26,11 @@ module GitCurate
26
26
  return EXIT_FAILURE
27
27
  end
28
28
 
29
- if interactive?
30
- puts
31
- print_help
32
- puts
33
- end
34
-
35
29
  branches = Branch.local
36
30
  branches.reject!(&:current?) if interactive?
37
31
 
38
32
  table = Tabulo::Table.new(branches, border: :reduced_ascii, column_padding: 0, align_header: :left) do |t|
39
- t.add_column(:branch, header: "Branch") { |b| b.displayable_name(pad: !interactive?) }
33
+ t.add_column("Branch") { |b| b.displayable_name(pad: !interactive?) }
40
34
  t.add_column("Last commit:#{$/}Date", &:last_commit_date)
41
35
  t.add_column("#{$/}Hash", &:hash)
42
36
  t.add_column("#{$/}Author", &:last_author)
@@ -57,6 +51,15 @@ module GitCurate
57
51
  return EXIT_SUCCESS
58
52
  end
59
53
 
54
+ if branches.empty?
55
+ puts "There are no local branches that can be deleted."
56
+ return EXIT_SUCCESS
57
+ end
58
+
59
+ puts
60
+ print_help
61
+ puts
62
+
60
63
  table.each_with_index do |row, index|
61
64
  case HighLine.ask("#{row} #{prompt}").downcase
62
65
  when "d"
@@ -1,3 +1,3 @@
1
1
  module GitCurate
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.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: 1.0.2
4
+ version: 1.1.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: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2020-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline