<commit_before>require 'fpm/cookery/source_handler/template'

module FPM
  module Cookery
    class SourceHandler
      class Git < FPM::Cookery::SourceHandler::Template
        CHECKSUM = false
        NAME = :git

        def fetch
          if local_path.exist?
            Dir.chdir(local_path) do
              git('fetch', url)
            end
          else
            Dir.chdir(cachedir) do
              git('clone', url, local_path)
            end
          end

          local_path
        end

        def extract
          extracted_source = (builddir/local_path.basename.to_s).to_s

          Dir.chdir(local_path) do
            if options[:sha]
              git('reset', '--hard', options[:sha])
            elsif options[:tag]
              git('checkout', '-f', options[:tag])
            elsif options[:branch]
              git('checkout', '-f', "origin/#{options[:branch]}")
            else
              git('checkout', '-f', 'origin/HEAD')
            end

            # Trailing '/' is important! (see git-checkout-index(1))
            git('checkout-index', '-a', '-f', "--prefix=#{extracted_source}/")
          end

          extracted_source
        end

        private
        def git(command, *args)
          #puts "[DEBUG] git #{command} #{args.join(' ')}"
          safesystem('git', command, *args)
        end
      end
    end
  end
end<commit_msg>Nicer name for the extracted source directory.<commit_after>require 'fpm/cookery/source_handler/template'

module FPM
  module Cookery
    class SourceHandler
      class Git < FPM::Cookery::SourceHandler::Template
        CHECKSUM = false
        NAME = :git

        def fetch
          if local_path.exist?
            Dir.chdir(local_path) do
              git('fetch', url)
            end
          else
            Dir.chdir(cachedir) do
              git('clone', url, local_path)
            end
          end

          local_path
        end

        def extract
          extracted_source = (builddir/local_path.basename('.git').to_s).to_s

          Dir.chdir(local_path) do
            if options[:sha]
              git('reset', '--hard', options[:sha])
              extracted_source << "-#{options[:sha]}"
            elsif options[:tag]
              git('checkout', '-f', options[:tag])
              extracted_source << "-tag-#{options[:tag]}"
            elsif options[:branch]
              git('checkout', '-f', "origin/#{options[:branch]}")
              extracted_source << "-branch-#{options[:branch]}"
            else
              git('checkout', '-f', 'origin/HEAD')
              extracted_source << '-HEAD'
            end

            # Trailing '/' is important! (see git-checkout-index(1))
            git('checkout-index', '-a', '-f', "--prefix=#{extracted_source}/")
          end

          extracted_source
        end

        private
        def git(command, *args)
          #puts "[DEBUG] git #{command} #{args.join(' ')}"
          safesystem('git', command, *args)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12833168805528133, 'fraction_numerical': 0.0006581112207963146, 'mean_word_length': 1.600513259195894, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, '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': '7470892', 'n_tokens_mistral': 858, 'n_tokens_neox': 850, 'n_words': 191}