-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhook-lib.php
64 lines (50 loc) · 1.52 KB
/
hook-lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
define('SUCCESS', 0);
define('FAILURE', 1);
// Load and check the configuration
if (!file_exists('.git/hooks/hook-config.php')){
echo "/!\\ Could not load the hooks configuration at " . getcwd() . ".git/hooks/hook-config.php.";
echo PHP_EOL;
exit(1);
}
require('hook-config.php');
if (!defined('CONFIG_VERSION') || CONFIG_VERSION != '0.2.0') {
echo "/!\\ The configuration doesn't match the hooks requirement. Please check .git/hooks/hook-config.php.template to update your configuration file.";
echo PHP_EOL;
exit(1);
}
/**
* Find the current branch name from witch the commit is beeing done.
*
* @return string|false Branch name.
*/
function getCurrentBranchName(){
$output = array();
$rc = 0;
exec('git branch --no-color 2> /dev/null', $output, $rc);
if ($rc != 0){
return false;
}
$needle = '/^\* (.+)/';
foreach ($output as $branch) {
if (preg_match($needle, $branch, $matches)) {
return $matches[1];
}
}
return false;
}
/**
* Extract the list of the files in the commit.
* This list include without distinction edited/modified and deleted files.
*
* @return array File list.
*/
function getCommitFileList(){
$output = array();
$rc = 0;
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $rc);
if ($rc == 0) $against = 'HEAD';
else $against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
exec('git diff-index --cached --name-only '. $against, $output);
return $output;
}