Sha256: 428d6018164670399940d84ed70d46d46057af91e914628c5da26e33f1ec60a1

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

module GitCompound
  module Worker
    # Worker that defends local changes in
    # component repositories
    #
    class LocalChangesGuard < Worker
      def initialize(lock)
        @lock = lock
      end

      def visit_component(component)
        return unless component.exists?

        @component  = component
        @repository = component.repository

        check_uncommited_changes!
        check_untracked_files!
      end

      private

      def check_uncommited_changes!
        return unless @repository.uncommited_changes?

        raise LocalChangesError,
              "Component `#{@component.name}` contains uncommited changes !"
      end

      def check_untracked_files!
        return unless @repository.untracked_files?(subcomponents_dirs)

        raise LocalChangesError,
              "Component `#{@component.name}` contains untracked files !"
      end

      def subcomponents_dirs
        locked_dirs = @lock.components.map { |locked| "#{locked.path}".chop }
        component_subdirs = locked_dirs.select do |locked_dir|
          locked_dir.start_with?(@component.path)
        end

        component_subdirs.collect do |subdir|
          subdir.sub(/^#{@component.path}/, '').split(File::SEPARATOR).first
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
git_compound-0.2.2 lib/git_compound/worker/local_changes_guard.rb
git_compound-0.2.1 lib/git_compound/worker/local_changes_guard.rb
git_compound-0.2.0 lib/git_compound/worker/local_changes_guard.rb
git_compound-0.1.2 lib/git_compound/worker/local_changes_guard.rb
git_compound-0.1.1 lib/git_compound/worker/local_changes_guard.rb