git_tools 0.2.2 → 0.3.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/VERSION +1 -0
- data/bin/git-branch-cleaner +35 -14
- data/git_tools.gemspec +1 -1
- data/lib/git_tools/branches/cleaner.rb +25 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1657841a12c0ef189a6d3fca4cdd48e479c0758
|
4
|
+
data.tar.gz: 30448143febad9adb062895611a55647196d2ac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7f1daa352df56ca237e4c4727caaf69ba88d0b7a5ffc398dd42c5ea1725fc5d857688f3a4e7e93007116c6f8e8b619f8282c2267d6f9afaa9dad5a704872750
|
7
|
+
data.tar.gz: 39ec25606c2267005997e836aba4e07008440e9779507409e521e2643e0d4debd2e830b1b5537a6ac308df2e933d348ec90aedb17ad96a35621bdab9dfb7ae99
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
data/bin/git-branch-cleaner
CHANGED
@@ -5,28 +5,37 @@ require 'git_tools'
|
|
5
5
|
require 'git_tools/branches/cleaner'
|
6
6
|
|
7
7
|
doc = <<DOCOPT
|
8
|
-
Git branch cleaner. Will
|
8
|
+
Git branch cleaner. Will delete local and remote branches that have been merged into the master HEAD branch.
|
9
|
+
Only branches older than merged threshold will be deleted unless otherwise specified.
|
10
|
+
Unmerged branches older than the unmerged threshold will deleted only if so specified.
|
9
11
|
|
10
12
|
Usage:
|
11
|
-
#{__FILE__} [options]
|
13
|
+
#{File.basename(__FILE__)} [options]
|
12
14
|
|
13
15
|
Options:
|
14
|
-
-h --help
|
15
|
-
-v --version
|
16
|
-
-w --verbose
|
17
|
-
-d --debug
|
18
|
-
-
|
19
|
-
-l --local
|
20
|
-
-r --remote
|
21
|
-
-
|
22
|
-
|
23
|
-
|
16
|
+
-h --help Show this screen.
|
17
|
+
-v --version Show version and exit.
|
18
|
+
-w --verbose Show verbose messages.
|
19
|
+
-d --debug Show debug messages.
|
20
|
+
-n --no-execute Test run (no actualy deleting of branches).
|
21
|
+
-l --local Delete local branches.
|
22
|
+
-r --remote Delete remote branches.
|
23
|
+
-t --merged-threshold <days> Delete merged branches older than this
|
24
|
+
(default ≈15 days).
|
25
|
+
-u --unmerged-threshold <days> Prompt for deletion of unmerged branches older
|
26
|
+
than this (default ≈180 days, forces -p flag).
|
27
|
+
-m --master <branch_name> Use branch as master.
|
28
|
+
-p --prompt Deletion confirmation prompts. Without this
|
29
|
+
all prompts are assumed to be negative.
|
24
30
|
DOCOPT
|
25
31
|
|
26
32
|
begin
|
27
33
|
args = Docopt::docopt(doc)
|
28
|
-
|
29
|
-
|
34
|
+
|
35
|
+
if args['--version']
|
36
|
+
puts File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'VERSION')))
|
37
|
+
exit
|
38
|
+
end
|
30
39
|
|
31
40
|
if args['--verbose']
|
32
41
|
$VERBOSE = true
|
@@ -38,6 +47,18 @@ begin
|
|
38
47
|
|
39
48
|
puts args.inspect if $DEBUG
|
40
49
|
|
50
|
+
if time = args['--merged-threshold']
|
51
|
+
GitTools::Branches::Cleaner.merged_threshold_in_days = time.to_i
|
52
|
+
end
|
53
|
+
|
54
|
+
if time = args['--unmerged-threshold']
|
55
|
+
GitTools::Branches::Cleaner.unmerged_threshold_in_days = time.to_i
|
56
|
+
args['--prompt'] = true # Force this option.
|
57
|
+
end
|
58
|
+
|
59
|
+
GitTools::Branches::ActionExecutor.test_mode = args['--no-execute']
|
60
|
+
GitTools::Branches::ActionExecutor.skip_prompted = !args['--prompt']
|
61
|
+
|
41
62
|
if args['--local']
|
42
63
|
if master = args['--master']
|
43
64
|
GitTools::Branches::Cleaner.with_local(master).run!
|
data/git_tools.gemspec
CHANGED
@@ -21,8 +21,8 @@ module GitTools
|
|
21
21
|
class Cleaner
|
22
22
|
MASTER_BRANCH = 'master'
|
23
23
|
DEFAULT_REMOTE = 'origin'
|
24
|
-
|
25
|
-
|
24
|
+
@@age_threshold_for_deleting_remote_branches_in_master = 15 * Time::SECONDS_IN_DAY
|
25
|
+
@@age_threshold_for_deleting_any_unmerged_branches = 180 * Time::SECONDS_IN_DAY
|
26
26
|
|
27
27
|
attr_reader :master_branch, :remote, :protected_branches
|
28
28
|
|
@@ -34,6 +34,22 @@ module GitTools
|
|
34
34
|
self.new(DEFAULT_REMOTE, nil, protected_branches)
|
35
35
|
end
|
36
36
|
|
37
|
+
def self.merged_threshold
|
38
|
+
@@age_threshold_for_deleting_remote_branches_in_master
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.merged_threshold_in_days=(days)
|
42
|
+
@@age_threshold_for_deleting_remote_branches_in_master = days * Time::SECONDS_IN_DAY
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.unmerged_threshold
|
46
|
+
@@age_threshold_for_deleting_any_unmerged_branches
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.unmerged_threshold_in_days=(days)
|
50
|
+
@@age_threshold_for_deleting_any_unmerged_branches = days * Time::SECONDS_IN_DAY
|
51
|
+
end
|
52
|
+
|
37
53
|
public
|
38
54
|
|
39
55
|
def initialize(remote = nil, master_branch = nil, protected_branches = nil)
|
@@ -47,6 +63,11 @@ module GitTools
|
|
47
63
|
else
|
48
64
|
puts "Master branch is #{@master_branch}" if $VERBOSE
|
49
65
|
end
|
66
|
+
|
67
|
+
puts "Merged branch threshold is #{@@age_threshold_for_deleting_remote_branches_in_master/Time::SECONDS_IN_DAY} days." if $VERBOSE
|
68
|
+
puts "Unmerged branch threshold is #{@@age_threshold_for_deleting_any_unmerged_branches/Time::SECONDS_IN_DAY} days." if $VERBOSE
|
69
|
+
|
70
|
+
git_remote_prune
|
50
71
|
end
|
51
72
|
|
52
73
|
def local?
|
@@ -141,12 +162,12 @@ module GitTools
|
|
141
162
|
if local?
|
142
163
|
true
|
143
164
|
else
|
144
|
-
(Time.now - time) >
|
165
|
+
(Time.now - time) > self.class.merged_threshold
|
145
166
|
end
|
146
167
|
end
|
147
168
|
|
148
169
|
def delete_unmerged_branch?(time)
|
149
|
-
(Time.now - time) >
|
170
|
+
(Time.now - time) > self.class.unmerged_threshold
|
150
171
|
end
|
151
172
|
|
152
173
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docopt
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- Gemfile
|
37
37
|
- README.md
|
38
38
|
- Rakefile
|
39
|
+
- VERSION
|
39
40
|
- bin/git-branch-cleaner
|
40
41
|
- git_tools.gemspec
|
41
42
|
- lib/git_tools.rb
|