Class: Gollum::Git::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/rjgit_adapter/git_layer_rjgit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commit) ⇒ Commit

Returns a new instance of Commit.



133
134
135
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 133

def initialize(commit)
  @commit = commit
end

Instance Attribute Details

#commitObject (readonly)

Returns the value of attribute commit.



131
132
133
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 131

def commit
  @commit
end

Instance Method Details

#authorObject



143
144
145
146
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 143

def author
  author = @commit.actor
  Gollum::Git::Actor.new(author.name, author.email)
end

#authored_dateObject



148
149
150
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 148

def authored_date
  @commit.authored_date
end

#idObject Also known as: sha, to_s



137
138
139
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 137

def id
  @commit.id
end

#messageObject



152
153
154
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 152

def message
  @commit.message
end

#note(ref = 'refs/notes/commits') ⇒ Object



191
192
193
194
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 191

def note(ref='refs/notes/commits')
  result = @commit.note(ref)
  result ? result.to_s : nil
end

#note=(msg, ref = 'refs/notes/commits') ⇒ Object



196
197
198
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 196

def note=(msg, ref='refs/notes/commits')
  @commit.send(:note=,msg,ref)
end

#parentObject



160
161
162
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 160

def parent
  @commit.parents.empty? ? nil : Gollum::Git::Commit.new(@commit.parents.first)
end

#statsObject



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 164

def stats
  return @stats unless @stats.nil?
  rjgit_stats = @commit.stats

  files = rjgit_stats[:files].map do |file|
    file[:new_file] == file[:old_file] if file[:new_file] == '/dev/null' # File is deleted, display only the original, deleted path.
    file.delete(:old_file) if (file[:old_file] == '/dev/null') || (file[:old_file] == file[:new_file]) # Don't include an old path when the file is new, or it's a regular update
    file
  end
  
  @stats = OpenStruct.new(
    :additions => rjgit_stats[:total_additions],
    :deletions => rjgit_stats[:total_deletions],
    :total => rjgit_stats[:total_additions] + rjgit_stats[:total_deletions],
    :files => files,
    :id => id
  )
end

#tracked_pathnameObject



183
184
185
186
187
188
189
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 183

def tracked_pathname
  begin
    @commit.tracked_pathname
  rescue NoMethodError
    nil
  end
end

#treeObject



156
157
158
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 156

def tree
  Gollum::Git::Tree.new(@commit.tree)
end