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, track = nil) ⇒ Branch

– addition of track parameter for –t switch



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

def initialize(base, name, track=nil)
#
  @remote = nil
  @full = name
  @base = base
  @gcommit = nil
  @stashes = nil
  
  # -- addition of track attribute to implement
  #    --t switch
  @track = track
  name, remote = name.split(' ').first.split('/').reverse
  if remote
    @remote = Git::Remote.new(@base, remote)
    name = "#{remote}/#{name}"
  end
  @name = name
  #
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

#archive(file, opts = {}) ⇒ Object



41
42
43
# File 'lib/git/branch.rb', line 41

def archive(file, opts = {})
  @base.lib.archive(@full, file, opts)
end

#checkoutObject



36
37
38
39
# File 'lib/git/branch.rb', line 36

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

#createObject



61
62
63
# File 'lib/git/branch.rb', line 61

def create
  check_if_create
end

#currentObject



69
70
71
# File 'lib/git/branch.rb', line 69

def current
  determine_current
end

#deleteObject



65
66
67
# File 'lib/git/branch.rb', line 65

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

#gcommitObject



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

def gcommit
  @gcommit ||= @base.gcommit(@full)
  @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



50
51
52
53
54
55
56
57
58
59
# File 'lib/git/branch.rb', line 50

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



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/git/branch.rb', line 73

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

#stashesObject



32
33
34
# File 'lib/git/branch.rb', line 32

def stashes
  @stashes ||= Git::Stashes.new(@base)
end

#to_aObject



90
91
92
# File 'lib/git/branch.rb', line 90

def to_a
  [@full]
end

#to_sObject



94
95
96
# File 'lib/git/branch.rb', line 94

def to_s
  @full
end

#update_ref(commit) ⇒ Object



86
87
88
# File 'lib/git/branch.rb', line 86

def update_ref(commit)
  @base.lib.update_ref(@full, commit)
end