class GitCommands::Branch
Constants
- DEFAULT
- ORIGIN
Attributes
name[R]
Public Class Methods
by_file(path)
click to toggle source
# File lib/git_commands/branch.rb, line 13 def self.by_file(path) return [] unless valid_path?(path) File.foreach(path).map do |name| new(name.strip) end.select(&:valid?) end
by_names(names_list)
click to toggle source
# File lib/git_commands/branch.rb, line 27 def self.by_names(names_list) String(names_list).split(",").map do |name| new(name.strip) end.select(&:valid?) end
by_pattern(pattern)
click to toggle source
# File lib/git_commands/branch.rb, line 20 def self.by_pattern(pattern) return [] unless pattern.index("*") `git branch -r --list #{ORIGIN}/#{pattern}`.split("\n").map do |name| new(strip_origin(name)) end.reject(&:default?) end
factory(src)
click to toggle source
# File lib/git_commands/branch.rb, line 33 def self.factory(src) return [] unless src branches = by_file(src) branches = by_pattern(src) if branches.empty? branches = by_names(src) if branches.empty? branches end
new(name)
click to toggle source
# File lib/git_commands/branch.rb, line 48 def initialize(name) @name = name end
strip_origin(name)
click to toggle source
# File lib/git_commands/branch.rb, line 9 def self.strip_origin(name) name.strip.split("#{ORIGIN}/").last end
valid_path?(path)
click to toggle source
# File lib/git_commands/branch.rb, line 41 def self.valid_path?(path) path = Pathname.new(path) path.absolute? && path.file? end
Public Instance Methods
==(other)
click to toggle source
# File lib/git_commands/branch.rb, line 62 def ==(other) self.name == other.name end
default?()
click to toggle source
# File lib/git_commands/branch.rb, line 66 def default? @name == DEFAULT end
exists?(remote = true)
click to toggle source
# File lib/git_commands/branch.rb, line 70 def exists?(remote = true) origin = "#{ORIGIN}/" if remote `git rev-parse --verify #{origin}#{@name} 2> /dev/null`.match(/^[0-9a-z]+/) end
to_s()
click to toggle source
# File lib/git_commands/branch.rb, line 52 def to_s @name end
valid?()
click to toggle source
# File lib/git_commands/branch.rb, line 56 def valid? return false if default? return false unless exists? true end