Class: Git::Status::StatusFile

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

Overview

Represents a single file's status in the git repository. Each instance holds information about a file's state in the index and working tree.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, hash) ⇒ StatusFile

Initialize a new StatusFile with the given git object and data hash



258
259
260
261
262
263
264
265
266
267
268
# File 'lib/git/status.rb', line 258

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? (readonly)

The file mode recorded in the index



230
231
232
# File 'lib/git/status.rb', line 230

def mode_index
  @mode_index
end

#mode_repoString? (readonly)

The file mode recorded in HEAD



235
236
237
# File 'lib/git/status.rb', line 235

def mode_repo
  @mode_repo
end

#pathString (readonly)

The repository-relative file path



213
214
215
# File 'lib/git/status.rb', line 213

def path
  @path
end

#sha_indexString? (readonly)

The SHA of the index version of this file



240
241
242
# File 'lib/git/status.rb', line 240

def sha_index
  @sha_index
end

#sha_repoString? (readonly)

The SHA of the HEAD version of this file



245
246
247
# File 'lib/git/status.rb', line 245

def sha_repo
  @sha_repo
end

#stageString? (readonly)

The merge stage for this file



225
226
227
# File 'lib/git/status.rb', line 225

def stage
  @stage
end

#typeString? (readonly)

The change type for this file



219
220
221
# File 'lib/git/status.rb', line 219

def type
  @type
end

#untrackedBoolean? (readonly)

Whether this file is untracked



250
251
252
# File 'lib/git/status.rb', line 250

def untracked
  @untracked
end

Instance Method Details

#blob(type = :index) ⇒ Git::Object::Blob?

Return a blob object for the index or repo version of this file



278
279
280
281
# File 'lib/git/status.rb', line 278

def blob(type = :index)
  sha = type == :repo ? sha_repo : (sha_index || sha_repo)
  @base.object(sha) if sha
end