git-cleanup 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/git-cleanup CHANGED
@@ -1,3 +1,35 @@
1
1
  require 'git-cleanup'
2
+ require 'optparse'
2
3
 
3
- GitCleanup.run
4
+ trap("INT") {
5
+ Formatador.redisplay("[bold][yellow]No more cleanup[/]\n")
6
+ exit(1)
7
+ }
8
+
9
+ conf = {
10
+ :skip_unmerged => false
11
+ }
12
+
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = "Usage: git-cleanup [OPTIONS] -- ... commands"
15
+ opts.on("-s", "--skip-unmerged", "Unmerge branches will be skipped") do |u|
16
+ conf[:skip_unmerged] = true
17
+ end
18
+ opts.on("-v", "--version", "Shows version") do
19
+ puts GitCleanup::VERSION
20
+ exit
21
+ end
22
+ opts.on("-h", "--help", "Shows this help") do
23
+ puts opts
24
+ exit
25
+ end
26
+ end
27
+
28
+ begin
29
+ opts.parse!(ARGV)
30
+ rescue OptionParser::ParseError => ex
31
+ $stderr.puts ex
32
+ exit 1
33
+ end
34
+
35
+ GitCleanup.run(conf)
data/git-cleanup.gemspec CHANGED
@@ -1,9 +1,10 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
+ require "git-cleanup/version"
3
4
 
4
5
  Gem::Specification.new do |s|
5
6
  s.name = "git-cleanup"
6
- s.version = "0.1.3"
7
+ s.version = GitCleanup::VERSION
7
8
  s.platform = Gem::Platform::RUBY
8
9
  s.authors = ["Martyn Loughran"]
9
10
  s.email = ["me@mloughran.com"]
@@ -12,6 +13,7 @@ Gem::Specification.new do |s|
12
13
  s.description = %q{Command line tool for interactively cleaning up old git branches (remotely and locally)}
13
14
 
14
15
  s.add_dependency 'grit', '~> 2.2.0'
16
+ s.add_dependency 'formatador', '~> 0.2.1'
15
17
 
16
18
  s.files = `git ls-files`.split("\n")
17
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/lib/git-cleanup.rb CHANGED
@@ -1,15 +1,22 @@
1
1
  require 'grit'
2
2
  require 'tempfile'
3
-
3
+ require 'formatador'
4
4
  # Grit.debug = true
5
5
 
6
+ # No default indent
7
+ class Formatador
8
+ def initialize
9
+ @indent = 0
10
+ end
11
+ end
12
+
6
13
  class GitCleanup
7
- def self.run
14
+ def self.run(options = {})
8
15
  repo = Grit::Repo.new(Dir.pwd)
9
16
 
10
17
  master = repo.heads.find { |h| h.name == 'master' }
11
18
 
12
- # self.prune(repo)
19
+ self.prune(repo)
13
20
 
14
21
  local_branches = repo.branches.map { |b| b.name }
15
22
 
@@ -23,28 +30,39 @@ class GitCleanup
23
30
  commits = branch.commits(master)
24
31
 
25
32
  msg = "Branch #{branch.to_s} (#{index+1}/#{remote_branches.size})"
26
- puts
27
- puts msg
28
- puts '-' * msg.size
29
- puts "Latest commits:\n"
30
- puts commits
33
+ Formatador.display_line
34
+
35
+ Formatador.display_line("[bold][green]#{msg}[/]")
36
+ Formatador.display_line "[bold][green]" + '-' * msg.size + "[/]"
31
37
 
32
38
  if diff.empty?
39
+ Formatador.display_line "Branch merged. Last commit on branch:"
33
40
  last_commit = branch.commit
34
41
  if last_commit
35
- puts "Last commit:"
36
- puts "Author: #{last_commit.author}"
37
- puts "Date: #{last_commit.committed_date}"
38
- puts "SHA: #{last_commit.sha}"
39
- puts "#{last_commit.message}"
40
- puts
42
+ Formatador.indent {
43
+ Formatador.display_line "Author: #{last_commit.author}"
44
+ Formatador.display_line "Date: #{last_commit.committed_date}"
45
+ Formatador.display_line "SHA: #{last_commit.sha}"
46
+ Formatador.display_line "#{last_commit.message}"
47
+ }
41
48
  end
42
49
 
43
- Helper.boolean 'All commits merged. Do you want the branch deleted?' do
50
+ Helper.boolean 'Do you want the branch deleted?' do
44
51
  branch.delete(local_branches)
45
52
  end
46
53
  else
47
- Helper.boolean "Branch not merged. Do you want to see a diff?" do
54
+ if options[:skip_unmerged]
55
+ Helper.info "Branch not merged. Skipped"
56
+ next
57
+ end
58
+
59
+ Formatador.display_line "Branch not merged. Commits on branch:"
60
+
61
+ Formatador.indent {
62
+ Formatador.display_lines commits.split("\n")
63
+ }
64
+
65
+ Helper.boolean "Do you want to see a diff?" do
48
66
  Tempfile.open('diff') do |tempfile|
49
67
  tempfile << diff
50
68
  tempfile.flush
@@ -52,7 +70,7 @@ class GitCleanup
52
70
  if ENV["GIT_EDITOR"]
53
71
  `#{ENV["GIT_EDITOR"]} #{tempfile.path}`
