class YJCocoa::GitCheckout

Attributes

branch[RW]

property

gits[RW]

Public Class Methods

new(argv) click to toggle source

初始化

Calls superclass method
# File lib/yjcocoa/git/git_checkout.rb, line 29
def initialize(argv)
    super
    self.branch = argv.option('branch')
end
options() click to toggle source
# File lib/yjcocoa/git/git_checkout.rb, line 20
def self.options
    [['--branch', '切换 branch'],]
end

Public Instance Methods

buildGitPaths() click to toggle source
# File lib/yjcocoa/git/git_checkout.rb, line 52
def buildGitPaths
    self.gits = Dir["**/.git"]
    self.gits.map! { |path|
        File.dirname(path)
    }
end
gitCheckout(path=".") click to toggle source
# File lib/yjcocoa/git/git_checkout.rb, line 59
def gitCheckout(path=".")
    Dir.chdir(path) {
        puts "YJCocoa git checkout #{path}/.git".green
        localChanges = !(`git stash` =~ /No local changes to save/)
        system("git checkout -b #{self.branch}") unless system("git checkout #{self.branch}")
        `git stash pop` if localChanges
        puts
    }
end
run() click to toggle source
# File lib/yjcocoa/git/git_checkout.rb, line 39
def run
    self.buildGitPaths
    if self.gits.empty?
        if self.gitExist?
            self.gitCheckout
        end
    else
        self.gits.each { |path|
            self.gitCheckout(path)
        }
    end
end
validate!() click to toggle source

businrss

# File lib/yjcocoa/git/git_checkout.rb, line 35
def validate!
    self.banner! unless self.branch
end