Class: Henitai::GitDiffAnalyzer
- Inherits:
-
Object
- Object
- Henitai::GitDiffAnalyzer
- Defined in:
- lib/henitai/git_diff_analyzer.rb
Overview
Shells out to git to discover changed files between two refs.
By default the analyzer runs in the current working directory. Callers can pass dir: to point it at another repository root without changing cwd.
Instance Method Summary collapse
- #changed_files(from:, to:, dir: Dir.pwd) ⇒ Object
- #changed_methods(from:, to:, dir: Dir.pwd) ⇒ Object
- #head_sha(dir: Dir.pwd) ⇒ Object
- #working_tree_changed_files(dir: Dir.pwd) ⇒ Object
Instance Method Details
#changed_files(from:, to:, dir: Dir.pwd) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/henitai/git_diff_analyzer.rb', line 14 def changed_files(from:, to:, dir: Dir.pwd) stdout, stderr, status = git_diff(dir, "--name-only", from, to) raise GitDiffError, stderr.strip unless status.success? stdout.split("\n").reject(&:empty?) end |
#changed_methods(from:, to:, dir: Dir.pwd) ⇒ Object
37 38 39 40 41 |
# File 'lib/henitai/git_diff_analyzer.rb', line 37 def changed_methods(from:, to:, dir: Dir.pwd) changed_files(from:, to:, dir:).flat_map do |path| changed_methods_in_file(path, from:, to:, dir:) end end |
#head_sha(dir: Dir.pwd) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/henitai/git_diff_analyzer.rb', line 29 def head_sha(dir: Dir.pwd) command = ["git", "-C", dir, "rev-parse", "HEAD"] stdout, _, status = Open3.capture3(*command) stdout.strip if status.success? && !stdout.strip.empty? rescue Errno::ENOENT nil end |
#working_tree_changed_files(dir: Dir.pwd) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/henitai/git_diff_analyzer.rb', line 22 def working_tree_changed_files(dir: Dir.pwd) tracked = working_tree_tracked_files(dir) untracked = untracked_files(dir) (tracked + untracked).uniq end |