added branch and checkout functionality
[rubygit.git] / lib / git / branch.rb
blob3d8337b8092888bf74fb03319af892f75a1b2c17
1 module Git
2   class Branch < Path
3     
4     attr_accessor :full, :remote, :name
5     
6     @base = nil
7     @gcommit = nil
8     
9     def initialize(base, name)
10       @remote = nil
11       @full = name
12       @base = base
13       
14       parts = name.split('/')
15       if parts[1]
16         @remote = Git::Remote.new(@base, parts[0])
17         @name = parts[1]
18       else
19         @name = parts[0]
20       end
21     end
22     
23     def gcommit
24       @gcommit = @base.object(name) if !@gcommit
25       @gcommit
26     end
27     
28     def checkout
29       check_if_create
30       @base.lib.checkout(@name)
31     end
32     
33     def create
34       check_if_create
35     end
36     
37     def delete
38       @base.lib.branch_delete(@name)
39     end
40     
41     def current
42       determine_current
43     end
44     
45     def to_s
46       @name
47     end
48     
49     private 
51       def check_if_create
52         @base.lib.branch_new(@name) rescue nil
53       end
54       
55       def determine_current
56         @base.lib.branch_current == @name
57       end
58     
59   end
60 end