Class: YJCocoa::GitBranch

Inherits:
Git
  • Object
show all
Defined in:
lib/yjcocoa/git/git_branch.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) ⇒ GitBranch

初始化



36
37
38
39
40
41
# File 'lib/yjcocoa/git/git_branch.rb', line 36

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

Instance Attribute Details

#addBranchObject

property



32
33
34
# File 'lib/yjcocoa/git/git_branch.rb', line 32

def addBranch
  @addBranch
end

#deleteBranchsObject

Returns the value of attribute deleteBranchs.



33
34
35
# File 'lib/yjcocoa/git/git_branch.rb', line 33

def deleteBranchs
  @deleteBranchs
end

Class Method Details

.optionsObject



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

def self.options
    [['--add', '增加branch并推送到服务器'],
    ['--delete', '删除多个branch并推送到服务器'],]
end

Instance Method Details

#gitBranchAddObject



57
58
59
60
# File 'lib/yjcocoa/git/git_branch.rb', line 57

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

#gitBranchDeleteObject



62
63
64
65
66
67
68
# File 'lib/yjcocoa/git/git_branch.rb', line 62

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

#runObject



49
50
51
52
53
54
55
# File 'lib/yjcocoa/git/git_branch.rb', line 49

def run
    if self.addBranch
        self.gitBranchAdd
        puts
    end
    self.gitBranchDelete if self.deleteBranchs && !self.deleteBranchs.empty?
end

#validate!Object

businrss



44
45
46
47
# File 'lib/yjcocoa/git/git_branch.rb', line 44

def validate!
    exit 0 unless self.gitExist?
    self.banner! unless self.addBranch || self.deleteBranchs
end