1
嘿所以我用一個鉤子後像這樣:混帳REV-解析--short HEAD沒有得到最新的承諾
<?php
file_put_contents('deploy.log', serialize($_POST['payload']), FILE_APPEND);
$repo_dir = '/home/admin/web/website/repo-fullstack.git';
$web_root_dir = '/home/admin/web/website/public_html';
// Full path to git binary is required if git is not in your PHP user's path. Otherwise just use 'git'.
$git_bin_path = 'git';
$update = false;
// Parse data from Bitbucket hook payload
$payload = json_decode($_POST['payload']);
if (empty($payload->commits)){
// When merging and pushing to bitbucket, the commits array will be empty.
// In this case there is no way to know what branch was pushed to, so we will do an update.
$update = true;
} else {
foreach ($payload->commits as $commit) {
$branch = $commit->branch;
if ($branch === 'production' || isset($commit->branches) && in_array('production', $commit->branches)) {
$update = true;
break;
}
}
}
if ($update) {
// Do a git checkout to the web root
exec('cd ' . $repo_dir . ' && ' . $git_bin_path . ' fetch');
exec('cd ' . $repo_dir . ' && GIT_WORK_TREE=' . $web_root_dir . ' ' . $git_bin_path . ' checkout -f');
// Log the deployment
$commit_hash = shell_exec('cd ' . $repo_dir . ' && ' . $git_bin_path . ' rev-parse --short HEAD');
file_put_contents('deploy.log', date('m/d/Y h:i:s a') . " Deployed branch: " . $branch . " Commit: " . $commit_hash . "\n", FILE_APPEND);
}
?>
的問題是POST HOOK得到一個老犯,而且,不得到最新的提交。我注意到,即使是ROOT用戶。我運行命令git rev-parse --short HEAD它也得到了舊的提交。所以它肯定不是一個權限問題。
此命令不起作用的任何原因?我只是不明白爲什麼它會得到一箇舊的提交。
編輯:最奇怪的問題,如果所有,如果你想知道的是,它得到POST HOOK的正確描述。只是不正確的提交。跆拳道是這樣嗎?