29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/geordi/gitpt.rb', line 29
def run_branch(from_master: false)
story = choose_story || Interaction.fail('No story selected.')
normalized_story_name = normalize_string(story.name)
branch_list_string = if Util.testing?
ENV['GEORDI_TESTING_GIT_BRANCHES'] || ''
else
`git branch --format="%(refname:short)"`
end
if branch_list_string.nil? || branch_list_string.strip.empty?
Interaction.fail 'Could not determine local git branches.'
end
new_branch_name = "#{git_user_initials}/#{normalized_story_name}-#{story.id}"
local_branches = branch_list_string.split("\n")
branch_name = local_branches.find { |branch_name| branch_name == new_branch_name }
branch_name ||= local_branches.find { |branch_name| branch_name.include? story.id.to_s }
if branch_name.present?
checkout_branch branch_name, new_branch: false
else
checkout_branch new_branch_name, new_branch: true, from_master: from_master
end
end
|