in src/shipit/repo/ShipItRepoGIT.php [356:407]
private async function genPrepareSubmoduleForPatch(
self::TSubmoduleSpec $submodule,
): Awaitable<void> {
// If a submodule has changed, then we need to actually update to the
// new version. + before commit hash represents changed submdoule.
// - before commit hash represents an uninitialized submodule. Make
// sure there is no leading whitespace that comes back when we get the
// status since the first character will tell us whether submodule
// changed.
$sm_status = Str\trim_left(
await $this->genGitCommand('submodule', 'status', $submodule['path']),
);
if ($sm_status === '') {
// If the path exists, we know we are adding a submodule.
$full_path = $this->getPath().'/'.$submodule['path'];
$sha = Str\trim(Str\slice(
\file_get_contents($full_path),
Str\length('Subproject commit '),
));
await $this->genGitCommand('rm', $submodule['path']);
await $this->genGitCommand(
'submodule',
'add',
'-f',
'--name',
$submodule['name'],
$submodule['url'],
$submodule['path'],
);
await (new ShipItShellCommand($full_path, 'git', 'checkout', $sha))
->genRun();
await $this->genGitCommand('add', $submodule['path']);
// Preserve any whitespace in the .gitmodules file.
await $this->genGitCommand('checkout', 'HEAD', '.gitmodules');
await $this->genGitCommand('commit', '--amend', '--no-edit');
} else if ($sm_status[0] === '+') {
await $this->genGitCommand(
'submodule',
'update',
'--recursive',
$submodule['path'],
);
} else if ($sm_status[0] === '-') {
await $this->genGitCommand(
'submodule',
'update',
'--init',
'--recursive',
$submodule['path'],
);
}
}