Skip to content

Fix relative paths not resolving against the repository in Repository::run() - #249

Merged
lyrixx merged 1 commit into
mainfrom
fix-67-relative-path-resolution
Sep 7, 2026
Merged

Fix relative paths not resolving against the repository in Repository::run()#249
lyrixx merged 1 commit into
mainfrom
fix-67-relative-path-resolution

Conversation

@lyrixx

@lyrixx lyrixx commented Sep 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Repository::getProcess() never set the spawned git process's working directory, so it defaulted to the calling PHP script's cwd instead of the repository.
  • Commands such as apply resolve paths referenced in their arguments (e.g. the files listed in a patch) against the process cwd rather than --work-tree, so running them from outside the repository directory failed with errors like error: hello.txt: No such file or directory, as reported in Problems with Applying and reverting patches  #67.
  • Fix: set the process's working directory to the repository path ($this->getPath()) when building the process.

Fixes #67

Test plan

  • Added a regression test that applies a patch referencing a tracked file while the process cwd is deliberately set to an unrelated directory; it fails without the fix (error: README.md: No such file or directory) and passes with it.
  • Full test suite passes (vendor/bin/phpunit).
  • PHPStan clean on changed files.
  • PHP CS Fixer clean on changed files.

…::run()

The git process spawned by Repository::run() never had its working
directory set, so Symfony Process defaulted it to the calling PHP
script's cwd. Commands such as "apply" resolve the paths referenced
inside their arguments (e.g. the files listed in a patch) against the
process cwd rather than --work-tree, so running them from outside the
repository directory failed with errors like "No such file or
directory" even though --git-dir/--work-tree were correctly set.

Fixes #67
@lyrixx
lyrixx merged commit 02cda1b into main Sep 7, 2026
6 checks passed
@lyrixx
lyrixx deleted the fix-67-relative-path-resolution branch September 7, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Problems with Applying and reverting patches

1 participant