54
72
  else
55
- puts diff
73
+ Formatador.display_line diff
56
74
  end
57
75
  end
58
76
  Helper.boolean "Do you want the branch deleted?" do
@@ -66,7 +84,7 @@ class GitCleanup
66
84
  # Prunes branches that have already been removed on origin
67
85
  def self.prune(repo)
68
86
  list = repo.git.native(:remote, {}, 'prune', '-n', "origin")
69
- if list.any?
87
+ if !list.empty?
70
88
  Helper.boolean "Planning to prune the following. Ok?\n#{list}" do
71
89
  repo.git.native(:remote, {}, 'prune', "origin")
72
90
  end
@@ -76,3 +94,4 @@ end
76
94
 
77
95
  require 'git-cleanup/branch'
78
96
  require 'git-cleanup/helper'
97
+ require 'git-cleanup/version'
@@ -11,7 +11,7 @@ class GitCleanup
11
11
  def initialize(repo, ref)
12
12
  @repo = repo
13
13
  @ref = ref
14
- @remote, @name = ref.name.split('/')
14
+ @remote, @name = ref.name.split('/', 2)
15
15
  end
16
16
 
17
17
  def to_s
@@ -31,15 +31,15 @@ class GitCleanup
31
31
  end
32
32
 
33
33
  def delete(local_branches = nil)
34
- puts "Deleting..."
34
+ Formatador.display('[red]Deleting...[/]')
35
35
  @repo.git.native(:push, {}, @remote, ":#{@name}")
36
- puts "Done"
36
+ Formatador.display_line('[red]done[/]')
37
37
 
38
38
  if local_branches && local_branches.include?(name)
39
39
  Helper.boolean "There is also a local branch called #{name}. Would you like to delete that too?" do
40
- puts "Deleting..."
41
- @repo.git.native(:branch, {}, '-d', name)
42
- puts "Done"
40
+ Formatador.display('[red]Deleting...[/]')
41
+ @repo.git.native(:branch, {}, '-d', name)
42
+ Formatador.display_line('[red]done[/]')
43
43
  end
44
44
  end
45
45
  end
@@ -1,7 +1,8 @@
1
1
  class GitCleanup
2
2
  module Helper
3
3
  def self.boolean(question, &block)
4
- puts "#{question} (y/n)"
4
+ Formatador.display_line ""
5
+ Formatador.display("[bold][blue][QUESTION][/] #{question} (y/n)[/] ")
5
6
  answer = STDIN.gets.chomp
6
7
  if answer == 'y'
7
8
  yield
@@ -11,5 +12,9 @@ class GitCleanup
11
12
  boolean(question, &block)
12
13
  end
13
14
  end
15
+
16
+ def self.info(info)
17
+ Formatador.display_line "[bold][yellow][INFO][/] #{info}[/]"
18
+ end
14
19
  end
15
20
  end
@@ -0,0 +1,3 @@
1
+ class GitCleanup
2
+ VERSION = "0.2.0"
3
+ end
metadata CHANGED
@@ -1,39 +1,47 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: git-cleanup
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
4
5
  prerelease:
5
- version: 0.1.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Martyn Loughran
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-06 00:00:00 +01:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: grit
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70356485463960 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
18
+ requirements:
22
19
  - - ~>
23
- - !ruby/object:Gem::Version
20
+ - !ruby/object:Gem::Version
24
21
  version: 2.2.0
25
22
  type: :runtime
26
- version_requirements: *id001
27
- description: Command line tool for interactively cleaning up old git branches (remotely and locally)
28
- email:
23
+ prerelease: false
24
+ version_requirements: *70356485463960
25
+ - !ruby/object:Gem::Dependency
26
+ name: formatador
27
+ requirement: &70356485462640 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.2.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70356485462640
36
+ description: Command line tool for interactively cleaning up old git branches (remotely
37
+ and locally)
38
+ email:
29
39
  - me@mloughran.com
30
- executables:
40
+ executables:
31
41
  - git-cleanup
32
42
  extensions: []
33
-
34
43
  extra_rdoc_files: []
35
-
36
- files:
44
+ files:
37
45
  - .document
38
46
  - .gitignore
39
47
  - Gemfile
@@ -46,33 +54,31 @@ files:
46
54
  - lib/git-cleanup.rb
47
55
  - lib/git-cleanup/branch.rb
48
56
  - lib/git-cleanup/helper.rb
49
- has_rdoc: true
57
+ - lib/git-cleanup/version.rb
50
58
  homepage: http://github.com/mloughran/git-cleanup
51
59
  licenses: []
52
-
53
60
  post_install_message:
54
61
  rdoc_options: []
55
-
56
- require_paths:
62
+ require_paths:
57
63
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
64
+ required_ruby_version: !ruby/object:Gem::Requirement
59
65
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
71
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
70
76
  requirements: []
71
-
72
77
  rubyforge_project:
73
- rubygems_version: 1.6.2
78
+ rubygems_version: 1.8.10
74
79
  signing_key:
75
80
  specification_version: 3
76
- summary: Command line tool for interactively cleaning up old git branches (remotely and locally)
81
+ summary: Command line tool for interactively cleaning up old git branches (remotely
82
+ and locally)
77
83
  test_files: []
78
-
84
+ has_rdoc: