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.



108
109
110
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 108

def initialize(commit)
  @commit = commit
end

Instance Attribute Details

#commitObject (readonly)

Returns the value of attribute commit.



106
107
108
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 106

def commit
  @commit
end

Instance Method Details

#authorObject



118
119
120
121
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 118

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

#authored_dateObject



123
124
125
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 123

def authored_date
  @commit.authored_date
end

#idObject Also known as: sha, to_s



112
113
114
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 112

def id
  @commit.id
end

#messageObject



127
128
129
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 127

def message
  @commit.message
end

#parentObject



135
136
137
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 135

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

#statsObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 139

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



158
159
160
161
162
163
164
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 158

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

#treeObject



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

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