git-cleanremote 0.0.2 → 0.0.3
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/README.md +2 -1
- data/lib/git-cleanremote.rb +3 -2
- data/lib/git-cleanremote/branch.rb +9 -0
- data/lib/git-cleanremote/cleaner.rb +17 -4
- data/lib/git-cleanremote/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
data/lib/git-cleanremote.rb
CHANGED
@@ -7,8 +7,9 @@ module Git
|
|
7
7
|
autoload :Branch, 'git-cleanremote/branch'
|
8
8
|
|
9
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
|
10
|
+
class_option :dryrun, :type => :boolean, :default => false
|
11
|
+
class_option :version, :type => :boolean, :default => false
|
12
|
+
class_option :local, :type => :boolean, :default => false
|
12
13
|
class_option :ask, :type => :boolean, :default => true
|
13
14
|
class_option :remote, :type => :string, :default => "origin"
|
14
15
|
desc "Cleans up a remote branch."
|
@@ -22,4 +22,13 @@ class Git::CleanRemote::Branch
|
|
22
22
|
true
|
23
23
|
end
|
24
24
|
|
25
|
+
def local_delete!
|
26
|
+
error = ''
|
27
|
+
status = Open4::popen4("git branch -D #{name}") do |pid, stdin, stdout, stderr|
|
28
|
+
error = stderr.gets.to_s
|
29
|
+
end
|
30
|
+
raise StandardError, error if status.to_i > 0
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
25
34
|
end
|
@@ -5,9 +5,9 @@ class Git::CleanRemote::Cleaner < Thor::Shell::Color
|
|
5
5
|
def initialize(branch, options={})
|
6
6
|
@padding = 0
|
7
7
|
return say ["git-cleanremote", Git::CleanRemoteVersion::STRING].join(' ') if options[:version]
|
8
|
-
options
|
9
|
-
@branch
|
10
|
-
@remote
|
8
|
+
options = options.dup
|
9
|
+
@branch = branch
|
10
|
+
@remote = options.delete :remote
|
11
11
|
@options = options
|
12
12
|
if options[:dryrun]
|
13
13
|
dryrun
|
@@ -24,6 +24,8 @@ class Git::CleanRemote::Cleaner < Thor::Shell::Color
|
|
24
24
|
[branch.to_s, set_color("will be deleted!", :red)]
|
25
25
|
end
|
26
26
|
print_table array
|
27
|
+
count = array.count
|
28
|
+
say "\n" + [count, (count == 1 ? 'branch' : 'branches'), 'will be deleted!'].join(' ')
|
27
29
|
end
|
28
30
|
|
29
31
|
def run
|
@@ -43,14 +45,25 @@ class Git::CleanRemote::Cleaner < Thor::Shell::Color
|
|
43
45
|
|
44
46
|
def delete_merged_branches
|
45
47
|
say "Deleting branches on #{remote}", :blue, true
|
46
|
-
@merged_branches.
|
48
|
+
status = @merged_branches.reduce({}) do |hash, branch|
|
49
|
+
hash[:success] ||= 0
|
50
|
+
hash[:error] ||= 0
|
47
51
|
begin
|
48
52
|
branch.delete!
|
53
|
+
branch.local_delete! if options[:local]
|
49
54
|
say [set_color("DELETED", :yellow), branch].join(" ")
|
55
|
+
hash[:success] += 1
|
50
56
|
rescue => message
|
51
57
|
say [set_color("ERROR ", :red), branch, set_color(message, :magenta)].join(" ")
|
58
|
+
hash[:error] += 1
|
52
59
|
end
|
60
|
+
hash
|
53
61
|
end
|
62
|
+
system "git fetch #{remote} --prune"
|
63
|
+
message = []
|
64
|
+
message << [status[:success], (status[:success] == 1 ? 'deletion' : 'deletions')].join(' ')
|
65
|
+
message << [status[:error], (status[:error] == 1 ? 'error' : 'errors')].join(' ')
|
66
|
+
say message.join(', ')
|
54
67
|
end
|
55
68
|
|
56
69
|
def get_merged_branches
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-cleanremote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|