#!/usr/bin/env ruby-2.1

# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.

refs = $stdin.read
key_id  = ENV['GL_ID']
protocol = ENV['GL_PROTOCOL']
repo_path = Dir.pwd

require_relative '../lib/gitlab_custom_hook'
require_relative '../lib/gitlab_access'

if GitlabAccess.new(repo_path, key_id, refs, protocol).exec &&
    GitlabCustomHook.new.pre_receive(refs, repo_path)
  exit 0
else
  # reset GL_ID env since we stop git push here
  ENV['GL_ID'] = nil
  
  exit 1
end
