Sha256: f5a76a23d75b288a2a0fbbd4f83705faff9bf3038e91cebbf9205831020e7812

Contents?: true

Size: 1.91 KB

Versions: 130

Compression:

Stored size: 1.91 KB

Contents

module Git
  class Branch < Path
    
    attr_accessor :full, :remote, :name
    
    def initialize(base, name)
      @remote = nil
      @full = name
      @base = base
      @gcommit = nil
      @stashes = nil
      
      parts = name.split('/')
      if parts[1]
        @remote = Git::Remote.new(@base, parts[0])
        @name = parts[1]
      else
        @name = parts[0]
      end
    end
    
    def gcommit
      @gcommit ||= @base.gcommit(@full)
      @gcommit
    end
    
    def stashes
      @stashes ||= Git::Stashes.new(@base)
    end
    
    def checkout
      check_if_create
      @base.checkout(@full)
    end
    
    def archive(file, opts = {})
      @base.lib.archive(@full, file, opts)
    end
    
    # g.branch('new_branch').in_branch do
    #   # create new file
    #   # do other stuff
    #   return true # auto commits and switches back
    # end
    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
    
    def create
      check_if_create
    end
    
    def delete
      @base.lib.branch_delete(@name)
    end
    
    def current
      determine_current
    end
    
    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
    
    def update_ref(commit)
      @base.lib.update_ref(@full, commit)
    end
    
    def to_a
      [@full]
    end
    
    def to_s
      @full
    end
    
    private 

      def check_if_create
        @base.lib.branch_new(@name) rescue nil
      end
      
      def determine_current
        @base.lib.branch_current == @name
      end
    
  end
end

Version data entries

130 entries across 103 versions & 14 rubygems

Version Path
birkirb-git-1.1.1 lib/git/branch.rb
birkirb-git-1.1.2 lib/git/branch.rb
peterwald-git-1.1.2 lib/git/branch.rb
peterwald-git-1.1.3 lib/git/branch.rb
peterwald-git-1.1.4 lib/git/branch.rb
schacon-git-1.1.1 lib/git/branch.rb
schacon-git-1.2.0 lib/git/branch.rb
schacon-git-1.2.1 lib/git/branch.rb
schacon-git-1.2.2 lib/git/branch.rb
technicalpickles-git-1.1.1 lib/git/branch.rb
devise_sociable-0.1.0 vendor/bundle/gems/git-1.2.5/lib/git/branch.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/git-1.2.5/lib/git/branch.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/git-1.2.5/lib/git/branch.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/git-1.2.5/lib/git/branch.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/git-1.2.5/lib/git/branch.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/git-1.2.5/lib/git/branch.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/git-1.2.5/lib/git/branch.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/git-1.2.5/lib/git/branch.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/git-1.2.5/lib/git/branch.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/git-1.2.5/lib/git/branch.rb