module Mono

experimental stuff

note: use a different module/namespace

for the gem version info e.g. MonoCore vs Mono

add a convenience shortcut for now - why? why not?

Constants

VERSION

Public Class Methods

clone( name, depth: nil ) click to toggle source
# File lib/mono/base.rb, line 48
def self.clone( name, depth: nil ) MonoGitHub.clone( name, depth: depth ); end
monofile() click to toggle source
# File lib/mono.rb, line 42
def self.monofile
  path = Monofile.find

  if path
    Monofile.read( path )
  else
    puts "!! WARN: no mono configuration file found; looking for #{Monofile::NAMES.join(', ')} in (#{Dir.getwd})"
    Monofile.new   ## return empty set -todo/check: return nil - why? why not?
  end
end
open( name, &block ) click to toggle source

add some short cuts

# File lib/mono/base.rb, line 47
def self.open( name, &block )      MonoGitProject.open( name, &block ); end
sync( name ) click to toggle source

add some more “porcelain” helpers

# File lib/mono/base.rb, line 52
def self.sync( name )
   ## add some options - why? why not?
   ##  -  :readonly    - auto-adds  depth: 1 on clone or such - why? why not?
   ##  -  :clone  true/false  - do NOT clone only fast forward or such - why? why not?
   ##  -  :clean  true/false or similar  - only clone repos; no fast forward
   ##  others - ideas -- ??

   ## note: allow passing in (reusing) of mononames too
   mononame =  name.is_a?( Mononame ) ? name : Mononame.parse( name )
   if mononame.exist?
     MonoGitProject.open( mononame ) do |proj|
       if proj.changes?
         puts "!! WARN - local changes in workdir; skipping fast forward (remote) sync / merge"
       else
         proj.fast_forward   ## note: use git pull --ff-only (fast forward only - do NOT merge)
       end
     end
   else
     MonoGitHub.clone( mononame )
   end
end
walk( path=root) click to toggle source
lint/print mono (source) tree
  - check for git repos (via .git/ dir)

turn into

- tree or
- lint or
- doctor or
- check or such command - why? why not?
# File lib/mono/experimental.rb, line 16
def self.walk( path=root)
   repos = walk_dir( path )
   repos
end

Private Class Methods

walk_dir( path, repos=[], level=1, depth: nil ) click to toggle source

todo/check - use max_depth or max_level or such - why? why not?

# File lib/mono/experimental.rb, line 27
def self.walk_dir( path, repos=[], level=1, depth: nil )
  entries = Dir.entries(path)

  ## filter dirs
  dirs = entries.select do |entry|
    if ['..', '.'].include?( entry )  ## first check for excludes
      false
    else
      full_path = File.join( path, entry )
      File.directory?( full_path )
    end
  end

  if dirs.size == 0   ## shortcircuit - no dirs in dir
    return repos
  end

  repos_count = 0  ## note: local (only) repos count
  warns_count = 0
  sub_dirs = []



  buf = String.new('')    ## use an output buffer (allows optional print)


  buf << ">#{path}< - level #{level}:\n"
  dirs.each do |entry|
    next if ['..', '.', '.git'].include?( entry )
    full_path = File.join( path, entry )

    if Dir.exist?( File.join( full_path, '.git' ))
      repos_count += 1

      if level == 1
        warns_count += 1
        buf << "!! WARN - top-level repo (w/o user/org) >#{entry}< @ #{path}\n"
      end

      if level > 2
        warns_count += 1
        buf << "!! WARN - hidden (?) sub-level #{level} repo (nested too deep?) >#{entry}< @ #{path}\n"
      end

      buf << "    repo ##{'%-2d' % repos_count} | "
      buf << "#{'%-20s' % entry} @ #{File.basename(path)} (#{path})"
      buf << "\n"
      repos << full_path

    ## check for bare bone git repos  - todo/fix: add .gitconfig or such and more - why? why not?
    elsif Dir.exist?( File.join( full_path, 'hooks' )) &&
          Dir.exist?( File.join( full_path, 'info' )) &&
          Dir.exist?( File.join( full_path, 'objects' )) &&
          Dir.exist?( File.join( full_path, 'refs' ))
      warns_count += 1
      buf << "!! WARN - skip bare git repo >#{entry}< @ #{path}\n"
    else
      buf << "     x  >#{entry}<\n"
      sub_dirs << entry
    end
  end
  buf << "  #{repos_count} repos(s), #{dirs.size} dir(s), #{warns_count} warn(s)\n"
  buf << "\n"

  ## note: skip output of "plain" diretory listings (no repos, no warnings)
  puts buf   if repos_count > 0 || warns_count > 0


  sub_dirs.each do |entry|
    ## continue walking
    full_path = File.join( path, entry )
    walk_dir( full_path, repos, level+1, depth: depth )
  end

  repos
end