<commit_before>require 'enzyme'

module Sync extend self

  def run
    skip_resources = !!ARGV.delete("--skip-resources")
    skip_production = !!ARGV.delete("--skip-production")
    ARGV.each { |x| raise UnknownOption.new(x) if x.start_with?("-") }
    project_name = ARGV.shift || $settings.project_name
    ARGV.each { |x| raise UnknownArgument.new(x) }

    raise ArgumentOrSettingMissing.new("project_name", "project_name") unless project_name
    raise SettingMissing.new("projects_directory") unless $settings.projects_directory

    directory = "#{$settings.projects_directory}/#{project_name}"

    raise CannotFindProject.new(directory) unless File.directory?(directory)

    # BASE

    system "cd #{directory}"
    Dir.chdir("#{directory}")

    system "git add .enzyme.yml > /dev/null"
    system "git commit -m 'Enzyme sync.'"
    system "git pull > /dev/null"
    system "git push > /dev/null"

    # SHARED

    unless skip_resources
      system "cd #{directory}/resources"
      Dir.chdir("#{directory}/resources")

      system "git checkout -q . > /dev/null"
      system "git add . > /dev/null"
      system "git commit -m 'Enzyme sync.'"
      system "git pull > /dev/null"
      system "git push > /dev/null"
    end

    # WORKING

    system "cd #{directory}/production"
    Dir.chdir("#{directory}/production")

    system "git add #{$settings.short_name} > /dev/null"
    system "git add -u > /dev/null"
    system "git commit -a -m 'Enzyme sync.'"
    system "git clean -fd > /dev/null"
    system "git pull > /dev/null"
    system "git push > /dev/null"
  end

end

Enzyme.register('sync', Sync) do
  puts "#{$format.bold}SYNOPSIS#{$format.normal}"
  puts '     enzyme sync [<project_name>] [--discard-changes] [--init]'
  puts
  puts "#{$format.bold}DESCRIPTION#{$format.normal}"
  puts '     Options:'
  puts
  puts "     #{$format.bold}<project_name>#{$format.normal}"
  puts '             The name of the project to sync. If the production directory is the root of a project this option does not need to be passed.'
  puts
  puts "#{$format.bold}EXAMPLES#{$format.normal}"
  puts '     You can run sync like this:'
  puts
  puts '     enzyme sync another_project'
  puts '             If you specify a project you can run sync from anywhere.'<commit_msg>Update SHARED/RESOURCES and WORKING/PRODUCTION comments.<commit_after>require 'enzyme'

module Sync extend self

  def run
    skip_resources = !!ARGV.delete("--skip-resources")
    skip_production = !!ARGV.delete("--skip-production")
    ARGV.each { |x| raise UnknownOption.new(x) if x.start_with?("-") }
    project_name = ARGV.shift || $settings.project_name
    ARGV.each { |x| raise UnknownArgument.new(x) }

    raise ArgumentOrSettingMissing.new("project_name", "project_name") unless project_name
    raise SettingMissing.new("projects_directory") unless $settings.projects_directory

    directory = "#{$settings.projects_directory}/#{project_name}"

    raise CannotFindProject.new(directory) unless File.directory?(directory)

    # BASE

    system "cd #{directory}"
    Dir.chdir("#{directory}")

    system "git add .enzyme.yml > /dev/null"
    system "git commit -m 'Enzyme sync.'"
    system "git pull > /dev/null"
    system "git push > /dev/null"

    # RESOURCES

    unless skip_resources
      system "cd #{directory}/resources"
      Dir.chdir("#{directory}/resources")

      system "git checkout -q . > /dev/null"
      system "git add . > /dev/null"
      system "git commit -m 'Enzyme sync.'"
      system "git pull > /dev/null"
      system "git push > /dev/null"
    end

    # PRODUCTION

    system "cd #{directory}/production"
    Dir.chdir("#{directory}/production")

    system "git add #{$settings.short_name} > /dev/null"
    system "git add -u > /dev/null"
    system "git commit -a -m 'Enzyme sync.'"
    system "git clean -fd > /dev/null"
    system "git pull > /dev/null"
    system "git push > /dev/null"
  end

end

Enzyme.register('sync', Sync) do
  puts "#{$format.bold}SYNOPSIS#{$format.normal}"
  puts '     enzyme sync [<project_name>] [--discard-changes] [--init]'
  puts
  puts "#{$format.bold}DESCRIPTION#{$format.normal}"
  puts '     Options:'
  puts
  puts "     #{$format.bold}<project_name>#{$format.normal}"
  puts '             The name of the project to sync. If the production directory is the root of a project this option does not need to be passed.'
  puts
  puts "#{$format.bold}EXAMPLES#{$format.normal}"
  puts '     You can run sync like this:'
  puts
  puts '     enzyme sync another_project'
  puts '             If you specify a project you can run sync from anywhere.'
{'fraction_non_alphanumeric': 0.136, 'fraction_numerical': 0.0, 'mean_word_length': 3.0437062937062938, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '193738', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1436, 'n_words': 411}