Skip to content

Commit fbb6037

Browse files
committed
Patch file path in metadata not platform independent
Fixes #937
1 parent b97da8a commit fbb6037

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Release 0.12.0 (unreleased)
99
* Allow multiple patches in manifest (#897)
1010
* Fallback and warn if patch is not UTF-8 encoded (#941)
1111
* Skip patches outside manifest dir (#0)
12+
* Make patch path in metadata platform independeny (#937)
1213

1314
Release 0.11.0 (released 2026-01-03)
1415
====================================

dfetch/manifest/project.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@
226226
*DFetch* promotes upstreaming changes, but also allows local changes. These changes can be managed with local patch
227227
files. *DFetch* will apply the patch files in order every time a new upstream version is fetched. The patch file can
228228
be specified with the ``patch:`` attribute. This can be a single patch file or multiple. Patch files should be UTF-8
229-
encoded files.
229+
encoded files and using forward slashes is encouraged for cross-platform support. The path should be relative to the
230+
directory of the manifest.
230231
231232
.. code-block:: yaml
232233
@@ -241,11 +242,11 @@
241242
- name: cpputest
242243
vcs: git
243244
repo-path: cpputest/cpputest
244-
patch: local_changes.patch
245+
patch: patches/local_changes.patch
245246
246247
The patch should be generated using the *Dfetch* :ref:`Diff` command.
247-
Alternately the patch can be generated manually as such.
248-
Note that the patch should be *relative* to the projects root.
248+
Alternately the patch can be generated manually as such and should be
249+
a *relative* patch, relative to the fetched projects root.
249250
250251
.. tabs::
251252

dfetch/project/subproject.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pathlib
66
from abc import ABC, abstractmethod
77
from collections.abc import Sequence
8+
from pathlib import Path
89
from typing import Optional
910

1011
from halo import Halo
@@ -141,24 +142,29 @@ def update(
141142

142143
def _apply_patches(self) -> list[str]:
143144
"""Apply the patches."""
144-
manifest_dir = os.getcwd()
145+
manifest_dir = Path(".").resolve()
145146
applied_patches = []
146147
for patch in self.__project.patch:
147148

148-
real_path = os.path.realpath(patch)
149-
if os.path.commonprefix((real_path, manifest_dir)) != manifest_dir:
149+
patch_path = (manifest_dir / patch).resolve()
150+
151+
try:
152+
patch_path.relative_to(manifest_dir)
153+
except ValueError:
150154
self._log_project(
151155
f'Skipping patch "{patch}" which is outside manifest dir.'
152156
)
153157
continue
154158

155-
if not os.path.exists(patch):
159+
if not patch_path.exists():
156160
self._log_project(f"Skipping non-existent patch {patch}")
157161
continue
158162

159-
apply_patch(patch, root=self.local_path)
160-
self._log_project(f'Applied patch "{patch}"')
161-
applied_patches.append(patch)
163+
normalized_patch_path = str(patch_path.relative_to(manifest_dir).as_posix())
164+
165+
apply_patch(normalized_patch_path, root=self.local_path)
166+
self._log_project(f'Applied patch "{normalized_patch_path}"')
167+
applied_patches.append(normalized_patch_path)
162168
return applied_patches
163169

164170
def check_for_update(

0 commit comments

Comments
 (0)