diff --git a/dfetch/manifest/project.py b/dfetch/manifest/project.py index 567cfe15..2c47da58 100644 --- a/dfetch/manifest/project.py +++ b/dfetch/manifest/project.py @@ -259,6 +259,8 @@ For more details see the `git-diff `_ documentation. .. scenario-include:: ../features/diff-in-git.feature + .. scenario-include:: ../features/patch-after-fetch-git.feature + .. scenario-include:: ../features/patch-fuzzy-matching-git.feature .. tab:: SVN @@ -269,6 +271,7 @@ For more details see the `svn-diff `_ documentation. .. scenario-include:: ../features/diff-in-svn.feature + .. scenario-include:: ../features/patch-after-fetch-svn.feature """ diff --git a/features/patch-fuzzy-matching-git.feature b/features/patch-fuzzy-matching-git.feature new file mode 100644 index 00000000..38487693 --- /dev/null +++ b/features/patch-fuzzy-matching-git.feature @@ -0,0 +1,77 @@ +Feature: Patch application tolerates small upstream changes + + If an upstream git repository changes slightly after a patch was created, + the patch should still apply successfully using fuzzy matching, as long as + the changes are compatible. + + Background: + Given a git repository "SomeProject.git" + And the patch file 'SomeProject.patch' in MyProject + """ + diff --git a/README.md b/README.md + index 1e65bd6..faa3b21 100644 + --- a/README.md + +++ b/README.md + @@ -1 +1,2 @@ + Generated file for SomeProject.git + +An important sentence for the README! + """ + And a fetched and committed MyProject with the manifest + """ + manifest: + version: 0.0 + projects: + - name: SomeProject + url: some-remote-server/SomeProject.git + patch: SomeProject.patch + """ + + Scenario: Patch applies when upstream adds extra lines + Given "README.md" in git-repository "SomeProject.git" is changed to: + """ + Generated file for SomeProject.git + Additional upstream line. + """ + When I run "dfetch update" + Then the patched 'MyProject/SomeProject/README.md' is + """ + Generated file for SomeProject.git + An important sentence for the README! + Additional upstream line. + """ + + Scenario: Patch applies when context lines have changed + Given "README.md" in git-repository "SomeProject.git" is changed to: + """ + Generated file for SomeProject + This repository is used for testing. + """ + And the patch file 'SomeProject.patch' in MyProject + """ + diff --git a/README.md b/README.md + index 1e65bd6..faa3b21 100644 + --- a/README.md + +++ b/README.md + @@ -1 +1,2 @@ + Generated file for SomeProject.git + +An important sentence for the README! + """ + When I run "dfetch update" + Then the output shows + """ + Dfetch (0.11.0) + SomeProject: + > Fetched master - f47d80c35e14dfa4f9c9c30c9865cbf0f8d50933 + > Applying patch "SomeProject.patch" + file 1/1: b'README.md' + hunk no.1 doesn't match source file at line 1 + expected: b'Generated file for SomeProject.git' + actual : b'Generated file for SomeProject' + successfully patched 1/1: b'README.md' + """ + And the patched 'MyProject/SomeProject/README.md' is + """ + Generated file for SomeProject + An important sentence for the README! + This repository is used for testing. + """ diff --git a/features/steps/generic_steps.py b/features/steps/generic_steps.py index 8e00b9e2..8d35a44f 100644 --- a/features/steps/generic_steps.py +++ b/features/steps/generic_steps.py @@ -198,6 +198,7 @@ def check_output(context, line_count=None): """ expected_text = multisub( patterns=[ + (dfetch_title, "Dfetch (x.x.x)"), (git_hash, r"\1[commit-hash]\2"), (timestamp, "[timestamp]"), (ansi_escape, ""), @@ -208,6 +209,7 @@ def check_output(context, line_count=None): actual_text = multisub( patterns=[ + (dfetch_title, "Dfetch (x.x.x)"), (git_hash, r"\1[commit-hash]\2"), (timestamp, "[timestamp]"), (ansi_escape, ""), @@ -246,9 +248,10 @@ def step_impl(_, old_path: str, new_path: str, directory: str): @given("the patch file '{name}'") +@given("the patch file '{name}' in {directory}") @given("the patch file '{name}' with '{encoding}' encoding") -def step_impl(context, name, encoding="UTF-8"): - generate_file(os.path.join(os.getcwd(), name), context.text, encoding) +def step_impl(context, name, encoding="UTF-8", directory="."): + generate_file(os.path.join(directory, name), context.text, encoding) @given('"{path}" in {directory} is created') diff --git a/features/steps/git_steps.py b/features/steps/git_steps.py index b1d923fc..73d61318 100644 --- a/features/steps/git_steps.py +++ b/features/steps/git_steps.py @@ -135,6 +135,14 @@ def step_impl(context, directory, path): commit_all("A change") +@given('"{path}" in git-repository "{name}" is changed to:') +def step_impl(context, path, name): + remote_path = os.path.join(context.remotes_dir, name) + with in_directory(remote_path): + generate_file(path, context.text) + commit_all("A change") + + @given("all files in {directory} are committed") @when("all files in {directory} are committed") def step_impl(_, directory):