git_tools 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Rakefile +2 -2
- data/bin/git-branch-cleaner +54 -0
- data/git_tools.gemspec +2 -1
- data/lib/git_tools/branches/cleaner.rb +11 -4
- data/lib/tasks/git_tools/branches.rake +1 -2
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bc3f7f01ad32646404bc725653462fdba76ecfc
|
4
|
+
data.tar.gz: 4e133c8c0c56c335f0e0f2756f06b84d218f5b65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fba53a172ba660ef0b6aed34b6d90162e094b7a7667c78bdfc7b3a146c4d4e741421566d4bdfab8855afd744e3864a5241bb1e2b122a0418afa4ff39358f421
|
7
|
+
data.tar.gz: 9bbdcaf7b15c26efa2d344ea8a21fdd02a2b93b0a5e8a9d8358b50cdb3026ec4890e92452439cc39adaf6c7e2ef0c99d2a9825871be1f314bc2820899733ee74
|
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'docopt'
|
4
|
+
require 'git_tools'
|
5
|
+
require 'git_tools/branches/cleaner'
|
6
|
+
|
7
|
+
doc = <<DOCOPT
|
8
|
+
Git branch cleaner. Will clean up local and remote branches based on master (HEAD) branch.
|
9
|
+
|
10
|
+
Usage:
|
11
|
+
#{__FILE__} [options]
|
12
|
+
|
13
|
+
Options:
|
14
|
+
-h --help Show this screen.
|
15
|
+
-v --version Show version.
|
16
|
+
-w --verbose Show verbose messages.
|
17
|
+
-d --debug Show debug messages.
|
18
|
+
-t --test Test run (no actualy deleting of branches).
|
19
|
+
-l --local Delete local branches.
|
20
|
+
-r --remote Delete remote branches.
|
21
|
+
-m --master <branch_name> Use branch as master.
|
22
|
+
-p --prompt Deletion confirmation prompts.
|
23
|
+
Without this all prompts are assumed to be negative.
|
24
|
+
DOCOPT
|
25
|
+
|
26
|
+
begin
|
27
|
+
args = Docopt::docopt(doc)
|
28
|
+
GitTools::Branches::ActionExecutor.test_mode = args[:test]
|
29
|
+
GitTools::Branches::ActionExecutor.skip_prompted = !args[:prompt]
|
30
|
+
|
31
|
+
if args['--verbose']
|
32
|
+
$VERBOSE = true
|
33
|
+
end
|
34
|
+
|
35
|
+
if args['--debug']
|
36
|
+
$DEBUG = true
|
37
|
+
end
|
38
|
+
|
39
|
+
puts args.inspect if $DEBUG
|
40
|
+
|
41
|
+
if args['--local']
|
42
|
+
if master = args['--master']
|
43
|
+
GitTools::Branches::Cleaner.with_local(master).run!
|
44
|
+
else
|
45
|
+
GitTools::Branches::Cleaner.with_local.run!
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if args['--remote']
|
50
|
+
GitTools::Branches::Cleaner.with_origin.run!
|
51
|
+
end
|
52
|
+
rescue Docopt::Exit => e
|
53
|
+
puts e.message
|
54
|
+
end
|
data/git_tools.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "git_tools"
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.2.0'
|
7
7
|
s.authors = ["Birkir A. Barkarson"]
|
8
8
|
s.email = ["birkirb@stoicviking.net"]
|
9
9
|
s.licenses = ['MIT']
|
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.rubyforge_project = "git_tools"
|
15
15
|
|
16
|
+
s.add_runtime_dependency("docopt")
|
16
17
|
s.files = `git ls-files`.split("\n")
|
17
18
|
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
18
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -26,7 +26,7 @@ module GitTools
|
|
26
26
|
|
27
27
|
attr_reader :master_branch, :remote, :protected_branches
|
28
28
|
|
29
|
-
def self.with_local(master_branch, protected_branches = nil)
|
29
|
+
def self.with_local(master_branch = nil, protected_branches = nil)
|
30
30
|
self.new(nil, master_branch, protected_branches)
|
31
31
|
end
|
32
32
|
|
@@ -42,7 +42,7 @@ module GitTools
|
|
42
42
|
@master_branch = master_branch || get_remote_head || MASTER_BRANCH
|
43
43
|
@branches = branches
|
44
44
|
|
45
|
-
if @master_branch.
|
45
|
+
if @master_branch.empty?
|
46
46
|
raise "Master branch was not set or determined."
|
47
47
|
else
|
48
48
|
puts "Master branch is #{@master_branch}" if $VERBOSE
|
@@ -82,6 +82,8 @@ module GitTools
|
|
82
82
|
end
|
83
83
|
|
84
84
|
git_remote_prune
|
85
|
+
rescue StandardError => e
|
86
|
+
puts e.message
|
85
87
|
end
|
86
88
|
|
87
89
|
private
|
@@ -103,7 +105,8 @@ module GitTools
|
|
103
105
|
end
|
104
106
|
|
105
107
|
def get_remote_head
|
106
|
-
(`git branch -r | grep #{remote}/HEAD`).sub(/#{remote}\/HEAD -> #{remote}\//, '').strip
|
108
|
+
head = (`git branch -r | grep #{remote}/HEAD`).sub(/#{remote}\/HEAD -> #{remote}\//, '').strip
|
109
|
+
head.empty? ? nil : head
|
107
110
|
end
|
108
111
|
|
109
112
|
def clean_branches_result(branches)
|
@@ -153,7 +156,11 @@ module GitTools
|
|
153
156
|
|
154
157
|
def self.age(branch)
|
155
158
|
time = DATE_REGEXP.match(`git log --shortstat --date=iso -n 1 #{branch}`)
|
156
|
-
|
159
|
+
if time.nil?
|
160
|
+
raise "Error due to unexpected git output."
|
161
|
+
else
|
162
|
+
Time.parse(time[1])
|
163
|
+
end
|
157
164
|
end
|
158
165
|
|
159
166
|
def self.executor
|
@@ -16,12 +16,11 @@ namespace :git do
|
|
16
16
|
namespace :clean do
|
17
17
|
desc 'Clean up local branches'
|
18
18
|
task :local do
|
19
|
-
GitTools::Branches::Cleaner.with_local
|
19
|
+
GitTools::Branches::Cleaner.with_local.run!
|
20
20
|
end
|
21
21
|
|
22
22
|
desc 'Clean up remote branches'
|
23
23
|
task :remote do
|
24
|
-
# TODO: Handle non origin
|
25
24
|
GitTools::Branches::Cleaner.with_origin.run!
|
26
25
|
end
|
27
26
|
|
metadata
CHANGED
@@ -1,25 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Birkir A. Barkarson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
12
|
-
dependencies:
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: docopt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: Git tools for installing hooks, cleaning up branches and more.
|
14
28
|
email:
|
15
29
|
- birkirb@stoicviking.net
|
16
|
-
executables:
|
30
|
+
executables:
|
31
|
+
- git-branch-cleaner
|
17
32
|
extensions: []
|
18
33
|
extra_rdoc_files: []
|
19
34
|
files:
|
20
35
|
- .gitignore
|
36
|
+
- Gemfile
|
21
37
|
- README.md
|
22
38
|
- Rakefile
|
39
|
+
- bin/git-branch-cleaner
|
23
40
|
- git_tools.gemspec
|
24
41
|
- lib/git_tools.rb
|
25
42
|
- lib/git_tools/branches/cleaner.rb
|