Module: GitWorkflow::Git

Included in:
Callbacks::Loader, Commands::Base, Configuration, Configuration::Convention
Defined in:
lib/git_workflow/git.rb

Defined Under Namespace

Classes: Repository

Instance Method Summary collapse

Instance Method Details

#checkout_or_create_branch(branch, source = nil) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/git_workflow/git.rb', line 121

def checkout_or_create_branch(branch, source = nil)
  if repository.does_branch_exist?(branch)
    repository.checkout(branch)
  else
    repository.create(branch, source)
  end
end

#get_config_value_for(key, default = nil) ⇒ Object



129
130
131
132
133
# File 'lib/git_workflow/git.rb', line 129

def get_config_value_for(key, default = nil)
  repository.config_get(key)
rescue Repository::ConfigError => exception
  default
end

#get_config_value_for!(key) ⇒ Object



135
136
137
# File 'lib/git_workflow/git.rb', line 135

def get_config_value_for!(key)
  get_config_value_for(key) or raise StandardError, "Required configuration setting '#{ key }' is unset"
end

#in_git_branch(target_branch, &block) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/git_workflow/git.rb', line 99

def in_git_branch(target_branch, &block)
  current_branch = repository.current_branch
  if current_branch == target_branch
    yield
  else
    info("Temporarily switching to branch '#{ target_branch }'")

    repository.checkout(target_branch)
    yield
    repository.checkout(current_branch)

    info("Switched back to '#{ current_branch }'")
  end
end

#merge_branch(source_branch, target_branch) ⇒ Object



114
115
116
117
118
119
# File 'lib/git_workflow/git.rb', line 114

def merge_branch(source_branch, target_branch)
  info("Merging branch '#{ source_branch }' into '#{ target_branch }'") do
    repository.checkout(target_branch)
    repository.merge(source_branch)
  end
end

#repositoryObject



95
96
97
# File 'lib/git_workflow/git.rb', line 95

def repository
  Repository.instance
end

#set_config_value(key, value) ⇒ Object



139
140
141
# File 'lib/git_workflow/git.rb', line 139

def set_config_value(key, value)
  repository.config_set(key, value)
end