private static function installGitConfig($rootDir, $pluginDir, $driver)
{
$gitconfigPath = $rootDir . '/.git/config';
if (strpos(file_get_contents($gitconfigPath), '[merge "vp-ini"]') !== false) {
return;
}
$gitconfigContents = file_get_contents($pluginDir . '/src/Initialization/gitconfig.tpl');
$mergeDriverScript = '';
if ($driver == MergeDriverInstaller::DRIVER_BASH || $driver == MergeDriverInstaller::DRIVER_AUTO && DIRECTORY_SEPARATOR == '/') {
$mergeDriverScript = $pluginDir . '/src/Git/merge-drivers/ini-merge.sh';
chmod($mergeDriverScript, 0750);
}
if ($driver == MergeDriverInstaller::DRIVER_PHP || $driver == MergeDriverInstaller::DRIVER_AUTO && DIRECTORY_SEPARATOR == '\\') {
// Finding the PHP binary is a bit tricky because web server requests don't use the main PHP binary at all
// (they either use `mod_php` or call `php-cgi`). PHP_BINARY is only correct when the process
// is initiated from the command line, e.g., via WP-CLI when cloning.
//
// We'll only fix the path for Windows because on Linux and Mac OS, Bash driver is used most of time
// and the tests are started from command line so PHP_BINARY is fine there too.
$phpBinary = PHP_BINARY;
if (DIRECTORY_SEPARATOR == '\\' && !Strings::endsWith($phpBinary, 'php.exe')) {
$phpBinary = realpath(ini_get('extension_dir') . '/..') . '/php.exe';
}
$mergeDriverScript = '"' . $phpBinary . '" "' . $pluginDir . '/src/Git/merge-drivers/ini-merge.php' . '"';
}
$gitconfigVariables = ['merge-driver-script' => str_replace('\\', '/', $mergeDriverScript)];
$gitconfigContents = StringUtils::fillTemplateString($gitconfigVariables, $gitconfigContents);
file_put_contents($gitconfigPath, $gitconfigContents, FILE_APPEND);
}