Class: YJCocoa::GitCheckout
- Defined in:
- lib/yjcocoa/git/git_checkout.rb
Constant Summary
Constants inherited from Command
Instance Attribute Summary collapse
-
#branch ⇒ Object
property.
-
#gits ⇒ Object
Returns the value of attribute gits.
Class Method Summary collapse
Instance Method Summary collapse
- #buildGitPaths ⇒ Object
- #gitCheckout(path = ".") ⇒ Object
-
#initialize(argv) ⇒ GitCheckout
constructor
初始化.
- #run ⇒ Object
-
#validate! ⇒ Object
businrss.
Methods inherited from Git
Methods inherited from Command
Constructor Details
#initialize(argv) ⇒ GitCheckout
初始化
29 30 31 32 |
# File 'lib/yjcocoa/git/git_checkout.rb', line 29 def initialize(argv) super self.branch = argv.option('branch') end |
Instance Attribute Details
#branch ⇒ Object
property
25 26 27 |
# File 'lib/yjcocoa/git/git_checkout.rb', line 25 def branch @branch end |
#gits ⇒ Object
Returns the value of attribute gits.
26 27 28 |
# File 'lib/yjcocoa/git/git_checkout.rb', line 26 def gits @gits end |
Class Method Details
.options ⇒ Object
20 21 22 |
# File 'lib/yjcocoa/git/git_checkout.rb', line 20 def self. [['--branch', '切换 branch'],] end |
Instance Method Details
#buildGitPaths ⇒ Object
52 53 54 55 56 57 |
# 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 = ".") ⇒ Object
59 60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# 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! ⇒ Object
businrss
35 36 37 |
# File 'lib/yjcocoa/git/git_checkout.rb', line 35 def validate! self. unless self.branch end |