Class: E2B::Services::GitStatus
- Inherits:
-
Object
- Object
- E2B::Services::GitStatus
- Defined in:
- lib/e2b/services/git.rb
Overview
Represents the result of ‘git status`, including branch info and file statuses
Instance Attribute Summary collapse
-
#ahead ⇒ Integer
readonly
Number of commits ahead of upstream.
-
#behind ⇒ Integer
readonly
Number of commits behind upstream.
-
#current_branch ⇒ String?
readonly
Name of the current branch, or nil if detached.
-
#detached ⇒ Boolean
readonly
Whether HEAD is in detached state.
-
#file_status ⇒ Array<GitFileStatus>
readonly
List of file statuses.
-
#upstream ⇒ String?
readonly
Name of the upstream tracking branch.
Instance Method Summary collapse
-
#clean? ⇒ Boolean
Whether the working tree is clean (no changes at all).
-
#conflict_count ⇒ Integer
Number of conflicted files.
-
#has_changes? ⇒ Boolean
Whether the working tree has any changes.
-
#has_conflicts? ⇒ Boolean
Whether there are any merge conflicts.
-
#has_staged? ⇒ Boolean
Whether there are any staged changes.
-
#has_untracked? ⇒ Boolean
Whether there are any untracked files.
-
#initialize(current_branch: nil, upstream: nil, ahead: 0, behind: 0, detached: false, file_status: []) ⇒ GitStatus
constructor
A new instance of GitStatus.
-
#modified_count ⇒ Integer
Number of modified files (in the working tree).
-
#staged_count ⇒ Integer
Number of staged files.
-
#untracked_count ⇒ Integer
Number of untracked files.
Constructor Details
#initialize(current_branch: nil, upstream: nil, ahead: 0, behind: 0, detached: false, file_status: []) ⇒ GitStatus
Returns a new instance of GitStatus.
46 47 48 49 50 51 52 53 |
# File 'lib/e2b/services/git.rb', line 46 def initialize(current_branch: nil, upstream: nil, ahead: 0, behind: 0, detached: false, file_status: []) @current_branch = current_branch @upstream = upstream @ahead = ahead @behind = behind @detached = detached @file_status = file_status end |
Instance Attribute Details
#ahead ⇒ Integer (readonly)
Returns Number of commits ahead of upstream.
29 30 31 |
# File 'lib/e2b/services/git.rb', line 29 def ahead @ahead end |
#behind ⇒ Integer (readonly)
Returns Number of commits behind upstream.
32 33 34 |
# File 'lib/e2b/services/git.rb', line 32 def behind @behind end |
#current_branch ⇒ String? (readonly)
Returns Name of the current branch, or nil if detached.
23 24 25 |
# File 'lib/e2b/services/git.rb', line 23 def current_branch @current_branch end |
#detached ⇒ Boolean (readonly)
Returns Whether HEAD is in detached state.
35 36 37 |
# File 'lib/e2b/services/git.rb', line 35 def detached @detached end |
#file_status ⇒ Array<GitFileStatus> (readonly)
Returns List of file statuses.
38 39 40 |
# File 'lib/e2b/services/git.rb', line 38 def file_status @file_status end |
#upstream ⇒ String? (readonly)
Returns Name of the upstream tracking branch.
26 27 28 |
# File 'lib/e2b/services/git.rb', line 26 def upstream @upstream end |
Instance Method Details
#clean? ⇒ Boolean
Whether the working tree is clean (no changes at all)
58 59 60 |
# File 'lib/e2b/services/git.rb', line 58 def clean? file_status.empty? end |
#conflict_count ⇒ Integer
Number of conflicted files
107 108 109 |
# File 'lib/e2b/services/git.rb', line 107 def conflict_count file_status.count { |f| f.index_status == "u" || f.index_status == "U" } end |
#has_changes? ⇒ Boolean
Whether the working tree has any changes
65 66 67 |
# File 'lib/e2b/services/git.rb', line 65 def has_changes? !clean? end |
#has_conflicts? ⇒ Boolean
Whether there are any merge conflicts
86 87 88 |
# File 'lib/e2b/services/git.rb', line 86 def has_conflicts? file_status.any? { |f| f.index_status == "u" || f.index_status == "U" } end |
#has_staged? ⇒ Boolean
Whether there are any staged changes
72 73 74 |
# File 'lib/e2b/services/git.rb', line 72 def has_staged? file_status.any? { |f| f.index_status != "." && f.index_status != "?" } end |
#has_untracked? ⇒ Boolean
Whether there are any untracked files
79 80 81 |
# File 'lib/e2b/services/git.rb', line 79 def has_untracked? file_status.any? { |f| f.index_status == "?" } end |
#modified_count ⇒ Integer
Number of modified files (in the working tree)
114 115 116 |
# File 'lib/e2b/services/git.rb', line 114 def modified_count file_status.count { |f| f.work_tree_status == "M" } end |
#staged_count ⇒ Integer
Number of staged files
93 94 95 |
# File 'lib/e2b/services/git.rb', line 93 def staged_count file_status.count { |f| f.index_status != "." && f.index_status != "?" } end |
#untracked_count ⇒ Integer
Number of untracked files
100 101 102 |
# File 'lib/e2b/services/git.rb', line 100 def untracked_count file_status.count { |f| f.index_status == "?" } end |