Module: Yatte::Git
- Defined in:
- lib/yatte/git.rb
Constant Summary collapse
- ADDED =
:added- MODIFIED =
:modified- DELETED =
:deleted- GUTTER =
{ added: "\x1b[32m+\x1b[0m", modified: "\x1b[33m~\x1b[0m", deleted: "\x1b[31m-\x1b[0m" }.freeze
Class Method Summary collapse
- .ignored?(filepath) ⇒ Boolean
- .line_status(filepath) ⇒ Object
- .repo?(filepath) ⇒ Boolean
- .tracked?(filepath) ⇒ Boolean
Class Method Details
.ignored?(filepath) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/yatte/git.rb', line 43 def self.ignored?(filepath) return false unless filepath dir = File.dirname(File.(filepath)) _, _, status = Open3.capture3( "git", "check-ignore", "-q", File.basename(filepath), chdir: dir ) status.success? rescue Errno::ENOENT false end |
.line_status(filepath) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/yatte/git.rb', line 56 def self.line_status(filepath) return nil unless filepath && repo?(filepath) return nil if ignored?(filepath) return all_added(filepath) unless tracked?(filepath) dir = File.dirname(File.(filepath)) output, _, status = Open3.capture3( "git", "diff", "--no-color", "-U0", "HEAD", "--", File.basename(filepath), chdir: dir ) return {} unless status.success? parse_diff(output) rescue Errno::ENOENT nil end |
.repo?(filepath) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/yatte/git.rb', line 17 def self.repo?(filepath) return false unless filepath dir = File.dirname(File.(filepath)) output, _, status = Open3.capture3( "git", "rev-parse", "--is-inside-work-tree", chdir: dir ) status.success? && output.strip == "true" rescue Errno::ENOENT false end |
.tracked?(filepath) ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yatte/git.rb', line 30 def self.tracked?(filepath) return false unless filepath dir = File.dirname(File.(filepath)) _, _, status = Open3.capture3( "git", "ls-files", "--error-unmatch", File.basename(filepath), chdir: dir ) status.success? rescue Errno::ENOENT false end |