<commit_before>require "serverkit/resources/base"

module Serverkit
  module Resources
    class Git < Base
      DEFAULT_STATE = "cloned"

      attribute :path, required: true, type: String
      attribute :repository, required: true, type: String
      attribute :state, default: DEFAULT_STATE, type: String

      # @note Override
      def apply
        _clone if clonable?
        update if updatable?
      end

      # @note Override
      def check
        has_git? && cloned? && !updatable?
      end

      private

      def clonable?
        !cloned?
      end

      # @note #clone is reserved ;(
      def _clone
        run_command("git clone #{repository} #{path}")
      end

      def cloned?
        check_command_from_identifier(:check_file_is_directory, git_path)
      end

      # @return [String] Path to .git directory in the cloned repository
      def git_path
        ::File.join(path, ".git")
      end<commit_msg>Improve validation on git resource<commit_after>require "serverkit/resources/base"

module Serverkit
  module Resources
    class Git < Base
      DEFAULT_STATE = "cloned"

      attribute :path, required: true, type: String
      attribute :repository, required: true, type: String
      attribute :state, default: DEFAULT_STATE, in: %w[cloned updated], type: String

      # @note Override
      def apply
        _clone if clonable?
        update if updatable?
      end

      # @note Override
      def check
        has_git? && cloned? && !updatable?
      end

      private

      def clonable?
        !cloned?
      end

      # @note #clone is reserved ;(
      def _clone
        run_command("git clone #{repository} #{path}")
      end

      def cloned?
        check_command_from_identifier(:check_file_is_directory, git_path)
      end

      # @return [String] Path to .git directory in the cloned repository
      def git_path
        ::File.join(path, ".git")
      end
{'fraction_non_alphanumeric': 0.08225556130367305, 'fraction_numerical': 0.0, 'mean_word_length': 2.2449664429530203, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6694405', 'n_tokens_mistral': 564, 'n_tokens_neox': 536, 'n_words': 174}