git_curate 1.0.1 → 1.0.2

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: 32a05c73884f0ccb28a0c77fbecce6aa123c866b8de6a519fd1dc02f5ae81475
4
- data.tar.gz: fa8f0967a63ceb77a4cd325d47e9306882f1de712d656b63ccb6936386ecbc6d
3
+ metadata.gz: 50f00058b5232e499100bf5a03447ed891a640c3efb8b9c1ce9adae50bf84b02
4
+ data.tar.gz: bb443922c86047f3356e01eb160e83cbed0eb3ff8038826d03d2de3baef81f7b
5
5
  SHA512:
6
- metadata.gz: a229f824eabb501d718b0533041c7308536fb939219391544b6cca176e5c278e52a0951d14d897142737226175e1911057c7306b430ca0e8752b2b6c920b8e38
7
- data.tar.gz: e9166c2594376faeb422fbb4936d788249b59d5b6af530edd655c5f24d9be566615326337b490fb3185df50e1d1d0753bf8bf86d7bb6e55d0521409f43557520
6
+ metadata.gz: 699f1b52fd674860eb71c8fc3c9eb4b43d8fbc884f5616d48781d965de50702ef910e6bea2d57b9bdd88a0f63c6aae976f497ab8de3a7a7819b1841edc0ef7a4
7
+ data.tar.gz: 100ec40a8f8a23ebcef141c7ef7bd4df970719a7e0c9e76ebde4c8bf9d823a9c36a3010cc3732442e29bf2c714bb909eb9ff83f88ac5ba43063ebd0b8aa024fd
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  After a while, my local repo becomes cluttered with branches, and `git branch` outputs an awkwardly
13
13
  long list. I want to delete some of those branches to bring that list back under control; but I
14
- can't always remember which branches I want to keep from the branch names alone; and inspecting them
14
+ can’t always remember which branches I want to keep from the branch names alone; and inspecting them
15
15
  one at a time and _then_ running `git branch -D` in a separate step, is painful.
16
16
 
17
17
  `git curate` is intended to ease this pain. It steps you through the local branches of a repo one at
@@ -27,12 +27,12 @@ a time, outputting the following information about each:
27
27
  You can then select whether to delete or keep each branch as you go.
28
28
 
29
29
  **NOTE** `git curate` does _not_ run `git fetch` prior to generating its output. If you want to
30
- be sure that the "Status vs upstream" column reflects the latest state of the upstream branches
30
+ be sure that the “Status vs upstream” column reflects the latest state of the upstream branches
31
31
  as per their remote repository, you should run `git fetch` first.
32
32
 
33
33
  ## Installation
34
34
 
35
- You'll need Ruby (v2.4.9 or greater) installed. Run:
35
+ You’ll need Ruby (v2.4.9 or greater) installed. Run:
36
36
 
37
37
  ```
38
38
  gem install git_curate
@@ -51,15 +51,16 @@ git curate
51
51
  This will step you through your local branches one at a time, outputting some information about
52
52
  each, and asking you whether to keep or delete each branch.
53
53
 
54
- At each branch, enter "k"—or simply press Enter—to _keep_ the branch and move to the next one;
55
- or enter "d" to select the branch for deletion.
54
+ At each branch, enter “k”—or simply press Enter—to _keep_ the branch and move to the next one;
55
+ or enter “d” to select the branch for deletion.
56
56
 
57
- Entering "e" will end the session immediately, deleting all selected branches; and "a" will
57
+ Entering “e” will end the session immediately, deleting all selected branches; and “a” will
58
58
  abort the session without deleting any branches. Once the final branch has been considered,
59
59
  any selected branches will be immediately deleted.
60
60
 
61
61
  Note the branch you are currently on will not be included in the list, as `git` does not allow you to delete
62
- the branch you're on.
62
+ the branch you’re on. (The same applies to any branches that are currently checked out in other
63
+ [worktrees](https://git-scm.com/docs/git-worktree).)
63
64
 
64
65
  If you just want to view the information about your local branches without stepping through
65
66
  them interactively, enter `git curate --list` or `git curate -l`. Your current branch _will_
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -10,7 +10,7 @@ module GitCurate
10
10
  BRANCH_NAME_REGEX = /\s+/
11
11
  LEADING_STAR_REGEX = /^\* /
12
12
  LEADING_PLUS_REGEX = /^\+ /
13
- REMOTE_INFO_REGEX = /^[^\s]+\s+[^\s]+\s+(\(.+\)\s+)?\[(?<remote_info>.+)\]/
13
+ REMOTE_INFO_REGEX = /^[^\s]+\s+[^\s]+\s+(\(.+\)\s+)?\[(?<remote_info>[^\]]+)\]/
14
14
 
15
15
  # Returns the branch name, with "* " prefixed if it's the current branch.
16
16
  attr_reader :raw_name
@@ -24,19 +24,8 @@ module GitCurate
24
24
  @proper_name ||= @raw_name.lstrip.sub(CURRENT_BRANCH_REGEX, '')
25
25
  end
26
26
 
27
- # Returns truthy if and only if this is the currently checked out branch on the current
28
- # worktree.
29
- def current_branch_this_worktree?
30
- @current_branch_this_worktree ||= (@raw_name =~ LEADING_STAR_REGEX)
31
- end
32
-
33
- # Returns truthy if and only if this is the currently checked out branch on another worktree.
34
- def current_branch_other_worktree?
35
- @current_branch_other_worktree ||= (@raw_name =~ LEADING_PLUS_REGEX)
36
- end
37
-
38
27
  def current?
39
- current_branch_this_worktree? || current_branch_other_worktree?
28
+ @current ||= (@raw_name =~ CURRENT_BRANCH_REGEX)
40
29
  end
41
30
 
42
31
  # Return truthy if and only if this branch has been merged into the current HEAD.
@@ -92,7 +81,15 @@ module GitCurate
92
81
  # a brief description of each branch's status relative to its upstream branch (up to
93
82
  # date, or ahead/behind).
94
83
  def self.branch_info
95
- Util.command_to_a("git branch -vv").map do |line|
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]
90
+ end.to_h
91
+
92
+ info = Util.command_to_a(command_1).map do |line|
96
93
  line_is_current_branch = (line =~ CURRENT_BRANCH_REGEX)
97
94
  tidied_line = (line_is_current_branch ? line.gsub(CURRENT_BRANCH_REGEX, "") : line)
98
95
  proper_branch_name = tidied_line.split(BRANCH_NAME_REGEX)[0]
@@ -104,16 +101,18 @@ module GitCurate
104
101
  else
105
102
  proper_branch_name
106
103
  end
107
- remote_info = tidied_line[REMOTE_INFO_REGEX, :remote_info]
108
104
  upstream_info =
109
- if remote_info.nil?
110
- "No upstream"
111
- else
105
+ if branches_with_remotes[proper_branch_name]
106
+ remote_info = tidied_line[REMOTE_INFO_REGEX, :remote_info]
112
107
  comparison_raw = remote_info.split(":")
113
108
  comparison_raw.length < 2 ? "Up to date" : comparison_raw[1].strip.capitalize
109
+ else
110
+ "No upstream"
114
111
  end
115
112
  [raw_branch_name, upstream_info]
116
- end.to_h
113
+ end
114
+
115
+ info.to_h
117
116
  end
118
117
 
119
118
  def self.delete_multi(*branches)
@@ -1,3 +1,3 @@
1
1
  module GitCurate
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
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.1
4
+ version: 1.0.2
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-01 00:00:00.000000000 Z
11
+ date: 2020-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline