Skip to content

Commit 9aea63f

Browse files
spoorccclaude
andauthored
docs: improve patching how-to (#1288)
- Add a note at the top pointing new users to the first-patch tutorial (with a dedicated anchor on that section) - Expand the upstream section: dry-run check first, then git am with a link to the official git-am docs; note that each patch yields a separate commit; keep git-specific instructions inside the Git tab - Document multiple patch support with a numbered-file naming convention - Mention fuzzy matching so users know patches survive minor upstream context changes - Add ref labels for diff and update-patch in the command reference and link each how-to section to the corresponding command reference entry Claude-Session: https://claude.ai/code/session_01HSFnUY2fa6WxQ7SwJ94H3Y Co-authored-by: Claude <noreply@anthropic.com>
1 parent 12ac482 commit 9aea63f

3 files changed

Lines changed: 54 additions & 5 deletions

File tree

doc/howto/patching.rst

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ patch file that is automatically re-applied on every :ref:`dfetch update
1111
into a contributor-ready unified diff that upstream maintainers can apply
1212
directly.
1313

14+
.. note::
15+
16+
New to patching with *Dfetch*? Start with :ref:`first-patch` in the
17+
getting-started tutorial, which walks through creating and applying
18+
your first patch step by step.
19+
1420
The full lifecycle looks like this:
1521

1622
1. :ref:`patching-create` — capture local edits as a ``.patch`` file with ``dfetch diff``
@@ -45,6 +51,8 @@ base. You can override this:
4551
- Single base revision: ``dfetch diff some-project --revs 23864ef2``
4652
- Explicit range: ``dfetch diff some-project --revs 23864ef2:4a9cb18``
4753

54+
See :ref:`diff` in the command reference for all options.
55+
4856
.. tabs::
4957

5058
.. tab:: Git
@@ -74,8 +82,24 @@ Once you have a patch file, reference it from the project entry in
7482
patch: some-project.patch
7583
7684
From this point on, every ``dfetch update`` will fetch the upstream source and
77-
re-apply the patch on top. See :ref:`patch` in the manifest reference for the
78-
full attribute syntax.
85+
re-apply the patch on top.
86+
87+
**Multiple patches**
88+
89+
You can split your changes into separate, focused patch files and list them in
90+
order:
91+
92+
.. code-block:: yaml
93+
94+
patch:
95+
- 001-fix-null-dereference.patch
96+
- 002-add-missing-header.patch
97+
98+
Patches are applied in the order listed. A good convention is to prefix each
99+
file name with a zero-padded number so they sort correctly and their purpose is
100+
clear at a glance.
101+
102+
See :ref:`patch` in the manifest reference for the full attribute syntax.
79103

80104
.. _patching-update:
81105

@@ -94,8 +118,15 @@ This regenerates the last patch for ``some-project`` from the current working
94118
tree, keeping the upstream revision unchanged. It is safe to run repeatedly
95119
as you iterate on the fix.
96120

121+
When the upstream version changes, *Dfetch* applies patches with fuzzy
122+
matching, so a patch can survive minor context changes without needing an
123+
immediate refresh. If the patch no longer applies at all, ``dfetch update``
124+
will report the failure and you can refresh with ``dfetch update-patch``.
125+
97126
.. asciinema:: ../asciicasts/update-patch.cast
98127

128+
See :ref:`update-patch` in the command reference for all options.
129+
99130
.. tabs::
100131

101132
.. tab:: Git
@@ -121,10 +152,10 @@ for a project:
121152
$ dfetch format-patch some-project
122153
123154
This writes a ``formatted-some-project.patch`` file (or one file per patch if
124-
there are several) that is ready to attach to a pull request or send by email.
125-
155+
there are several) that is ready to share with the upstream project.
126156

127-
You can verify the formatted patch applies cleanly before submitting:
157+
Before sending it, do a dry-run check to confirm it applies cleanly to a local
158+
clone of the upstream repository:
128159

129160
.. tabs::
130161

@@ -136,6 +167,16 @@ You can verify the formatted patch applies cleanly before submitting:
136167
137168
.. scenario-include:: ../features/format-patch-in-git.feature
138169

170+
Once confirmed, hand the file off to the upstream project. Upstream
171+
maintainers can apply it with `git am
172+
<https://git-scm.com/docs/git-am>`_:
173+
174+
.. code-block:: console
175+
176+
$ git am formatted-some-project.patch
177+
178+
Each patch file results in a separate commit.
179+
139180
.. tab:: SVN
140181

141182
.. code-block:: console
@@ -145,3 +186,5 @@ You can verify the formatted patch applies cleanly before submitting:
145186
.. scenario-include:: ../features/format-patch-in-svn.feature
146187

147188
.. asciinema:: ../asciicasts/format-patch.cast
189+
190+
See :ref:`format-patch` in the command reference for all options.

doc/reference/commands.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ Update
9696

9797
.. seealso:: :ref:`Update projects <updating-projects>` — covers the update workflow, pinning versions, and force-fetching.
9898

99+
.. _diff:
100+
99101
Diff
100102
----
101103
.. argparse::
@@ -108,6 +110,8 @@ Diff
108110

109111
.. seealso:: :ref:`Patch a project <patching>` — creating, applying, and maintaining patches across upstream version bumps.
110112

113+
.. _update-patch:
114+
111115
Update patch
112116
------------
113117
.. argparse::

doc/tutorials/getting_started.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ details on working with remotes see :ref:`Remotes`.
156156
157157
.. scenario-include:: ../features/journey-basic-usage.feature
158158

159+
.. _first-patch:
160+
159161
My first patch
160162
-----------------
161163
Sometimes you need to :term:`patch <Patch>` a dependency to get it working with your project.

0 commit comments

Comments
 (0)