<commit_before># NOTE: Please don't depend on tasks without a description (`desc`) as they
# might change between minor or patch version releases. They make up the
# private API and internals of Capistrano::Rsync. If you think something should
# be public for extending and hooking, please let me know!

rsync_cache = lambda do
  cache = fetch(:rsync_cache)
  cache = deploy_to + "/" + cache if cache && cache !~ /^\//
  cache
end

# PATCH https://github.com/moll/capistrano-rsync/pull/13
# Use cap3's load:defaults to set default vars so that they can be overridden.
namespace :load do
  task :defaults do
    set :rsync_options, %w[--recursive --delete --delete-excluded  --exclude .git*]
    set :rsync_copy, "rsync --archive --acls --xattrs"

    # Stage is used on your local machine for rsyncing from.
    set :rsync_stage, "tmp/deploy"

    # Cache is used on the server to copy files to from to the release
    # directory. Saves you rsyncing your whole app folder each time. If you nil
    # rsync_cache, Capistrano::Rsync will sync straight to the release path.
    set :rsync_cache, "shared/deploy"
  end
end


Rake::Task["deploy:check"].enhance ["rsync:hook_scm"]
Rake::Task["deploy:updating"].enhance ["rsync:hook_scm"]

desc "Stage and rsync to the server (or its cache)."
task :rsync => %w[rsync:stage] do
  roles(:all).each do |role|
    user = role.user + "@" if !role.user.nil?

    rsync = %w[rsync]
    rsync.concat fetch(:rsync_options)
    rsync << fetch(:rsync_stage) + "/"
    rsync << "#{user}#{role.hostname}:#{rsync_cache.call || release_path}"

    Kernel.system *rsync
  end
end

namespace :rsync do
  task :hook_scm do
    Rake::Task.define_task("#{scm}:check") do
      invoke "rsync:check" 
    end

    Rake::Task.define_task("#{scm}:create_release") do
      invoke "rsync:release" 
    end
  end

  task :check do
    # Everything's a-okay inherently!
  end

  task :create_stage do
    next if File.directory?(fetch(:rsync_stage))

    clone = %W[git clone]
    clone << fetch(:repo_url, ".")
    clone << fetch(:rsync_stage)
    run_locally { execute *clone }
  end

  desc "Stage the repository in a local directory."
  task :stage => %w[create_stage] do
    Dir.chdir fetch(:rsync_stage) do
      update = %W[git fetch --quiet --all --prune]
      run_locally { execute *update }

      checkout = %W[git reset --hard origin/#{fetch(:branch)}]
      run_locally { execute *checkout }

      # PATCH https://github.com/moll/capistrano-rsync/pull/8
      set :current_revision, "#{`git rev-parse --short HEAD`}".chomp
    end
  end

  desc "Copy the code to the releases directory."
  task :release => %w[rsync] do
    # Skip copying if we've already synced straight to the release directory.
    next if !fetch(:rsync_cache)

    copy = %(#{fetch(:rsync_copy)} "#{rsync_cache.call}/" "#{release_path}/")<commit_msg>rsync recipe will clone the new repo_url if repo_url changed<commit_after># NOTE: Please don't depend on tasks without a description (`desc`) as they
# might change between minor or patch version releases. They make up the
# private API and internals of Capistrano::Rsync. If you think something should
# be public for extending and hooking, please let me know!

rsync_cache = lambda do
  cache = fetch(:rsync_cache)
  cache = deploy_to + "/" + cache if cache && cache !~ /^\//
  cache
end

# PATCH https://github.com/moll/capistrano-rsync/pull/13
# Use cap3's load:defaults to set default vars so that they can be overridden.
namespace :load do
  task :defaults do
    set :rsync_options, %w[--recursive --delete --delete-excluded  --exclude .git*]
    set :rsync_copy, "rsync --archive --acls --xattrs"

    # Stage is used on your local machine for rsyncing from.
    set :rsync_stage, "tmp/deploy"

    # Cache is used on the server to copy files to from to the release
    # directory. Saves you rsyncing your whole app folder each time. If you nil
    # rsync_cache, Capistrano::Rsync will sync straight to the release path.
    set :rsync_cache, "shared/deploy"
  end
end


Rake::Task["deploy:check"].enhance ["rsync:hook_scm"]
Rake::Task["deploy:updating"].enhance ["rsync:hook_scm"]

desc "Stage and rsync to the server (or its cache)."
task :rsync => %w[rsync:stage] do
  roles(:all).each do |role|
    user = role.user + "@" if !role.user.nil?

    rsync = %w[rsync]
    rsync.concat fetch(:rsync_options)
    rsync << fetch(:rsync_stage) + "/"
    rsync << "#{user}#{role.hostname}:#{rsync_cache.call || release_path}"

    Kernel.system *rsync
  end
end

namespace :rsync do
  task :hook_scm do
    Rake::Task.define_task("#{scm}:check") do
      invoke "rsync:check" 
    end

    Rake::Task.define_task("#{scm}:create_release") do
      invoke "rsync:release" 
    end
  end

  task :check do
    # Everything's a-okay inherently!
  end

  task :create_stage do
    repo_url = fetch(:repo_url, ".")
    deploy_cache_dir = fetch(:rsync_stage)
    if File.directory?(deploy_cache_dir)
      repo_url_changed = false
      Dir.chdir deploy_cache_dir do
        absolute_repo_url = File.absolute_path(repo_url)
        absolute_cache_repo_url = File.absolute_path(`git config --get remote.origin.url`.chomp)
        repo_url_changed = (absolute_repo_url != absolute_cache_repo_url)
      end

      if repo_url_changed
        run_locally { execute :rm, "-rf", deploy_cache_dir }
      else
        next
      end
    end

    clone = %W[git clone]
    clone << repo_url
    clone << deploy_cache_dir
    run_locally { execute *clone }
  end

  desc "Stage the repository in a local directory."
  task :stage => %w[create_stage] do
    Dir.chdir fetch(:rsync_stage) do
      update = %W[git fetch --quiet --all --prune]
      run_locally { execute *update }

      checkout = %W[git reset --hard origin/#{fetch(:branch)}]
      run_locally { execute *checkout }

      # PATCH https://github.com/moll/capistrano-rsync/pull/8
      set :current_revision, "#{`git rev-parse --short HEAD`}".chomp
    end
  end

  desc "Copy the code to the releases directory."
  task :release => %w[rsync] do
    # Skip copying if we've already synced straight to the release directory.
    next if !fetch(:rsync_cache)

    copy = %(#{fetch(:rsync_copy)} "#{rsync_cache.call}/" "#{release_path}/")
{'fraction_non_alphanumeric': 0.12027546444586804, 'fraction_numerical': 0.0012812299807815502, 'mean_word_length': 3.327789327789328, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 9, 'https://': 4, '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': '5967317', 'n_tokens_mistral': 2097, 'n_tokens_neox': 2034, 'n_words': 634}