Class: GitFlower::GitRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/git_flower/git_repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(path_to_repo) ⇒ GitRepository

Returns a new instance of GitRepository.



5
6
7
# File 'lib/git_flower/git_repository.rb', line 5

def initialize(path_to_repo)
  @repo = find_git_repo(path_to_repo)
end

Instance Method Details

#branch_up_to_date?(branch_name) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/git_flower/git_repository.rb', line 37

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

#checkout_branch(branch_name) ⇒ Object



17
18
19
# File 'lib/git_flower/git_repository.rb', line 17

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

#develop_up_to_date?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/git_flower/git_repository.rb', line 29

def develop_up_to_date?
  branch_up_to_date?('develop')
end

#find_git_repo(initial_dir) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/git_flower/git_repository.rb', line 9

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

#has_added_files?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/git_flower/git_repository.rb', line 21

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

#has_existing_branch_name?(branch_name) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/git_flower/git_repository.rb', line 33

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

#master_up_to_date?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/git_flower/git_repository.rb', line 25

def master_up_to_date?
  branch_up_to_date?('master')
end