git-cleanup 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Martyn Loughran
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = git-cleanup
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Martyn Loughran. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "git-cleanup"
8
+ gem.summary = %Q{Simplify cleaning up old git branches}
9
+ gem.description = %Q{Simplify cleaning up old git branches}
10
+ gem.email = "me@mloughran.com"
11
+ gem.homepage = "http://github.com/mloughran/git-cleanup"
12
+ gem.authors = ["Martyn Loughran"]
13
+ gem.add_dependency 'grit', '~> 2.2.0'
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/git-cleanup ADDED
@@ -0,0 +1,3 @@
1
+ require 'git-cleanup'
2
+
3
+ GitCleanup.run
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{git-cleanup}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Martyn Loughran"]
12
+ s.date = %q{2010-09-22}
13
+ s.default_executable = %q{git-cleanup}
14
+ s.description = %q{Simplify cleaning up old git branches}
15
+ s.email = %q{me@mloughran.com}
16
+ s.executables = ["git-cleanup"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/git-cleanup",
29
+ "git-cleanup.gemspec",
30
+ "lib/git-cleanup.rb",
31
+ "lib/git-cleanup/branch.rb",
32
+ "lib/git-cleanup/helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/mloughran/git-cleanup}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.6}
38
+ s.summary = %q{Simplify cleaning up old git branches}
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<grit>, ["~> 2.2.0"])
46
+ else
47
+ s.add_dependency(%q<grit>, ["~> 2.2.0"])
48
+ end
49
+ else
50
+ s.add_dependency(%q<grit>, ["~> 2.2.0"])
51
+ end
52
+ end
53
+
@@ -0,0 +1,61 @@
1
+ require 'grit'
2
+ require 'tempfile'
3
+
4
+ # Grit.debug = true
5
+
6
+ class GitCleanup
7
+ def self.run
8
+ repo = Grit::Repo.new(Dir.pwd)
9
+
10
+ master = repo.heads.find { |h| h.name == 'master' }
11
+
12
+ local_branches = repo.branches.map { |b| b.name }
13
+
14
+ remote_branches = Branch.remote(repo).select { |b| b.commit.lazy_source }
15
+
16
+ remote_branches.sort.each_with_index do |branch, index|
17
+ # Diff of commit in branch which is not in master
18
+ diff = branch.diff(master)
19
+
20
+ msg = "Branch #{branch.to_s} (#{index+1}/#{remote_branches.size})"
21
+ puts
22
+ puts msg
23
+ puts '-' * msg.size
24
+
25
+ if diff.empty?
26
+ last_commit = branch.commit
27
+ if last_commit
28
+ puts "Last commit:"
29
+ puts "Author: #{last_commit.author}"
30
+ puts "Date: #{last_commit.committed_date}"
31
+ puts "SHA: #{last_commit.sha}"
32
+ puts "#{last_commit.message}"
33
+ puts
34
+ end
35
+
36
+ Helper.boolean 'All commits merged. Do you want the branch deleted?' do
37
+ branch.delete(local_branches)
38
+ end
39
+ else
40
+ Helper.boolean "Branch not merged. Do you want to see a diff?" do
41
+ Tempfile.open('diff') do |tempfile|
42
+ tempfile << diff
43
+ tempfile.flush
44
+
45
+ if ENV["GIT_EDITOR"]
46
+ `#{ENV["GIT_EDITOR"]} #{tempfile.path}`
47
+ else
48
+ puts diff
49
+ end
50
+ end
51
+ Helper.boolean "Do you want the branch deleted?" do
52
+ branch.delete(local_branches)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ require 'git-cleanup/branch'
61
+ require 'git-cleanup/helper'
@@ -0,0 +1,47 @@
1
+ class GitCleanup
2
+ class Branch
3
+ include Comparable
4
+
5
+ def self.remote(repo)
6
+ repo.remotes.map { |r| new(repo, r) }
7
+ end
8
+
9
+ attr_reader :remote, :name, :ref
10
+
11
+ def initialize(repo, ref)
12
+ @repo = repo
13
+ @ref = ref
14
+ @remote, @name = ref.name.split('/')
15
+ end
16
+
17
+ def to_s
18
+ "#{remote}/#{name}"
19
+ end
20
+
21
+ def diff(ref)
22
+ @repo.git.native(:diff, {}, "#{ref.commit.sha}...#{@ref.commit.sha}")
23
+ end
24
+
25
+ def commit
26
+ @ref.commit
27
+ end
28
+
29
+ def delete(local_branches = nil)
30
+ puts "Deleting..."
31
+ @repo.git.native(:push, {}, @remote, ":#{@name}")
32
+ puts "Done"
33
+
34
+ if local_branches && local_branches.include?(name)
35
+ Helper.boolean "There is also a local branch called #{name}. Would you like to delete that too?" do
36
+ puts "Deleting..."
37
+ @repo.git.native(:branch, {}, '-d', name)
38
+ puts "Done"
39
+ end
40
+ end
41
+ end
42
+
43
+ def <=>(other)
44
+ commit.committed_date <=> other.commit.committed_date
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,15 @@
1
+ class GitCleanup
2
+ module Helper
3
+ def self.boolean(question)
4
+ puts "#{question} (y/n)"
5
+ answer = STDIN.gets.chomp
6
+ if answer == 'y'
7
+ yield
8
+ elsif answer == 'n'
9
+ return false
10
+ else
11
+ boolean(question)
12
+ end
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-cleanup
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Martyn Loughran
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-22 00:00:00 +01:00
18
+ default_executable: git-cleanup
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: grit
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 2
30
+ - 0
31
+ version: 2.2.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Simplify cleaning up old git branches
35
+ email: me@mloughran.com
36
+ executables:
37
+ - git-cleanup
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - bin/git-cleanup
51
+ - git-cleanup.gemspec
52
+ - lib/git-cleanup.rb
53
+ - lib/git-cleanup/branch.rb
54
+ - lib/git-cleanup/helper.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/mloughran/git-cleanup
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.6
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Simplify cleaning up old git branches
85
+ test_files: []
86
+