Class: Zio::Branch
- Inherits:
-
Object
- Object
- Zio::Branch
- Defined in:
- lib/zio/branch.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #_paths ⇒ Object
- #checkout ⇒ Object
-
#initialize(options = {}) ⇒ Branch
constructor
A new instance of Branch.
Constructor Details
#initialize(options = {}) ⇒ Branch
Returns a new instance of Branch.
6 7 8 9 |
# File 'lib/zio/branch.rb', line 6 def initialize( = {}) @options = raise MISSING_ARGUMENTS unless [:dir] || [:set] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/zio/branch.rb', line 5 def @options end |
Instance Method Details
#_paths ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/zio/branch.rb', line 34 def _paths return [:set] unless [:set].nil? @_paths ||= begin Dir.foreach([:dir]).map do |path| next if path == '.' || path == '..' || !File.exist?(File.(path, [:dir]) + '/.git') ab_path = File.(path, [:dir]) File.directory?(ab_path) ? ab_path : nil end.compact end end |
#checkout ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/zio/branch.rb', line 11 def checkout _paths.each do |path| puts sprintf("\nProcessing - #{path}").color(:green) puts sprintf('---------------------------').color(:green) stdout, stderr, status = Open3.capture3("cd #{path} && git stash && git rev-parse --verify #{[:branch]}") # Branch does not exists if status.exitstatus != 0 puts "Branch #{[:branch]} does not exists yet!".color(:blue) if [:force] puts "Creating new branch - #{[:branch]}".color(:blue) stdout, stderr, status = Open3.capture3( "cd #{path} && git checkout #{[:base_branch]} && git checkout -b #{[:branch]}" ) puts stdout.color(:blue) end else stdout, stderr, status = Open3.capture3("cd #{path} && git checkout #{[:branch]}") puts sprintf("%s%s", stderr.color(:red), stdout.color(:blue)) end end end |