class YJCocoa::GitPull

Attributes

all[RW]

property

gits[RW]

Public Class Methods

new(argv) click to toggle source

初始化

Calls superclass method
# File lib/yjcocoa/git/git_pull.rb, line 29
def initialize(argv)
    super
    self.all = argv.flag?('all', false)
end
options() click to toggle source
# File lib/yjcocoa/git/git_pull.rb, line 20
def self.options
    [['--all', 'pull all branch'],]
end

Public Instance Methods

buildGitPaths() click to toggle source
# File lib/yjcocoa/git/git_pull.rb, line 48
def buildGitPaths
    self.gits = Dir["**/.git"]
    self.gits.map! { |path|
        File.dirname(path)
    }
end
gitPull(path=".") click to toggle source
# File lib/yjcocoa/git/git_pull.rb, line 55
def gitPull(path=".")
    thread = Thread.new {
        Dir.chdir(path) {
            puts "YJCocoa git pull #{path}/.git".green
            localChanges = !(`git stash` =~ /No local changes to save/)
            system("git pull -p")
            if self.all
                list = (`git branch`).split("\n")
                if list.size >= 2
                    headBranch = "master"
                    list.each { |item|
                        if item =~ /\* /
                            headBranch = item.gsub(/\* /, "")
                        else
                            `git checkout #{item}`
                            system("git pull")
                        end
                    }
                    `git checkout #{headBranch}`
                end
            end
            `git stash pop` if localChanges
            puts
        }
    }
    thread.join
end
run() click to toggle source

businrss

# File lib/yjcocoa/git/git_pull.rb, line 35
def run
    self.buildGitPaths
    if self.gits.empty?
        if self.gitExist?
            self.gitPull
        end
    else
        self.gits.each { |path|
            self.gitPull(path)
        }
    end
end