Skip to content

Instantly share code, notes, and snippets.

@aripalo
Last active October 19, 2016 22:07
Show Gist options
  • Select an option

  • Save aripalo/b544370b124b23de8c07f81b38e6721f to your computer and use it in GitHub Desktop.

Select an option

Save aripalo/b544370b124b23de8c07f81b38e6721f to your computer and use it in GitHub Desktop.

Revisions

  1. aripalo revised this gist Oct 19, 2016. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions collect-ebignore-files.rb
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@
    # Remove .ebignore itself
    files = files.reject { |f| f == '.ebignore' }

    # Read the .ebignore file
    ebignore_path = File.join(Dir.pwd, '.ebignore')
    ebignore_rules = File.readlines(ebignore_path)
    ebignore_rules = ebignore_rules.reject {|line| line.empty? || line == "\n"}.reject {|line| line.start_with?('#')}.map {|line| line.strip}
    @@ -35,16 +36,20 @@
    end
    end

    # Remove possible duplicates
    included_files.uniq
    excluded_files.uniq

    # Not sure about this logic...? (have to test more)
    # works at least for "include everything except"-type of .ebignore files, like:
    # *
    # !foo
    # !bar
    excluded_files = excluded_files.reject{ |e| included_files.include? e }


    # Print out the results
    puts "excluded = ignored files:"
    puts excluded_files

    puts ""

    puts "included = files that are monitred by git:"
    puts included_files
  2. aripalo created this gist Oct 19, 2016.
    50 changes: 50 additions & 0 deletions collect-ebignore-files.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    # get files (also hidden ones with dot prefix)
    files = Dir.glob("{**/*}", File::FNM_DOTMATCH)

    # Remove folders from array as (git)ignore doesn't care about empty folders
    files = files.reject { |f| File.directory?(f) }

    # Remove .ebignore itself
    files = files.reject { |f| f == '.ebignore' }

    ebignore_path = File.join(Dir.pwd, '.ebignore')
    ebignore_rules = File.readlines(ebignore_path)
    ebignore_rules = ebignore_rules.reject {|line| line.empty? || line == "\n"}.reject {|line| line.start_with?('#')}.map {|line| line.strip}

    # Arrays to store files
    included_files = [] # a.k.a. files that will be zipped
    excluded_files = [] # a.k.a. ignored files

    # Go through each ebignore rule for file
    files.each do |f|
    ebignore_rules.each do |ignore_pattern|

    # account for 'dir' and 'dir/' patterns
    if File.directory?(ignore_pattern.gsub(/^!/, ''))
    ignore_pattern.gsub!(/\/$/, '').concat('/**')
    end

    # handle inverted rules (e.g. !foo) and normal rules
    if ignore_pattern.start_with?('!')
    matches_rule = File.fnmatch(ignore_pattern.gsub(/^!/, ''), f, File::FNM_DOTMATCH)
    if matches_rule then included_files.push(f) end
    else
    matches_rule = File.fnmatch(ignore_pattern, f, File::FNM_DOTMATCH)
    if matches_rule then excluded_files.push(f) end
    end
    end
    end

    included_files.uniq
    excluded_files.uniq

    excluded_files = excluded_files.reject{ |e| included_files.include? e }


    puts "excluded = ignored files:"
    puts excluded_files

    puts ""

    puts "included = files that are monitred by git:"
    puts included_files