Sha256: 0f837242b5d2ee70e914dee9156f4d4524035c6e7ea2e5a63d57e66d354f3386

Contents?: true

Size: 927 Bytes

Versions: 55

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'ostruct'

module EacGit
  class Local
    module DirtyFiles
      STATUS_LINE_PATTERN = /\A(.)(.)\s(.+)\z/.freeze

      def dirty?
        dirty_files.any?
      end

      def dirty_file?(path)
        absolute_path = path.to_pathname.expand_path(root_path)
        dirty_files.any? do |df|
          df.absolute_path == absolute_path
        end
      end

      def dirty_files
        command('status', '--porcelain', '--untracked-files').execute!.each_line.map do |line|
          parse_status_line(line.gsub(/\n\z/, ''))
        end
      end

      private

      def parse_status_line(line)
        STATUS_LINE_PATTERN.if_match(line) do |m|
          ::OpenStruct.new(index: m[1], worktree: m[2], path: m[3].to_pathname,
                           absolute_path: m[3].to_pathname.expand_path(root_path))
        end
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 2 rubygems

Version Path
avm-tools-0.94.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.93.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.92.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.91.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.90.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.89.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.88.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.87.1 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.87.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.86.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.85.1 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.85.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.84.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.83.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.82.1 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.82.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.81.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.80.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.79.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb
avm-tools-0.78.0 vendor/eac_git/lib/eac_git/local/dirty_files.rb