Skip to content

Commit 40794f1

Browse files
committed
Add basic patching documentation
1 parent 58a922d commit 40794f1

4 files changed

Lines changed: 140 additions & 2 deletions

File tree

doc/getting_started.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,64 @@ details on working with remotes see :ref:`Remotes`.
139139
repo-path: cpputest/cpputest
140140
141141
.. scenario-include:: ../features/journey-basic-usage.feature
142+
143+
My first patch
144+
-----------------
145+
Sometimes you need to patch a dependency to get it working with your project.
146+
*Dfetch* supports creating and applying patches after fetching the dependency.
147+
148+
Given you have fetched ``dfetch-org/test-repo`` and you need to apply a patch.
149+
First commit the fetched version to your version control system. This provides
150+
*Dfetch* a reference point.
151+
152+
.. code-block:: console
153+
154+
git add ext/test-repo-tag
155+
git commit -m "Add test-repo-tag v2.0"
156+
157+
Then you can work on the files inside ``ext/test-repo-tag``, once you are happy
158+
you can run ``dfetch diff`` to create a patch file with respect to the committed
159+
version.
160+
161+
.. code-block:: console
162+
163+
dfetch diff
164+
165+
This patch file can now be applied automatically by *Dfetch* in next updates.
166+
Add it to your manifest as shown below.
167+
168+
.. code-block:: yaml
169+
170+
manifest:
171+
version: '0.0'
172+
173+
remotes:
174+
- name: github
175+
url-base: https://github.com/
176+
177+
projects:
178+
- name: ext/test-repo-tag
179+
repo-path: dfetch-org/test-repo
180+
patch: ext-test-repo-tag.patch
181+
182+
- name: cpputest
183+
repo-path: cpputest/cpputest
184+
185+
To test the patch, update the project again but with the ``-f`` option to force
186+
overwriting the local changes. The local changes will be lost but the patch will
187+
be applied.
188+
189+
.. code-block:: console
190+
191+
dfetch update -f ext/test-repo-tag
192+
193+
Now all changes can be amended to the last committed version including the patch.
194+
195+
.. code-block:: console
196+
197+
git add ext/test-repo-tag ext-test-repo-tag.patch
198+
git commit --amend -no-edit
199+
200+
For more details on working with patches see :ref:`Diff` and :ref:`Patch`.
201+
202+
.. scenario-include:: ../features/journey-basic-patching.feature
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Feature: Basic patch journey
2+
3+
The main user journey is for patching is:
4+
- Adding a project to a manifest
5+
- Fetching the new project and committing it.
6+
- Changing files in the fetched project.
7+
- Generating a patch file.
8+
- Update the project again to verify the patch.
9+
- Amending the changed project and the patch to version control.
10+
11+
Below scenario is described in the getting started and should at least work.
12+
13+
Scenario: Basic patch journey
14+
15+
Given a local git repo "MyPatchExample" with the manifest
16+
"""
17+
manifest:
18+
version: '0.0'
19+
20+
projects:
21+
- name: test-repo
22+
dst: ext/test-repo
23+
tag: v1
24+
url: https://github.com/dfetch-org/test-repo
25+
"""
26+
When I run "dfetch update test-repo" in MyPatchExample
27+
Then the following projects are fetched
28+
| path |
29+
| MyPatchExample/ext/test-repo |
30+
When all files in MyPatchExample/ext/test-repo are committed
31+
And "ext/test-repo/my-new-file.md" in MyPatchExample is created
32+
When I run "dfetch diff test-repo" in MyPatchExample
33+
Then the patch file 'MyPatchExample/test-repo.patch' is generated
34+
"""
35+
diff --git a/my-new-file.md b/my-new-file.md
36+
new file mode 100644
37+
index 0000000..0ee3895
38+
--- /dev/null
39+
+++ my-new-file.md
40+
@@ -0,0 +1 @@
41+
+Some content
42+
"""
43+
When the manifest 'dfetch.yaml' in MyPatchExample is changed to
44+
"""
45+
manifest:
46+
version: '0.0'
47+
48+
projects:
49+
- name: test-repo
50+
dst: ext/test-repo
51+
tag: v1
52+
url: https://github.com/dfetch-org/test-repo
53+
patch: test-repo.patch
54+
"""
55+
And I run "dfetch update -f test-repo"
56+
Then the output shows
57+
"""
58+
Dfetch (0.10.0)
59+
test-repo : Fetched v1
60+
test-repo : Applied patch "test-repo.patch"
61+
"""

features/steps/generic_steps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def step_impl(context, name):
150150

151151

152152
@given('"{path}" in {directory} is created')
153-
def step_impl(context, directory, path):
153+
@when('"{path}" in {directory} is created')
154+
def step_impl(context, path, directory="."):
154155
with in_directory(directory):
155156
generate_file(path, context.text or "Some content")
156157

features/steps/git_steps.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pathlib
88
import subprocess
99

10-
from behave import given # pylint: disable=no-name-in-module
10+
from behave import given, when # pylint: disable=no-name-in-module
1111

1212
from dfetch.util.util import in_directory
1313
from features.steps.generic_steps import call_command, extend_file, generate_file
@@ -138,6 +138,15 @@ def step_impl(context):
138138
commit_all("Initial commit")
139139

140140

141+
@given('a local git repo "{directory}" with the manifest')
142+
def step_impl(context, directory):
143+
pathlib.Path(directory).mkdir(parents=True, exist_ok=True)
144+
with in_directory(directory):
145+
create_repo()
146+
generate_manifest(context)
147+
commit_all("Initial commit")
148+
149+
141150
@given("files as '{pattern}' are ignored in git in {directory}")
142151
def step_impl(_, pattern, directory):
143152
with in_directory(directory):
@@ -158,6 +167,12 @@ def step_impl(context, directory, path):
158167
commit_all("A change")
159168

160169

170+
@when("all files in {directory} are committed")
171+
def step_impl(_, directory):
172+
with in_directory(directory):
173+
commit_all("A change")
174+
175+
161176
@given('"{path}" in {directory} is created and committed with')
162177
def step_impl(context, directory, path):
163178
with in_directory(directory):

0 commit comments

Comments
 (0)