summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-11-06 13:32:40 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-11-06 13:32:40 +0200
commitbd144a604f3c72552cd112fdffc3a402e69b628c (patch)
tree406390779e73fd20ef886915d6a43030cb906d3f /app/models/commit.rb
parent1cc5704a00784f71ec2f4392160479fb3044f4d2 (diff)
downloadgitlab-ci-bd144a604f3c72552cd112fdffc3a402e69b628c.tar.gz
Refactor commit sha
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 33087b3..3532035 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -22,6 +22,10 @@ class Commit < ActiveRecord::Base
validates_presence_of :ref, :sha, :before_sha, :push_data
validate :valid_commit_sha
+ def self.truncate_sha(sha)
+ sha[0...8]
+ end
+
def to_param
sha
end
@@ -31,13 +35,17 @@ class Commit < ActiveRecord::Base
end
def valid_commit_sha
- if self.sha =~ /\A00000000/
+ if self.sha == Git::BLANK_SHA
self.errors.add(:sha, " cant be 00000000 (branch removal)")
end
end
+ def new_branch?
+ before_sha == Git::BLANK_SHA
+ end
+
def compare?
- gitlab? && before_sha
+ gitlab? && !new_branch?
end
def gitlab?
@@ -61,11 +69,11 @@ class Commit < ActiveRecord::Base
end
def short_before_sha
- before_sha[0..8]
+ Commit.truncate_sha(before_sha)
end
def short_sha
- sha[0..8]
+ Commit.truncate_sha(sha)
end
def commit_data