Get commits between two refs
Ex.
Commit.between('29eda46b', 'master')
# File lib/gitlab_git/commit.rb, line 77 def between(repo, base, head) repo.commits_between(base, head).map do |commit| decorate(commit) end end
# File lib/gitlab_git/commit.rb, line 88 def decorate(commit, ref = nil) Gitlab::Git::Commit.new(commit, ref) end
Get single commit
Ex.
Commit.find(repo, '29eda46b') Commit.find(repo, 'master')
# File lib/gitlab_git/commit.rb, line 42 def find(repo, commit_id = nil) commit = repo.log(ref: commit_id, limit: 1).first decorate(commit) if commit end
Delegate Repository#find_commits
# File lib/gitlab_git/commit.rb, line 84 def find_all(repo, options = {}) repo.find_commits(options) end
Get last commit for HEAD
Ex.
Commit.last(repo)
# File lib/gitlab_git/commit.rb, line 52 def last(repo) find(repo, nil) end
Get last commit for specified path and ref
Ex.
Commit.last_for_path(repo, '29eda46b', 'app/models') Commit.last_for_path(repo, 'master', 'Gemfile')
# File lib/gitlab_git/commit.rb, line 63 def last_for_path(repo, ref, path = nil) where( repo: repo, ref: ref, path: path, limit: 1 ).first end
# File lib/gitlab_git/commit.rb, line 93 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
Get commits collection
Ex.
Commit.where( repo: repo, ref: 'master', path: 'app/models', limit: 10, offset: 5, )
# File lib/gitlab_git/commit.rb, line 28 def where(options) repo = options.delete(:repo) raise 'Gitlab::Git::Repository is required' unless repo.respond_to?(:log) repo.log(options).map { |c| decorate(c) } end
# File lib/gitlab_git/commit.rb, line 117 def created_at committed_date end
Was this commit committed by a different person than the original author?
# File lib/gitlab_git/commit.rb, line 122 def different_committer? author_name != committer_name || author_email != committer_email end
# File lib/gitlab_git/commit.rb, line 167 def diffs raw_commit.diffs.map { |diff| Gitlab::Git::Diff.new(diff) } end
# File lib/gitlab_git/commit.rb, line 147 def has_zero_stats? stats.total.zero? rescue true end
# File lib/gitlab_git/commit.rb, line 153 def no_commit_message "--no commit message" end
# File lib/gitlab_git/commit.rb, line 126 def parent_id parent_ids.first end
# File lib/gitlab_git/commit.rb, line 171 def parents raw_commit.parents end
Get ref names collection
Ex.
commit.ref_names(repo)
# File lib/gitlab_git/commit.rb, line 201 def ref_names(repo) refs(repo).map(&:name) end
# File lib/gitlab_git/commit.rb, line 113 def safe_message @safe_message ||= message end
# File lib/gitlab_git/commit.rb, line 109 def short_id(length = 10) id.to_s[0..length] end
# File lib/gitlab_git/commit.rb, line 179 def stats raw_commit.stats end
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.
# File lib/gitlab_git/commit.rb, line 133 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
# File lib/gitlab_git/commit.rb, line 157 def to_hash serialize_keys.map.with_object({}) do |key, hash| hash[key] = send(key) end end
Generated with the Darkfish Rdoc Generator 2.