Class: Git::Status::StatusFile

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

Overview

subclass that does heavy lifting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, hash) ⇒ StatusFile

Returns a new instance of StatusFile.



192
193
194
195
196
197
198
199
200
201
202
# File 'lib/git/status.rb', line 192

def initialize(base, hash)
  @base = base
  @path = hash[:path]
  @type = hash[:type]
  @stage = hash[:stage]
  @mode_index = hash[:mode_index]
  @mode_repo = hash[:mode_repo]
  @sha_index = hash[:sha_index]
  @sha_repo = hash[:sha_repo]
  @untracked = hash[:untracked]
end

Instance Attribute Details

#mode_indexString

The mode of the file in the index

Examples:

100644

Returns:

  • (String)


155
156
157
# File 'lib/git/status.rb', line 155

def mode_index
  @mode_index
end

#mode_repoString

The mode of the file in the repo

Examples:

100644

Returns:

  • (String)


162
163
164
# File 'lib/git/status.rb', line 162

def mode_repo
  @mode_repo
end

#pathString

The path of the file relative to the project root directory

Returns:

  • (String)


137
138
139
# File 'lib/git/status.rb', line 137

def path
  @path
end

#sha_indexString

The sha of the file in the index

Examples:

123456

Returns:

  • (String)


169
170
171
# File 'lib/git/status.rb', line 169

def sha_index
  @sha_index
end

#sha_repoString

The sha of the file in the repo

Examples:

123456

Returns:

  • (String)


175
176
177
# File 'lib/git/status.rb', line 175

def sha_repo
  @sha_repo
end

#stageString

The stage of the file

  • '0': the unmerged state
  • '1': the common ancestor (or original) version
  • '2': "our version" from the current branch head
  • '3': "their version" from the other branch head

Returns:

  • (String)


190
191
192
# File 'lib/git/status.rb', line 190

def stage
  @stage
end

#typeString

The type of change

  • 'M': modified
  • 'A': added
  • 'D': deleted
  • nil: ???

Returns:

  • (String)


148
149
150
# File 'lib/git/status.rb', line 148

def type
  @type
end

#untrackedBoolean

Whether the file is untracked

Returns:

  • (Boolean)


180
181
182
# File 'lib/git/status.rb', line 180

def untracked
  @untracked
end

Instance Method Details

#blob(type = :index)



204
205
206
207
208
209
210
211
212
213
214
# File 'lib/git/status.rb', line 204

def blob(type = :index)
  if type == :repo
    @base.object(@sha_repo)
  else
    begin
      @base.object(@sha_index)
    rescue
      @base.object(@sha_repo)
    end
  end
end