diff --git a/src/Configuration/LifterConfig.php b/src/Configuration/LifterConfig.php index d5b6b39..d97afb1 100644 --- a/src/Configuration/LifterConfig.php +++ b/src/Configuration/LifterConfig.php @@ -20,6 +20,9 @@ final class LifterConfig private bool $commitResults = true; + private ?string $commitAuthor = null; + private ?string $commitEMail = null; + public function __construct(public readonly ?string $configurationFile) { $this->workingDirectory = \Safe\getcwd(); @@ -49,6 +52,21 @@ public function getCommitMessagePrefix(): string return $this->commitMessagePrefix; } + public function withCommitAuthor(string $name, string $email): void + { + $this->commitAuthor = $name; + $this->commitEMail = $email; + } + + public function getCommitAuthor(): ?string + { + if ($this->commitAuthor === null || $this->commitEMail === null) { + return null; + } + + return sprintf('%s <%s>', $this->commitAuthor, $this->commitEMail); + } + /** * @var list */ diff --git a/src/Upgrade/GitService.php b/src/Upgrade/GitService.php index c152048..1f03dc0 100644 --- a/src/Upgrade/GitService.php +++ b/src/Upgrade/GitService.php @@ -22,16 +22,23 @@ public function doGitCommitForStep(UpgradeStep $step): void if ($this->config->getCommitMessagePrefix() !== '') { $commitMessage = sprintf('%s %s', $this->config->getCommitMessagePrefix(), $commitMessage); } + $authorParams = []; + $commitAuthor = $this->config->getCommitAuthor(); + if ($commitAuthor !== null) { + $authorParams[] = '--author'; + $authorParams[] = $commitAuthor; + } - $process = $this->processFactory->createProcess( + $process = $this->processFactory->createProcess(...[ '/usr/bin/env', 'git', 'commit', + ...$authorParams, '-a', '--allow-empty', '-m', - $commitMessage - ); + $commitMessage, + ]); $process->run(); if ($process->getExitCode() > 0) {