Skip to content

Commit 450e56e

Browse files
committed
Critical fix: prevent 'patch' command from automaticall reversing patches that were applied upstream
1 parent 8f2b00a commit 450e56e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/PatchApplicator.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private function executePatchCommand($method, $targetDirectory, $patchFile, $str
126126
$cwd = null;
127127

128128
if ($method === self::METHOD_PATCH && $this->hasPatchCommand()) {
129-
$cmd = ['patch', '--posix', '--batch', '--strip=' . $stripPathComponents, '--input='.$patchFile, '--directory='.$targetDirectory];
129+
$cmd = ['patch', '--posix', '--batch', '--forward', '--strip=' . $stripPathComponents, '--input='.$patchFile, '--directory='.$targetDirectory];
130130
} else {
131131
$cmd = ['git', 'apply', '-v', '-p' . $stripPathComponents, $patchFile];
132132

@@ -159,6 +159,14 @@ public function applyPatch(Patch $patch, PackageInterface $sourcePackage, Packag
159159
$patchFilename = $this->pathResolver->getPatchSourceFilePath($sourcePackage, $patch);
160160

161161
if (!$this->executePatchCommand($patch->getMethod(), $targetDirectory, $patchFilename, $patch->getStripPathComponents())) {
162+
$this->logger->notice(sprintf('<error>Failed to apply patch</error> <info>%s:%s</info> [<comment>%s</comment>] (<comment>%s</comment>) using <comment>%s</comment> method',
163+
$patch->getSourcePackage(),
164+
$patch->getFilename(),
165+
$patch->getVersionConstraint(),
166+
$patch->getDescription(),
167+
$patch->getMethod()
168+
));
169+
162170
throw new PatchApplicationFailedException($this->lastCmd, $this->lastCmdOutput);
163171
}
164172

0 commit comments

Comments
 (0)