Class: E2B::Services::GitStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/e2b/services/git.rb

Overview

Represents the result of ‘git status`, including branch info and file statuses

Examples:

status = sandbox.git.status("/home/user/repo")
puts status.current_branch
puts "Clean!" if status.clean?

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_branch: nil, upstream: nil, ahead: 0, behind: 0, detached: false, file_status: []) ⇒ GitStatus

Returns a new instance of GitStatus.

Parameters:

  • current_branch (String, nil) (defaults to: nil)

    Current branch name

  • upstream (String, nil) (defaults to: nil)

    Upstream tracking branch

  • ahead (Integer) (defaults to: 0)

    Commits ahead of upstream

  • behind (Integer) (defaults to: 0)

    Commits behind upstream

  • detached (Boolean) (defaults to: false)

    Whether HEAD is detached

  • file_status (Array<GitFileStatus>) (defaults to: [])

    File status entries



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

#aheadInteger (readonly)

Returns Number of commits ahead of upstream.

Returns:

  • (Integer)

    Number of commits ahead of upstream



29
30
31
# File 'lib/e2b/services/git.rb', line 29

def ahead
  @ahead
end

#behindInteger (readonly)

Returns Number of commits behind upstream.

Returns:

  • (Integer)

    Number of commits behind upstream



32
33
34
# File 'lib/e2b/services/git.rb', line 32

def behind
  @behind
end

#current_branchString? (readonly)

Returns Name of the current branch, or nil if detached.

Returns:

  • (String, nil)

    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

#detachedBoolean (readonly)

Returns Whether HEAD is in detached state.

Returns:

  • (Boolean)

    Whether HEAD is in detached state



35
36
37
# File 'lib/e2b/services/git.rb', line 35

def detached
  @detached
end

#file_statusArray<GitFileStatus> (readonly)

Returns List of file statuses.

Returns:



38
39
40
# File 'lib/e2b/services/git.rb', line 38

def file_status
  @file_status
end

#upstreamString? (readonly)

Returns Name of the upstream tracking branch.

Returns:

  • (String, nil)

    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)

Returns:

  • (Boolean)


58
59
60
# File 'lib/e2b/services/git.rb', line 58

def clean?
  file_status.empty?
end

#conflict_countInteger

Number of conflicted files

Returns:

  • (Integer)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


79
80
81
# File 'lib/e2b/services/git.rb', line 79

def has_untracked?
  file_status.any? { |f| f.index_status == "?" }
end

#modified_countInteger

Number of modified files (in the working tree)

Returns:

  • (Integer)


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_countInteger

Number of staged files

Returns:

  • (Integer)


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_countInteger

Number of untracked files

Returns:

  • (Integer)


100
101
102
# File 'lib/e2b/services/git.rb', line 100

def untracked_count
  file_status.count { |f| f.index_status == "?" }
end