Class: YJCocoa::GitPull

Inherits:
Git
  • Object
show all
Defined in:
lib/yjcocoa/git/git_pull.rb

Constant Summary

Constants inherited from Command

Command::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Git

#gitExist?

Methods inherited from Command

#askWithAnswers

Constructor Details

#initialize(argv) ⇒ GitPull

初始化



29
30
31
32
# File 'lib/yjcocoa/git/git_pull.rb', line 29

def initialize(argv)
    super
    self.all = argv.flag?('all', false)
end

Instance Attribute Details

#allObject

property



25
26
27
# File 'lib/yjcocoa/git/git_pull.rb', line 25

def all
  @all
end

#gitsObject

git array



26
27
28
# File 'lib/yjcocoa/git/git_pull.rb', line 26

def gits
  @gits
end

Class Method Details

.optionsObject



20
21
22
# File 'lib/yjcocoa/git/git_pull.rb', line 20

def self.options
    [['--all', 'pull all branch'],]
end

Instance Method Details

#buildGitPathsObject



48
49
50
51
52
53
# 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 = ".") ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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

#runObject

businrss



35
36
37
38
39
40
41
42
43
44
45
46
# 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