Sha256: 68d4240ebf9381829872baf0bcf8286a34aa74e3dcd8088ad638eaecaedf82fd

Contents?: true

Size: 692 Bytes

Versions: 12

Compression:

Stored size: 692 Bytes

Contents

require 'git-utils/command'

class Switch < Command

  def parser
    OptionParser.new do |opts|
      opts.banner = "Usage: git switch <pattern>"
      opts.on_tail("-h", "--help", "this usage guide") do
        puts opts.to_s; exit 0
      end
    end
  end

  # Returns the branch to switch to.
  # When multiple branches match, switch to the first one.
  def other_branch
    @other_branch ||= `git branch | grep #{pattern}`.split.first
  end

  # Returns a command appropriate for executing at the command line.
  def cmd
    "git checkout #{other_branch}"
  end

  private

    # Returns the pattern of the branch to switch to.
    def pattern
      self.known_options.first
    end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
git-utils-2.4.0 lib/git-utils/switch.rb
git-utils-2.3.0 lib/git-utils/switch.rb
git-utils-2.2.1 lib/git-utils/switch.rb
git-utils-2.2.0 lib/git-utils/switch.rb
git-utils-2.1.0 lib/git-utils/switch.rb
git-utils-2.0.0 lib/git-utils/switch.rb
git-utils-1.0.0 lib/git-utils/switch.rb
git-utils-0.7.1 lib/git-utils/switch.rb
git-utils-0.7.0 lib/git-utils/switch.rb
git-utils-0.6.5 lib/git-utils/switch.rb
git-utils-0.6.4 lib/git-utils/switch.rb
git-utils-0.6.3 lib/git-utils/switch.rb