From 7410e491a2d9fd80770cdba29e2f92e179f46c43 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Sat, 18 Oct 2014 22:14:35 +0200 Subject: [PATCH] Modify environment before calling Ruby --- .gitignore | 1 + CHANGELOG | 6 ++++++ VERSION | 2 +- hooks/post-receive | 21 ++++----------------- hooks/post-receive-main.rb | 18 ++++++++++++++++++ hooks/pre-receive | 21 ++++----------------- hooks/pre-receive-main.rb | 18 ++++++++++++++++++ hooks/update | 20 ++++---------------- hooks/update-main.rb | 17 +++++++++++++++++ 9 files changed, 73 insertions(+), 51 deletions(-) create mode 100644 hooks/post-receive-main.rb create mode 100755 hooks/pre-receive-main.rb create mode 100755 hooks/update-main.rb diff --git a/.gitignore b/.gitignore index 62e2cd13c6..d0a94478cc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ coverage/ .bundle tags .bundle/ +hooks/.env diff --git a/CHANGELOG b/CHANGELOG index 4748fc2712..61b8e7460f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +v2.5.0 + - Restore PATH before calling hooks v2 + +v2.4.0 + - Show error message when git access is rejected + v2.2.0 - Support for custom hooks (Drew Blessing and Jose Kahan) diff --git a/VERSION b/VERSION index 2bf1c1ccf3..437459cd94 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3.1 +2.5.0 diff --git a/hooks/post-receive b/hooks/post-receive index 301f639e99..77ff5bca99 100755 --- a/hooks/post-receive +++ b/hooks/post-receive @@ -1,18 +1,5 @@ -#!/usr/bin/env ruby +#!/usr/bin/env bash -# This file was placed here by GitLab. It makes sure that your pushed commits -# will be processed properly. - -refs = ARGF.read -key_id = ENV['GL_ID'] -repo_path = Dir.pwd - -require_relative '../lib/gitlab_custom_hook' -require_relative '../lib/gitlab_post_receive' - -if GitlabPostReceive.new(repo_path, key_id, refs).exec && - GitlabCustomHook.new.post_receive(refs, repo_path) - exit 0 -else - exit 1 -end +# Remove paths Git automatically prepends to PATH on hooks. +. "$GIT_DIR/hooks/.env" +ruby "$GIT_DIR/hooks/post-receive-main.rb" diff --git a/hooks/post-receive-main.rb b/hooks/post-receive-main.rb new file mode 100644 index 0000000000..301f639e99 --- /dev/null +++ b/hooks/post-receive-main.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +# This file was placed here by GitLab. It makes sure that your pushed commits +# will be processed properly. + +refs = ARGF.read +key_id = ENV['GL_ID'] +repo_path = Dir.pwd + +require_relative '../lib/gitlab_custom_hook' +require_relative '../lib/gitlab_post_receive' + +if GitlabPostReceive.new(repo_path, key_id, refs).exec && + GitlabCustomHook.new.post_receive(refs, repo_path) + exit 0 +else + exit 1 +end diff --git a/hooks/pre-receive b/hooks/pre-receive index 7f9c0c0a24..ec35b27669 100755 --- a/hooks/pre-receive +++ b/hooks/pre-receive @@ -1,18 +1,5 @@ -#!/usr/bin/env ruby +#!/usr/bin/env bash -# This file was placed here by GitLab. It makes sure that your pushed commits -# will be processed properly. - -refs = ARGF.read -key_id = ENV['GL_ID'] -repo_path = Dir.pwd - -require_relative '../lib/gitlab_custom_hook' -require_relative '../lib/gitlab_access' - -if GitlabAccess.new(repo_path, key_id, refs).exec && - GitlabCustomHook.new.pre_receive(refs, repo_path) - exit 0 -else - exit 1 -end +# Remove paths Git automatically prepends to PATH on hooks. +. "$GIT_DIR/hooks/.env" +ruby "$GIT_DIR/hooks/pre-receive-main.rb" diff --git a/hooks/pre-receive-main.rb b/hooks/pre-receive-main.rb new file mode 100755 index 0000000000..7f9c0c0a24 --- /dev/null +++ b/hooks/pre-receive-main.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +# This file was placed here by GitLab. It makes sure that your pushed commits +# will be processed properly. + +refs = ARGF.read +key_id = ENV['GL_ID'] +repo_path = Dir.pwd + +require_relative '../lib/gitlab_custom_hook' +require_relative '../lib/gitlab_access' + +if GitlabAccess.new(repo_path, key_id, refs).exec && + GitlabCustomHook.new.pre_receive(refs, repo_path) + exit 0 +else + exit 1 +end diff --git a/hooks/update b/hooks/update index f1ac8e71b3..d2867bb3bf 100755 --- a/hooks/update +++ b/hooks/update @@ -1,17 +1,5 @@ -#!/usr/bin/env ruby +#!/usr/bin/env bash -# This file was placed here by GitLab. It makes sure that your pushed commits -# will be processed properly. - -ref_name = ARGV[0] -old_value = ARGV[1] -new_value = ARGV[2] -repo_path = Dir.pwd - -require_relative '../lib/gitlab_custom_hook' - -if GitlabCustomHook.new.update(ref_name, old_value, new_value, repo_path) - exit 0 -else - exit 1 -end +# Remove paths Git automatically prepends to PATH on hooks. +. "$GIT_DIR/hooks/.env" +ruby "$GIT_DIR/hooks/update-main.rb" diff --git a/hooks/update-main.rb b/hooks/update-main.rb new file mode 100755 index 0000000000..f1ac8e71b3 --- /dev/null +++ b/hooks/update-main.rb @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# This file was placed here by GitLab. It makes sure that your pushed commits +# will be processed properly. + +ref_name = ARGV[0] +old_value = ARGV[1] +new_value = ARGV[2] +repo_path = Dir.pwd + +require_relative '../lib/gitlab_custom_hook' + +if GitlabCustomHook.new.update(ref_name, old_value, new_value, repo_path) + exit 0 +else + exit 1 +end