git-cleanremote 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .idea
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in git-cleanremote.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jason Waldrip
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # git-cleanremote
2
+
3
+ Clean remote allows you clean up your remote branches
4
+
5
+ ## Installation
6
+
7
+ Install the gem:
8
+
9
+ $ gem install git-cleanremote
10
+
11
+ ## Usage
12
+
13
+ cleanremote is used in the command line as a git extension. Once installed you can follow the instructions below.
14
+
15
+ ```sh
16
+ Usage:
17
+ git cleanremote [BRANCH_NAME]
18
+
19
+ Options:
20
+ [--dryrun]
21
+ [--version]
22
+ [--ask] # Default: true
23
+ [--remote=REMOTE] # Default: origin
24
+ ```
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems" # ruby1.9 doesn't "require" it though
3
+ require "git-cleanremote"
4
+
5
+ Git::CleanRemote.start
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git-cleanremote/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "git-cleanremote"
8
+ gem.version = Git::CleanRemoteVersion::STRING
9
+ gem.authors = ["Jason Waldrip"]
10
+ gem.email = ["jason@waldrip.net"]
11
+ gem.description = %{A command line tool to clean up remote repositories.}
12
+ gem.summary = %{A command line tool to clean up remote repositories.}
13
+ gem.homepage = "https://github.com/jwaldrip/git-cleanremote"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "thor", "~> 0.17.0"
21
+ gem.add_dependency "open4"
22
+
23
+ # gem.add_development_dependency "rspec", "~> 2.12.0" # Todo: add some specs/tests.
24
+
25
+ end
@@ -0,0 +1,21 @@
1
+ require "git-cleanremote/version"
2
+ require "thor"
3
+
4
+ module Git
5
+ class CleanRemote < Thor::Group
6
+ autoload :Cleaner, 'git-cleanremote/cleaner'
7
+ autoload :Branch, 'git-cleanremote/branch'
8
+
9
+ argument :branch_name, :default => 'master', :type => :string, :desc => "The remote branch to cleanup"
10
+ class_option :dryrun, :type => :boolean
11
+ class_option :version, :type => :boolean
12
+ class_option :ask, :type => :boolean, :default => true
13
+ class_option :remote, :type => :string, :default => "origin"
14
+ desc "Cleans up a remote branch."
15
+
16
+ def clean
17
+ Cleaner.new(branch_name, options)
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require 'open4'
2
+
3
+ class Git::CleanRemote::Branch
4
+
5
+ attr_reader :name, :remote
6
+
7
+ def initialize(name, remote)
8
+ @name = name
9
+ @remote = remote
10
+ end
11
+
12
+ def to_s
13
+ [remote, name].join('/')
14
+ end
15
+
16
+ def delete!
17
+ error = ''
18
+ status = Open4::popen4("git push #{remote} --delete #{name}") do |pid, stdin, stdout, stderr|
19
+ error = stderr.gets.to_s
20
+ end
21
+ raise StandardError, error if status.to_i > 0
22
+ true
23
+ end
24
+
25
+ end
@@ -0,0 +1,71 @@
1
+ class Git::CleanRemote::Cleaner < Thor::Shell::Color
2
+
3
+ attr_reader :branch, :remote, :options
4
+
5
+ def initialize(branch, options={})
6
+ @padding = 0
7
+ return say ["git-cleanremote", Git::CleanRemoteVersion::STRING].join(' ') if options[:version]
8
+ options = options.dup
9
+ @branch = branch
10
+ @remote = options.delete :remote
11
+ @options = options
12
+ if options[:dryrun]
13
+ dryrun
14
+ else
15
+ run
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def dryrun
22
+ get_merged_branches
23
+ array = @merged_branches.map do |branch|
24
+ [branch.to_s, set_color("will be deleted!", :red)]
25
+ end
26
+ print_table array
27
+ end
28
+
29
+ def run
30
+ if options[:ask]
31
+ dryrun
32
+ say "\n"
33
+ if yes? "Do you want to delete the above branches?", :yellow
34
+ delete_merged_branches
35
+ else
36
+ say "ABORTED!", :red
37
+ end
38
+ else
39
+ get_merged_branches
40
+ delete_merged_branches
41
+ end
42
+ end
43
+
44
+ def delete_merged_branches
45
+ say "Deleting branches on #{remote}", :blue, true
46
+ @merged_branches.each do |branch|
47
+ begin
48
+ branch.delete!
49
+ say [set_color("DELETED", :yellow), branch].join(" ")
50
+ rescue => message
51
+ say [set_color("ERROR ", :red), branch, set_color(message, :magenta)].join(" ")
52
+ end
53
+ end
54
+ end
55
+
56
+ def get_merged_branches
57
+ say "Invalid Remote!", :red and exit unless system "git fetch #{remote} --prune"
58
+ say "Checking merge status on #{remote} for #{branch}", :blue
59
+ @merged_branches = `git branch -r --merged #{remote}/#{branch}`.lines.reduce([]) do |branches, branch|
60
+ remote, branch = branch.strip.split('/')
61
+ unless (branch == self.branch && remote == self.remote) || remote != self.remote
62
+ branches << Git::CleanRemote::Branch.new(branch, remote)
63
+ end
64
+ branches
65
+ end
66
+ if @merged_branches.empty?
67
+ say "Nothing to clean!", :blue and exit
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,5 @@
1
+ module Git
2
+ class CleanRemoteVersion
3
+ STRING = "0.0.2"
4
+ end
5
+ end
data/somefile.rb ADDED
File without changes
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-cleanremote
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Waldrip
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.17.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.17.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: open4
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A command line tool to clean up remote repositories.
47
+ email:
48
+ - jason@waldrip.net
49
+ executables:
50
+ - git-cleanremote
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/git-cleanremote
60
+ - git-cleanremote.gemspec
61
+ - lib/git-cleanremote.rb
62
+ - lib/git-cleanremote/branch.rb
63
+ - lib/git-cleanremote/cleaner.rb
64
+ - lib/git-cleanremote/version.rb
65
+ - somefile.rb
66
+ homepage: https://github.com/jwaldrip/git-cleanremote
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.25
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: A command line tool to clean up remote repositories.
90
+ test_files: []
91
+ has_rdoc: