Module: Yard::Lint::Git
- Defined in:
- lib/yard/lint/git.rb
Overview
Git integration for diff mode functionality
Defined Under Namespace
Classes: Error
Class Method Summary collapse
-
.branch_exists?(ref) ⇒ Boolean
Check if a git ref exists.
-
.changed_files(base_ref, path) ⇒ Array<String>
Get files changed since a base ref.
-
.default_branch ⇒ String
Detect the default branch (main or master).
-
.staged_files(path) ⇒ Array<String>
Get staged files (files in git index).
-
.uncommitted_files(path) ⇒ Array<String>
Get uncommitted files (all changes in working directory).
Class Method Details
.branch_exists?(ref) ⇒ Boolean
Check if a git ref exists
25 26 27 28 |
# File 'lib/yard/lint/git.rb', line 25 def branch_exists?(ref) _stdout, _stderr, status = Open3.capture3('git', 'rev-parse', '--verify', '--quiet', ref) status.success? end |
.changed_files(base_ref, path) ⇒ Array<String>
Get files changed since a base ref
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/yard/lint/git.rb', line 34 def changed_files(base_ref, path) base_ref ||= default_branch raise Error, 'Could not detect default branch (main/master)' unless base_ref ensure_git_repository! # Use three-dot diff to compare against merge base stdout, stderr, status = Open3.capture3('git', 'diff', '--name-only', "#{base_ref}...HEAD") unless status.success? raise Error, "Git diff failed: #{stderr.strip}" end filter_ruby_files(stdout.split("\n"), path) end |
.default_branch ⇒ String
Detect the default branch (main or master)
13 14 15 16 17 18 19 20 |
# File 'lib/yard/lint/git.rb', line 13 def default_branch # Try main first (modern default) return 'main' if branch_exists?('main') # Fall back to master (legacy default) return 'master' if branch_exists?('master') nil end |
.staged_files(path) ⇒ Array<String>
Get staged files (files in git index)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/yard/lint/git.rb', line 53 def staged_files(path) ensure_git_repository! # ACM filter: Added, Copied, Modified (exclude Deleted) stdout, stderr, status = Open3.capture3( 'git', 'diff', '--cached', '--name-only', '--diff-filter=ACM' ) unless status.success? raise Error, "Git diff failed: #{stderr.strip}" end filter_ruby_files(stdout.split("\n"), path) end |
.uncommitted_files(path) ⇒ Array<String>
Get uncommitted files (all changes in working directory)
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/yard/lint/git.rb', line 71 def uncommitted_files(path) ensure_git_repository! # Get both staged and unstaged changes stdout, stderr, status = Open3.capture3('git', 'diff', '--name-only', 'HEAD') unless status.success? raise Error, "Git diff failed: #{stderr.strip}" end filter_ruby_files(stdout.split("\n"), path) end |