From d933f690d48fa880588cbe240f5279b308a9e877 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Sun, 29 May 2022 09:41:43 +0200 Subject: [PATCH] Split run into smaller methods --- lib/format_staged.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/format_staged.rb b/lib/format_staged.rb index 8aa2160..a98964b 100644 --- a/lib/format_staged.rb +++ b/lib/format_staged.rb @@ -23,19 +23,26 @@ class FormatStaged end def run - verbose_info "Finding repository root" + matching_files(repo_root).each do |file| + format_file(file) + end + end + + def repo_root + verbose_info 'Finding repository root' root = get_output('git', 'rev-parse', '--show-toplevel', lines: false).chomp verbose_info "Repo at #{root}" - verbose_info "Listing staged files" - files = get_output('git', 'diff-index', '--cached', '--diff-filter=AM', '--no-renames', 'HEAD') - .map { |line| Entry.new(line, root: root) } - .reject(&:symlink?) - .filter { |entry| entry.matches?(@patterns) } + root + end - files.each do |file| - format_file(file) - end + def matching_files(root) + verbose_info 'Listing staged files' + + get_output('git', 'diff-index', '--cached', '--diff-filter=AM', '--no-renames', 'HEAD') + .map { |line| Entry.new(line, root: root) } + .reject(&:symlink?) + .filter { |entry| entry.matches?(@patterns) } end def format_file(file)