git_curate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b04d1e90854a31309b1d855ea8cdc160f5b6851
4
+ data.tar.gz: 8bf174d834ab459759ce18b99e5722cec584fb58
5
+ SHA512:
6
+ metadata.gz: 8a11b25d6351456b6f809dadfa881233e2d11f7fb8af6d20651fde5f5a5b97be329a99d76ad4246a53a395d20b015f63c8f9e2ca4e831f9e6e44ad6ca12a7b16
7
+ data.tar.gz: 5ced0a0962b42a679e00132b8fd84eae48eab1e23fb0b69a9aad88332b9fc1dc15069fc6865d20c33926df9a6656b13dd8c614197ec1eaa561eab4da0ebd0164
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ **/.*.swp
10
+ coverage
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in git_curate.gemspec
6
+ gemspec
7
+
8
+ gem "highline"
9
+ gem "tabulo"
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_curate (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ highline (2.0.0)
10
+ rake (11.3.0)
11
+ tabulo (1.2.0)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.16)
18
+ git_curate!
19
+ highline
20
+ rake (~> 11.0)
21
+ tabulo
22
+
23
+ BUNDLED WITH
24
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Matthew Harvey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # git curate
2
+
3
+ ## Motivation
4
+
5
+ After a while, my local repo becomes full of branches, and `git branch` outputs an awkwardly long
6
+ list. I want to delete some of those branches to bring that list back under control; but I
7
+ can't always remember which branches are which from the name alone, and inspecting them one at a
8
+ time and _then_ running `git branch -D` in a separate step, is painful.
9
+
10
+ I wrote `git curate` to ease this pain. It steps through the local branches of a repo one at a
11
+ time, outputting a small amount of information about each branch (author, last commit date and
12
+ last commit summary), and prompting you to either keep or delete each branch as you go.
13
+
14
+ ## Installation
15
+
16
+ ```
17
+ gem install git_curate
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ From within a git repo, run:
23
+
24
+ ```
25
+ git curate
26
+ ```
27
+
28
+ This will step you through your local branches one at a time, prompting you whether to keep or
29
+ delete each branch in what should be a self-explanatory fashion.
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies.
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/matt-harvey/tabulo.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT
42
+ License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/git-curate ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "git_curate"
4
+
5
+ runner = GitCurate::Runner.new
6
+ runner.run
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "git_curate/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git_curate"
8
+ spec.version = GitCurate::VERSION
9
+ spec.authors = ["Matthew Harvey"]
10
+ spec.email = ["software@matthewharvey.net"]
11
+
12
+ spec.summary = "Simple git branch curation tool"
13
+ spec.description = "Step through local git branches from the command line, keeping or deleting each."
14
+ spec.homepage = "https://github.com/matt-harvey/git_curate"
15
+ spec.license = "MIT"
16
+
17
+ spec.metadata = {
18
+ "source_code_uri" => "https://github.com/matt-harvey/git_curate",
19
+ "changelog_uri" => "https://raw.githubusercontent.com/matt-harvey/git_curate/master/CHANGELOG.md"
20
+ }
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
+ f.match(%r{^(test|spec|features)/})
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.16"
30
+ spec.add_development_dependency "rake", "~> 11.0"
31
+ end
data/lib/git_curate.rb ADDED
@@ -0,0 +1,94 @@
1
+ require "git_curate/version"
2
+ require "highline/import"
3
+ require "tabulo"
4
+
5
+ module GitCurate
6
+
7
+ class Runner
8
+
9
+ def run
10
+ if ARGV.length != 0
11
+ puts "This script does not accept any arguments."
12
+ exit
13
+ end
14
+
15
+ branches = `git branch`.split($/).reject { |b| current_branch?(b) }.map(&:strip)
16
+
17
+ table = Tabulo::Table.new(branches, vertical_rule_character: " ", intersection_character: " ",
18
+ horizontal_rule_character: "-", column_padding: 0) do |t|
19
+
20
+ t.add_column(:branch, header: "Branch", align_header: :left) { |branch| branch }
21
+
22
+ t.add_column("Last commit date", align_header: :left) do |branch|
23
+ `git log -n1 --date=short --format='format:%cd' #{branch}`
24
+ end
25
+
26
+ t.add_column("Last commit author", align_header: :left) do |branch|
27
+ `git log -n1 --format='format:%an' #{branch}`
28
+ end
29
+
30
+ t.add_column("Last commit subject", align_header: :left) do |branch|
31
+ `git log -n1 --format='format:%s' #{branch}`
32
+ end
33
+ end
34
+
35
+ table.shrinkwrap!(max_table_width: 200)
36
+
37
+ branches_to_delete = []
38
+
39
+ table.each_with_index do |row, index|
40
+ case HighLine.ask("#{row} Mark for deletion? [y/n/done/abort/help] ")
41
+ when "y"
42
+ branches_to_delete << row.to_h[:branch]
43
+ when "n"
44
+ ; # do nothing
45
+ when "done"
46
+ puts table.horizontal_rule
47
+ finalize(branches_to_delete)
48
+ exit
49
+ when "abort"
50
+ puts table.horizontal_rule
51
+ puts "\nAborting. No branches deleted."
52
+ exit
53
+ else
54
+ puts table.horizontal_rule
55
+ print_help
56
+ puts table.horizontal_rule unless index == 0
57
+ redo
58
+ end
59
+ end
60
+ puts table.horizontal_rule
61
+
62
+ finalize(branches_to_delete)
63
+ end
64
+
65
+ private
66
+
67
+ def current_branch?(branch)
68
+ branch =~ /^\s*\*/
69
+ end
70
+
71
+ def finalize(branches_to_delete)
72
+ if branches_to_delete.size != 0
73
+ puts
74
+ system("git branch -D #{branches_to_delete.join(" ")}")
75
+ puts "\nDone"
76
+ else
77
+ puts "\nNo branches deleted."
78
+ end
79
+ end
80
+
81
+ def print_help
82
+ puts <<-EOL
83
+ Please enter one of:
84
+ y -- mark branch for deletion
85
+ n -- keep branch
86
+ done -- delete marked branches and exit session
87
+ abort -- abort without deleting any branches
88
+ help -- print this help message
89
+ EOL
90
+ end
91
+
92
+ end
93
+
94
+ end
@@ -0,0 +1,3 @@
1
+ module GitCurate
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_curate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Harvey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.0'
41
+ description: Step through local git branches from the command line, keeping or deleting
42
+ each.
43
+ email:
44
+ - software@matthewharvey.net
45
+ executables:
46
+ - git-curate
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/setup
57
+ - exe/git-curate
58
+ - git_curate.gemspec
59
+ - lib/git_curate.rb
60
+ - lib/git_curate/version.rb
61
+ homepage: https://github.com/matt-harvey/git_curate
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ source_code_uri: https://github.com/matt-harvey/git_curate
66
+ changelog_uri: https://raw.githubusercontent.com/matt-harvey/git_curate/master/CHANGELOG.md
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.5.1
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Simple git branch curation tool
87
+ test_files: []