Class: Gitlab::Git::Commit
- Inherits:
-
Object
- Object
- Gitlab::Git::Commit
- Defined in:
- lib/gitlab_git/commit.rb
Instance Attribute Summary collapse
-
#author_email ⇒ Object
Returns the value of attribute author_email.
-
#author_name ⇒ Object
Returns the value of attribute author_name.
-
#authored_date ⇒ Object
Returns the value of attribute authored_date.
-
#committed_date ⇒ Object
Returns the value of attribute committed_date.
-
#committer_email ⇒ Object
Returns the value of attribute committer_email.
-
#committer_name ⇒ Object
Returns the value of attribute committer_name.
-
#head ⇒ Object
Returns the value of attribute head.
-
#id ⇒ Object
Returns the value of attribute id.
-
#message ⇒ Object
Returns the value of attribute message.
-
#parent_ids ⇒ Object
Returns the value of attribute parent_ids.
-
#raw_commit ⇒ Object
Returns the value of attribute raw_commit.
-
#refs ⇒ Object
Returns the value of attribute refs.
Instance Method Summary collapse
- #created_at ⇒ Object
- #date ⇒ Object
-
#different_committer? ⇒ Boolean
Was this commit committed by a different person than the original author?.
- #diffs ⇒ Object
- #has_zero_stats? ⇒ Boolean
-
#initialize(raw_commit, head = nil) ⇒ Commit
constructor
A new instance of Commit.
- #no_commit_message ⇒ Object
- #parent_id ⇒ Object
- #parents ⇒ Object
- #safe_message ⇒ Object
- #serialize_keys ⇒ Object
- #sha ⇒ Object
- #short_id(length = 10) ⇒ Object
- #stats ⇒ Object
-
#to_diff ⇒ Object
Shows the diff between the commit’s parent and the commit.
- #to_hash ⇒ Object
- #to_patch ⇒ Object
- #tree ⇒ Object
Constructor Details
#initialize(raw_commit, head = nil) ⇒ Commit
Returns a new instance of Commit.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gitlab_git/commit.rb', line 12 def initialize(raw_commit, head = nil) raise "Nil as raw commit passed" unless raw_commit if raw_commit.is_a?(Hash) init_from_hash(raw_commit) else init_from_grit(raw_commit) end @head = head end |
Instance Attribute Details
#author_email ⇒ Object
Returns the value of attribute author_email.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def @author_email end |
#author_name ⇒ Object
Returns the value of attribute author_name.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def @author_name end |
#authored_date ⇒ Object
Returns the value of attribute authored_date.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def @authored_date end |
#committed_date ⇒ Object
Returns the value of attribute committed_date.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def committed_date @committed_date end |
#committer_email ⇒ Object
Returns the value of attribute committer_email.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def committer_email @committer_email end |
#committer_name ⇒ Object
Returns the value of attribute committer_name.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def committer_name @committer_name end |
#head ⇒ Object
Returns the value of attribute head.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def head @head end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def id @id end |
#message ⇒ Object
Returns the value of attribute message.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def @message end |
#parent_ids ⇒ Object
Returns the value of attribute parent_ids.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def parent_ids @parent_ids end |
#raw_commit ⇒ Object
Returns the value of attribute raw_commit.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def raw_commit @raw_commit end |
#refs ⇒ Object
Returns the value of attribute refs.
7 8 9 |
# File 'lib/gitlab_git/commit.rb', line 7 def refs @refs end |
Instance Method Details
#created_at ⇒ Object
40 41 42 |
# File 'lib/gitlab_git/commit.rb', line 40 def created_at committed_date end |
#date ⇒ Object
92 93 94 |
# File 'lib/gitlab_git/commit.rb', line 92 def date committed_date end |
#different_committer? ⇒ Boolean
Was this commit committed by a different person than the original author?
45 46 47 |
# File 'lib/gitlab_git/commit.rb', line 45 def different_committer? != committer_name || != committer_email end |
#diffs ⇒ Object
96 97 98 |
# File 'lib/gitlab_git/commit.rb', line 96 def diffs raw_commit.diffs.map { |diff| Gitlab::Git::Diff.new(diff) } end |
#has_zero_stats? ⇒ Boolean
70 71 72 73 74 |
# File 'lib/gitlab_git/commit.rb', line 70 def has_zero_stats? stats.total.zero? rescue true end |
#no_commit_message ⇒ Object
76 77 78 |
# File 'lib/gitlab_git/commit.rb', line 76 def "--no commit message" end |
#parent_id ⇒ Object
49 50 51 |
# File 'lib/gitlab_git/commit.rb', line 49 def parent_id parent_ids.first end |
#parents ⇒ Object
100 101 102 |
# File 'lib/gitlab_git/commit.rb', line 100 def parents raw_commit.parents end |
#safe_message ⇒ Object
36 37 38 |
# File 'lib/gitlab_git/commit.rb', line 36 def @safe_message ||= end |
#serialize_keys ⇒ Object
24 25 26 |
# File 'lib/gitlab_git/commit.rb', line 24 def serialize_keys @serialize_keys ||= %w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids).map(&:to_sym) end |
#sha ⇒ Object
28 29 30 |
# File 'lib/gitlab_git/commit.rb', line 28 def sha id end |
#short_id(length = 10) ⇒ Object
32 33 34 |
# File 'lib/gitlab_git/commit.rb', line 32 def short_id(length = 10) id.to_s[0..length] end |
#stats ⇒ Object
108 109 110 |
# File 'lib/gitlab_git/commit.rb', line 108 def stats raw_commit.tree end |
#to_diff ⇒ Object
Shows the diff between the commit’s parent and the commit.
Cuts out the header and stats from #to_patch and returns only the diff.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/gitlab_git/commit.rb', line 56 def to_diff # see Grit::Commit#show patch = to_patch # discard lines before the diff lines = patch.split("\n") while !lines.first.start_with?("diff --git") do lines.shift end lines.pop if lines.last =~ /^[\d.]+$/ # Git version lines.pop if lines.last == "-- " # end of diff lines.join("\n") end |
#to_hash ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/gitlab_git/commit.rb', line 80 def to_hash hash = {} keys = serialize_keys keys.each do |key| hash[key] = send(key) end hash end |
#to_patch ⇒ Object
112 113 114 |
# File 'lib/gitlab_git/commit.rb', line 112 def to_patch raw_commit.to_patch end |
#tree ⇒ Object
104 105 106 |
# File 'lib/gitlab_git/commit.rb', line 104 def tree raw_commit.tree end |