git_tools 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20d0bb4e3f40cc05a6d2f684e06f69e3e4160af7
4
- data.tar.gz: 249cc375da442f650c784832357a3d0465460d24
3
+ metadata.gz: c1657841a12c0ef189a6d3fca4cdd48e479c0758
4
+ data.tar.gz: 30448143febad9adb062895611a55647196d2ac6
5
5
  SHA512:
6
- metadata.gz: f39a3b7b1b6f0e3bb8324719ceedc7185f38cb1837fcaf4b4eef09bfc9c240f4874e57f16655eba80be7c0b2945e4bd9b8d0ea08172804f57244f4e620d07275
7
- data.tar.gz: a4324f73f44c2757e185752c337e50a58eddc44ee6d11c94ef378c520af10dc17866ef175cd738180f919c531e72e0e43478dfa0f8e2da212131ee8faed2cfbb
6
+ metadata.gz: d7f1daa352df56ca237e4c4727caaf69ba88d0b7a5ffc398dd42c5ea1725fc5d857688f3a4e7e93007116c6f8e8b619f8282c2267d6f9afaa9dad5a704872750
7
+ data.tar.gz: 39ec25606c2267005997e836aba4e07008440e9779507409e521e2643e0d4debd2e830b1b5537a6ac308df2e933d348ec90aedb17ad96a35621bdab9dfb7ae99
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -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 clean up local and remote branches based on master (HEAD) branch.
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 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.
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
- GitTools::Branches::ActionExecutor.test_mode = args['--test']
29
- GitTools::Branches::ActionExecutor.skip_prompted = !args['--prompt']
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!
@@ -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.2.2'
6
+ s.version = File.read('VERSION')
7
7
  s.authors = ["Birkir A. Barkarson"]
8
8
  s.email = ["birkirb@stoicviking.net"]
9
9
  s.licenses = ['MIT']
@@ -21,8 +21,8 @@ module GitTools
21
21
  class Cleaner
22
22
  MASTER_BRANCH = 'master'
23
23
  DEFAULT_REMOTE = 'origin'
24
- AGE_THRESHOLD_IN_MONTHS_FOR_DELETING_REMOTE_BRANCHES_IN_MASTER = 1 * Time::SECONDS_IN_MONTH
25
- AGE_THRESHOLD_IN_MONTHS_FOR_DELETING_ANY_UNMERGED_BRANCHES = 6 * Time::SECONDS_IN_MONTH
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) > AGE_THRESHOLD_IN_MONTHS_FOR_DELETING_REMOTE_BRANCHES_IN_MASTER
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) > AGE_THRESHOLD_IN_MONTHS_FOR_DELETING_ANY_UNMERGED_BRANCHES
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.2.2
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-02-19 00:00:00.000000000 Z
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