Sha256: 14d31a39b75be1caa76843f40a996fff3126bf7e631bfb4622b6d16f8a6cd844

Contents?: true

Size: 1.34 KB

Versions: 12

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'eac_git/executables'
require 'eac_ruby_utils/core_ext'

module EacGit
  # A Git repository in local filesystem.
  class Local
    require_sub __FILE__

    common_constructor :root_path do
      self.root_path = root_path.to_pathname
    end

    def descendant?(descendant, ancestor)
      base = merge_base(descendant, ancestor)
      return false if base.blank?

      revparse = command('rev-parse', '--verify', ancestor).execute!.strip
      base == revparse
    end

    def merge_base(*commits)
      refs = commits.dup
      while refs.count > 1
        refs[1] = merge_base_pair(refs[0], refs[1])
        return nil if refs[1].blank?

        refs.shift
      end
      refs.first
    end

    def command(*args)
      ::EacGit::Executables.git.command('-C', root_path.to_path, *args)
    end

    def rev_parse(ref, required = false)
      r = command('rev-parse', ref).execute!(exit_outputs: { 128 => nil, 32_768 => nil })
      r.strip! if r.is_a?(String)
      return r if r.present?
      return nil unless required

      raise "Reference \"#{ref}\" not found"
    end

    def subrepo(subpath)
      ::EacGit::Local::Subrepo.new(self, subpath)
    end

    private

    def merge_base_pair(commit1, commit2)
      command('merge-base', commit1, commit2).execute!(exit_outputs: { 256 => nil }).strip
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
avm-tools-0.59.0 vendor/eac_git/lib/eac_git/local.rb
avm-tools-0.58.1 vendor/eac_git/lib/eac_git/local.rb
avm-tools-0.58.0 vendor/eac_git/lib/eac_git/local.rb
avm-tools-0.57.0 vendor/eac_git/lib/eac_git/local.rb
avm-tools-0.56.0 vendor/eac_git/lib/eac_git/local.rb
avm-tools-0.55.0 vendor/gems/eac_git/lib/eac_git/local.rb
avm-tools-0.54.2 vendor/gems/eac_git/lib/eac_git/local.rb
avm-tools-0.54.1 vendor/gems/eac_git/lib/eac_git/local.rb
avm-tools-0.54.0 vendor/gems/eac_git/lib/eac_git/local.rb
eac_git-0.2.0 lib/eac_git/local.rb
eac_git-0.1.0 lib/eac_git/local.rb
avm-tools-0.53.0 vendor/gems/eac_git/lib/eac_git/local.rb