Class: Git::Branch

Inherits:
Path
  • Object
show all
Defined in:
lib/git/branch.rb

Instance Attribute Summary collapse

Attributes inherited from Path

#path

Instance Method Summary collapse

Methods inherited from Path

#readable?, #writable?

Constructor Details

#initialize(base, name) ⇒ Branch

Returns a new instance of Branch.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/git/branch.rb', line 9

def initialize(base, name)
  @remote = nil
  @full = name
  @base = base
  
  parts = name.split('/')
  if parts[1]
    @remote = Git::Remote.new(@base, parts[0])
    @name = parts[1]
  else
    @name = parts[0]
  end
end

Instance Attribute Details

#fullObject

Returns the value of attribute full.



4
5
6
# File 'lib/git/branch.rb', line 4

def full
  @full
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/git/branch.rb', line 4

def name
  @name
end

#remoteObject

Returns the value of attribute remote.



4
5
6
# File 'lib/git/branch.rb', line 4

def remote
  @remote
end

Instance Method Details

#checkoutObject



28
29
30
31
# File 'lib/git/branch.rb', line 28

def checkout
  check_if_create
  @base.checkout(@name)
end

#createObject



50
51
52
# File 'lib/git/branch.rb', line 50

def create
  check_if_create
end

#currentObject



58
59
60
# File 'lib/git/branch.rb', line 58

def current
  determine_current
end

#deleteObject



54
55
56
# File 'lib/git/branch.rb', line 54

def delete
  @base.lib.branch_delete(@name)
end

#gcommitObject



23
24
25
26
# File 'lib/git/branch.rb', line 23

def gcommit
  @gcommit = @base.object(name) if !@gcommit
  @gcommit
end

#in_branch(message = 'in branch work') ⇒ Object

g.branch(‘new_branch’).in_branch do

# create new file
# do other stuff
return true # auto commits and switches back

end



39
40
41
42
43
44
45
46
47
48
# File 'lib/git/branch.rb', line 39

def in_branch (message = 'in branch work')
  old_current = @base.lib.branch_current
  checkout
  if yield
    @base.commit_all(message)
  else
    @base.reset_hard
  end
  @base.checkout(old_current)
end

#merge(branch = nil, message = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/git/branch.rb', line 62

def merge(branch = nil, message = nil)
  if branch
    in_branch do 
      @base.merge(branch, message)
      false
    end
    # merge a branch into this one
  else
    # merge this branch into the current one
    @base.merge(@name)
  end
end

#to_aObject



75
76
77
# File 'lib/git/branch.rb', line 75

def to_a
  [@full]
end

#to_sObject



79
80
81
# File 'lib/git/branch.rb', line 79

def to_s
  @full
end