class YJCocoa::GitBranch

Attributes

addBranch[RW]

property

deleteBranchs[RW]
gits[RW]

Public Class Methods

new(argv) click to toggle source

初始化

Calls superclass method
# File lib/yjcocoa/git/git_branch.rb, line 37
def initialize(argv)
    super
    self.addBranch = argv.option('add')
    self.deleteBranchs = argv.option('delete')
    self.deleteBranchs = self.deleteBranchs.split(",").reject {|i| i.empty? } if self.deleteBranchs
end
options() click to toggle source
# File lib/yjcocoa/git/git_branch.rb, line 26
def self.options
    [['--add', '增加branch并推送到服务器'],
    ['--delete', '删除多个branch并推送到服务器'],]
end

Public Instance Methods

buildGitPaths() click to toggle source
# File lib/yjcocoa/git/git_branch.rb, line 63
def buildGitPaths
    self.gits = Dir["**/.git"]
    self.gits.map! { |path|
        File.dirname(path)
    }
end
gitBranchAdd() click to toggle source
# File lib/yjcocoa/git/git_branch.rb, line 84
def gitBranchAdd
    puts "YJCocoa git add branch #{self.addBranch}".green
    system("git push --set-upstream origin #{self.addBranch}") if system("git checkout -b #{self.addBranch}")
end
gitBranchDelete() click to toggle source
# File lib/yjcocoa/git/git_branch.rb, line 89
def gitBranchDelete
    puts "YJCocoa git delete branchs #{self.deleteBranchs}".green
    self.deleteBranchs.each { |branch|
        system("git branch -d #{branch}")
        system("git push origin --delete #{branch}")
    }
end
gitRun(path=".") click to toggle source
# File lib/yjcocoa/git/git_branch.rb, line 70
def gitRun(path=".")
    thread = Thread.new {
        Dir.chdir(path) {
            puts "YJCocoa git #{path}/.git".green
            self.gitBranchDelete if self.deleteBranchs && !self.deleteBranchs.empty?
            if self.addBranch
                self.gitBranchAdd
                puts
            end                   
        }
    }
    thread.join
end
run() click to toggle source
# File lib/yjcocoa/git/git_branch.rb, line 50
def run    
    self.buildGitPaths        
    if self.gits.empty?
        if self.gitExist?
            self.gitRun
        end
    else
        self.gits.each { |path|
            self.gitRun(path)
        }
    end
end
validate!() click to toggle source

businrss

Calls superclass method
# File lib/yjcocoa/git/git_branch.rb, line 45
def validate!
    super
    self.banner! unless self.addBranch || self.deleteBranchs
end