git_manager 0.0.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.
- data/lib/git_manager.rb +29 -0
- data/spec/git_manager_spec.rb +34 -0
- metadata +66 -0
data/lib/git_manager.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
module Git
|
3
|
+
class Manager
|
4
|
+
attr_accessor :branches, :current_branch, :branches_to_delete
|
5
|
+
def initialize
|
6
|
+
@branches = `git branch`.split /\n/
|
7
|
+
partition_branches
|
8
|
+
end
|
9
|
+
def partition_branches
|
10
|
+
@current_branch = @branches.select {|branch| branch.match /^\*/}.first
|
11
|
+
@branches_to_delete = @branches.select {|branch| branch != @current_branch }
|
12
|
+
@current_branch.chomp!
|
13
|
+
@current_branch.gsub! /\s|\*/, ''
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete_branches
|
17
|
+
return false if @branches_to_delete.length == 0
|
18
|
+
@branches_to_delete.each do |branch|
|
19
|
+
delete_branch( branch.gsub /\s/, '' )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_branch branch
|
24
|
+
`git branch -D #{branch}`
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
require 'git_manager'
|
4
|
+
|
5
|
+
describe Git::Manager do
|
6
|
+
before :each do
|
7
|
+
@git_manager = Git::Manager.new
|
8
|
+
end
|
9
|
+
it "has branches" do
|
10
|
+
@git_manager.branches.should_not be_nil
|
11
|
+
end
|
12
|
+
it "has branches array" do
|
13
|
+
@git_manager.branches.class.should == Array
|
14
|
+
end
|
15
|
+
it "knows about current branch" do
|
16
|
+
@git_manager.current_branch.should == 'master'
|
17
|
+
end
|
18
|
+
it "knows about branches to delete" do
|
19
|
+
@git_manager.branches_to_delete.should_not be_nil
|
20
|
+
end
|
21
|
+
it "aborts if branches to delete is empty" do
|
22
|
+
@git_manager.branches_to_delete = []
|
23
|
+
@git_manager.delete_branches.should == false
|
24
|
+
end
|
25
|
+
it "deltes branches to delete if NOT empty" do
|
26
|
+
@fake_branch_name = 'some_fake_branch'
|
27
|
+
Git::Manager.any_instance.stub(:delete_branch).and_return( true )
|
28
|
+
|
29
|
+
@git_manager.branches_to_delete = ['some_fake_branch']
|
30
|
+
@git_manager.delete_branches.should_not == false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- kikuchiyo
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-08-11 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: all local branches, but one you are on
|
22
|
+
email: kikuchiyo6@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/git_manager.rb
|
31
|
+
- spec/git_manager_spec.rb
|
32
|
+
homepage: http://rubygems.org/gems/git_manager
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.24
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: manage git
|
65
|
+
test_files:
|
66
|
+
- spec/git_manager_spec.rb
|