Class: GitHooks::Hook::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/githooks/hook.rb

Instance Method Summary collapse

Constructor Details

#initialize(hook) ⇒ Manifest

Returns a new instance of Manifest.



168
169
170
# File 'lib/githooks/hook.rb', line 168

def initialize(hook)
  @hook = hook
end

Instance Method Details

#filesObject

rubocop:disable Metrics/AbcSize



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/githooks/hook.rb', line 176

def files # rubocop:disable Metrics/AbcSize
  @files ||= begin
    options = {
      staged:    hook.staged,
      tracked:   hook.tracked,
      untracked: hook.untracked
    }

    if %w[ commit-msg pre-push ].include? hook.phase
      begin
        if (parent_sha = repository.last_unpushed_commit_parent)
          options.merge!(ref: parent_sha)
        end
      rescue Error::RemoteNotSet
        # remote not set yet, so let's only focus on what's tracked for now
        options[:tracked]   = true
        options[:untracked] = false
        options[:staged]    = false
      end
    end

    repository.manifest(options)
  end
end

#filter(limiters) ⇒ Object



201
202
203
204
205
206
207
208
# File 'lib/githooks/hook.rb', line 201

def filter(limiters)
  files.dup.tap do |files|
    limiters.each do |type, limiter|
      STDERR.puts "Limiter [#{type}] -> (#{limiter.only.inspect}) match against: " if GitHooks.debug?
      limiter.limit(files)
    end
  end
end

#repositoryObject



172
173
174
# File 'lib/githooks/hook.rb', line 172

def repository
  @hook.repository
end