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.



7
8
9
10
11
12
13
# File 'lib/git/branch.rb', line 7

def initialize(base, name)
  @full = name
  @base = base
  @gcommit = nil
  @stashes = nil
  @remote, @name = parse_name(name)
end

Instance Attribute Details

#full

Returns the value of attribute full.



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

def full
  @full
end

#name

Returns the value of attribute name.



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

def name
  @name
end

#remote

Returns the value of attribute remote.



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

def remote
  @remote
end

Instance Method Details

#archive(file, opts = {})



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

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

#checkout



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

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

#contains?(commit) ⇒ Boolean

Returns:

  • (Boolean)


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

def contains?(commit)
  !@base.lib.branch_contains(commit, self.name).empty?
end

#create



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

def create
  check_if_create
end

#current



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

def current
  determine_current
end

#delete



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

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

#gcommit



15
16
17
18
# File 'lib/git/branch.rb', line 15

def gcommit
  @gcommit ||= @base.gcommit(@full)
  @gcommit
end

#in_branch(message = 'in branch work')

g.branch('new_branch').in_branch do # create new file # do other stuff return true # auto commits and switches back end



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

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)



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/git/branch.rb', line 65

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

#stashes



20
21
22
# File 'lib/git/branch.rb', line 20

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

#to_a



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

def to_a
  [@full]
end

#to_s



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

def to_s
  @full
end

#update_ref(commit)



78
79
80
81
82
83
84
# File 'lib/git/branch.rb', line 78

def update_ref(commit)
  if @remote
    @base.lib.update_ref("refs/remotes/#{@remote.name}/#{@name}", commit)
  else
    @base.lib.update_ref("refs/heads/#{@name}", commit)
  end
end