Commit c8a7e4c6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fewer-constants-more-helpres' into 'master'

Fewer Git constants, more Git helpers.

See merge request !1727
parents c71fa132 a5a5ec97
...@@ -109,7 +109,7 @@ class GitPushService ...@@ -109,7 +109,7 @@ class GitPushService
def push_to_existing_branch?(ref, oldrev) def push_to_existing_branch?(ref, oldrev)
# Return if this is not a push to a branch (e.g. new commits) # Return if this is not a push to a branch (e.g. new commits)
Gitlab::Git.branch_ref?(ref) && oldrev != Gitlab::Git::BLANK_SHA Gitlab::Git.branch_ref?(ref) && !Gitlab::Git.blank_ref?(oldrev)
end end
def push_to_new_branch?(ref, oldrev) def push_to_new_branch?(ref, oldrev)
......
...@@ -57,9 +57,9 @@ class IrkerWorker ...@@ -57,9 +57,9 @@ class IrkerWorker
end end
def send_branch_updates(push_data, project, repo_name, committer, branch) def send_branch_updates(push_data, project, repo_name, committer, branch)
if push_data['before'] == Gitlab::Git::BLANK_SHA if Gitlab::Git.blank_ref?(push_data['before'])
send_new_branch project, repo_name, committer, branch send_new_branch project, repo_name, committer, branch
elsif push_data['after'] == Gitlab::Git::BLANK_SHA elsif Gitlab::Git.blank_ref?(push_data['after'])
send_del_branch repo_name, committer, branch send_del_branch repo_name, committer, branch
end end
end end
...@@ -83,7 +83,7 @@ class IrkerWorker ...@@ -83,7 +83,7 @@ class IrkerWorker
return if push_data['total_commits_count'] == 0 return if push_data['total_commits_count'] == 0
# Next message is for number of commit pushed, if any # Next message is for number of commit pushed, if any
if push_data['before'] == Gitlab::Git::BLANK_SHA if Gitlab::Git.blank_ref?(push_data['before'])
# Tweak on push_data["before"] in order to have a nice compare URL # Tweak on push_data["before"] in order to have a nice compare URL
push_data['before'] = before_on_new_branch push_data, project push_data['before'] = before_on_new_branch push_data, project
end end
......
...@@ -3,11 +3,12 @@ module Gitlab ...@@ -3,11 +3,12 @@ module Gitlab
def self.force_push?(project, oldrev, newrev) def self.force_push?(project, oldrev, newrev)
return false if project.empty_repo? return false if project.empty_repo?
if oldrev != Gitlab::Git::BLANK_SHA && newrev != Gitlab::Git::BLANK_SHA # Created or deleted branch
if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev)
false
else
missed_refs, _ = Gitlab::Popen.popen(%W(git --git-dir=#{project.repository.path_to_repo} rev-list #{oldrev} ^#{newrev})) missed_refs, _ = Gitlab::Popen.popen(%W(git --git-dir=#{project.repository.path_to_repo} rev-list #{oldrev} ^#{newrev}))
missed_refs.split("\n").size > 0 missed_refs.split("\n").size > 0
else
false
end end
end end
end end
......
...@@ -71,7 +71,8 @@ module Gitlab ...@@ -71,7 +71,8 @@ module Gitlab
end end
def checkout_sha(repository, newrev, ref) def checkout_sha(repository, newrev, ref)
if newrev != Gitlab::Git::BLANK_SHA && Gitlab::Git.tag_ref?(ref) # Find sha for tag, except when it was deleted.
if Gitlab::Git.tag_ref?(ref) && !Gitlab::Git.blank_ref?(newrev)
tag_name = Gitlab::Git.ref_name(ref) tag_name = Gitlab::Git.ref_name(ref)
tag = repository.find_tag(tag_name) tag = repository.find_tag(tag_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment