Sha256: ba6220d0a56af81f415897672c1647a229489991d562c1ffe0941c4980a90ffa

Contents?: true

Size: 1.3 KB

Versions: 28

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require 'eac_git/local'
require 'eac_ruby_utils/envs'
require 'fileutils'
require 'tmpdir'

module EacGit
  module Rspec
    module StubbedGitLocalRepo
      def stubbed_git_local_repo(bare = false)
        path = ::Dir.mktmpdir
        ::EacRubyUtils::Envs.local.command(stubbed_git_local_repo_args(path, bare)).execute!
        repo = StubbedGitRepository.new(path)
        repo.command('config', 'user.email', 'theuser@example.net').execute!
        repo.command('config', 'user.name', 'The User').execute!
        repo
      end

      private

      def stubbed_git_local_repo_args(path, bare)
        r = %w[git init]
        r << '--bare' if bare
        r + [path]
      end

      class StubbedGitRepository < ::EacGit::Local
        def file(*subpath)
          StubbedGitRepositoryFile.new(self, subpath)
        end
      end

      class StubbedGitRepositoryFile
        attr_reader :git, :subpath

        def initialize(git, subpath)
          @git = git
          @subpath = subpath
        end

        def path
          git.root_path.join(*subpath)
        end

        def touch
          ::FileUtils.touch(path.to_path)
        end

        def delete
          path.unlink
        end

        def write(content)
          path.write(content)
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
avm-tools-0.99.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.98.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.97.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.96.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
eac_git-0.4.2 lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.95.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
eac_git-0.4.1 lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.94.3 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb