in src/shipit/repo/ShipItRepoGIT.php [269:354]
public async function genCommitPatch(
ShipItChangeset $patch,
bool $do_submodules = true,
): Awaitable<string> {
if (C\is_empty($patch->getDiffs())) {
// This is an empty commit, which `git am` does not handle properly.
await $this->genGitCommand(
'commit',
'--allow-empty',
'--author',
$patch->getAuthor(),
'--date',
(string)$patch->getTimestamp(),
'-m',
self::getCommitMessage($patch),
);
return await $this->genHEADSha();
}
$diff = self::renderPatch($patch);
try {
await $this->genGitPipeCommand(
$diff,
'am',
'--keep-non-patch',
'--keep-cr',
'--committer-date-is-author-date',
);
} catch (ShipItRepoGITException $e) {
// If we are trying to git am on a non-git repo, for example
await $this->genGitCommand('am', '--abort');
throw $e;
} catch (ShipItRepoException $e) {
await $this->genGitCommand('am', '--abort');
throw $e;
} catch (ShipItShellCommandException $e) {
await $this->genGitCommand('am', '--abort');
throw $e;
}
if ($do_submodules) {
$submodules = await $this->genSubmodules();
} else {
$submodules = vec[];
}
foreach ($submodules as $submodule) {
try {
// @lint-ignore AWAIT_IN_LOOP We need to do this serially
await $this->genPrepareSubmoduleForPatch($submodule);
} catch (ShipItShellCommandException $e) {
// HACK: try once again with GitHub HTTPS authentication.
// Since most submodules in use don't need auth, it's least disruptive
// to do this only when the first attempt fails.
$url = $submodule['url'];
$match = Regex\first_match(
$url,
re"@https://github.com/(?<org>[^\./]+)/(?<project>[^\./]+)[\./]?@",
);
if ($match is null) {
throw $e;
}
// FIXME: FB-specific
try {
// @lint-ignore AWAIT_IN_LOOP We need to do this serially
// @oss-disable: await FBGitHubUtils::genConfigureSubmodule(
// @oss-disable: $match['org'],
// @oss-disable: $match['project'],
// @oss-disable: $this->getPath(),
// @oss-disable: $submodule,
// @oss-disable: );
// @lint-ignore AWAIT_IN_LOOP We need to do this serially
await $this->genPrepareSubmoduleForPatch($submodule);
} finally {
// Cleanup from submodule auth
try {
// @lint-ignore AWAIT_IN_LOOP We need to do this serially
await $this->genGitCommand('restore', '.gitmodules');
} catch (ShipItShellCommandException $_) {
}
}
}
}
// DANGER ZONE! Cleanup any removed submodules.
await $this->genGitCommand('clean', '-f', '-f', '-d');
return await $this->genHEADSha();
}