class Abt::Providers::Git::Commands::Branch
Public Class Methods
description()
click to toggle source
# File lib/abt/providers/git/commands/branch.rb, line 12 def self.description "Switch branch. Uses a compatible scheme to generate the branch-name: E.g. `abt branch git asana`" end
usage()
click to toggle source
# File lib/abt/providers/git/commands/branch.rb, line 8 def self.usage "abt branch git <scheme>[:<path>]" end
Public Instance Methods
perform()
click to toggle source
# File lib/abt/providers/git/commands/branch.rb, line 16 def perform switch || create_and_switch warn("Switched to #{branch_name}") end
Private Instance Methods
branch_name()
click to toggle source
# File lib/abt/providers/git/commands/branch.rb, line 40 def branch_name # rubocop:disable Metrics/MethodLength @branch_name ||= begin if branch_names_from_aris.empty? abort([ "None of the specified ARIs responded to `branch-name`.", "Did you add compatible scheme? e.g.:", " abt branch git asana", " abt branch git devops" ].join("\n")) end if branch_names_from_aris.length > 1 abort([ "Got branch names from multiple ARIs, only one is supported", "Branch names were:", *branch_names_from_aris.map { |name| " #{name}" } ].join("\n")) end branch_names_from_aris.first end end
branch_names_from_aris()
click to toggle source
# File lib/abt/providers/git/commands/branch.rb, line 63 def branch_names_from_aris return @branch_names_from_aris if instance_variable_defined?(:@branch_names_from_aris) abort("You must provide an additional ARI that responds to: branch-name. E.g., asana") if other_aris.empty? input = StringIO.new(cli.aris.to_s) output = StringIO.new Abt::Cli.new(argv: ["branch-name"], output: output, input: input).perform @branch_names_from_aris = output.string.lines.map(&:strip).compact end
create_and_switch()
click to toggle source
# File lib/abt/providers/git/commands/branch.rb, line 31 def create_and_switch warn("No such branch: #{branch_name}") abort("Aborting") unless cli.prompt.boolean("Create branch?", default: true) Open3.popen3("git switch -c #{branch_name}") do |_i, _o, _e, thread| thread.value end end
other_aris()
click to toggle source
# File lib/abt/providers/git/commands/branch.rb, line 75 def other_aris @other_aris ||= cli.aris - [ari] end
switch()
click to toggle source
# File lib/abt/providers/git/commands/branch.rb, line 23 def switch success = false Open3.popen3("git switch #{branch_name}") do |_i, _o, _e, thread| success = thread.value.success? end success end