summaryrefslogtreecommitdiff
path: root/lib/gitlab/force_push_check.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/force_push_check.rb')
-rw-r--r--lib/gitlab/force_push_check.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/gitlab/force_push_check.rb b/lib/gitlab/force_push_check.rb
new file mode 100644
index 00000000000..eae9773a067
--- /dev/null
+++ b/lib/gitlab/force_push_check.rb
@@ -0,0 +1,14 @@
+module Gitlab
+ class ForcePushCheck
+ def self.force_push?(project, oldrev, newrev)
+ return false if project.empty_repo?
+
+ if oldrev != Gitlab::Git::BLANK_SHA && newrev != Gitlab::Git::BLANK_SHA
+ missed_refs, _ = Gitlab::Popen.popen(%W(git --git-dir=#{project.repository.path_to_repo} rev-list #{oldrev} ^#{newrev}))
+ missed_refs.split("\n").size > 0
+ else
+ false
+ end
+ end
+ end
+end