Sha256: 2d5a59e9fcf4cc8c5a5842f2fac9f81642bf19006be70ccd72b3f586ee9bc2f3

Contents?: true

Size: 937 Bytes

Versions: 1

Compression:

Stored size: 937 Bytes

Contents

require 'git'

module GitFlower
  class GitRepository
    def initialize(path_to_repo)
      @repo = find_git_repo(path_to_repo)
    end

    def find_git_repo(initial_dir)
      if Dir.exist?('.git')
        Git.open(initial_dir)
      else
        raise GitError, "Please navigate to the root of your git repository to use this gem."
      end
    end

    def checkout_branch(branch_name)
      @repo.branch(branch_name).checkout
    end

    def has_added_files?
      !@repo.status.added.empty?
    end

    def master_up_to_date?
      branch_up_to_date?('master')
    end

    def develop_up_to_date?
      branch_up_to_date?('develop')
    end

    def has_existing_branch_name?(branch_name)
      !@repo.branches.local.map(&:name).select { |name| name =~ /^#{branch_name}.*/ }.empty?
    end

    def branch_up_to_date?(branch_name)
      @repo.revparse(branch_name) == @repo.revparse("origin/#{branch_name}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_flower-0.2.0 lib/git_flower/git_repository.rb