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.



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

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)


157
158
159
# File 'lib/git/status.rb', line 157

def mode_index
  @mode_index
end

#mode_repoString

The mode of the file in the repo

Examples:

100644

Returns:

  • (String)


164
165
166
# File 'lib/git/status.rb', line 164

def mode_repo
  @mode_repo
end

#pathString

The path of the file relative to the project root directory

Returns:

  • (String)


139
140
141
# File 'lib/git/status.rb', line 139

def path
  @path
end

#sha_indexString

The sha of the file in the index

Examples:

123456

Returns:

  • (String)


171
172
173
# File 'lib/git/status.rb', line 171

def sha_index
  @sha_index
end

#sha_repoString

The sha of the file in the repo

Examples:

123456

Returns:

  • (String)


177
178
179
# File 'lib/git/status.rb', line 177

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)


192
193
194
# File 'lib/git/status.rb', line 192

def stage
  @stage
end

#typeString

The type of change

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

Returns:

  • (String)


150
151
152
# File 'lib/git/status.rb', line 150

def type
  @type
end

#untrackedBoolean

Whether the file is untracked

Returns:

  • (Boolean)


182
183
184
# File 'lib/git/status.rb', line 182

def untracked
  @untracked
end

Instance Method Details

#blob(type = :index)



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

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