Merge lp:~gz/juju-release-tools/non_patch_ext into lp:juju-release-tools

Proposed by Martin Packman
Status: Merged
Merged at revision: 331
Proposed branch: lp:~gz/juju-release-tools/non_patch_ext
Merge into: lp:juju-release-tools
Diff against target: 66 lines (+20/-3)
2 files modified
apply_patches.py (+5/-1)
tests/test_apply_patches.py (+15/-2)
To merge this branch: bzr merge lp:~gz/juju-release-tools/non_patch_ext
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+303263@code.launchpad.net

Description of the change

Allow and ignore files that aren't patches in patch directory

Juju is ready to remove the current godeps patch from master as the fix has landed upstream. As git doesn't version directories, this means we want to add a file in there that will keep the directory around but not be applied as a patch.

This branch limits patching to files that have either the 'diff' or 'patch' file extension.

To post a comment you must log in.
332. By Martin Packman

Fix typo noted by babbageclunk in review

Revision history for this message
Curtis Hovey (sinzui) wrote :

thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apply_patches.py'
2--- apply_patches.py 2016-07-21 15:30:35 +0000
3+++ apply_patches.py 2016-08-18 13:37:20 +0000
4@@ -10,6 +10,9 @@
5 import sys
6
7
8+PATCH_EXTENSIONS = (".diff", ".patch")
9+
10+
11 def apply_patch(patch_file, base_dir, dry_run=False, verbose=False):
12 """Run external patch command to apply given patch_file to base_dir."""
13 patch_cmd = ["patch", "-f", "-u", "-p1", "-r-"]
14@@ -40,11 +43,12 @@
15 parser = get_arg_parser()
16 args = parser.parse_args(argv[1:])
17 try:
18- patches = sorted(os.listdir(args.patchdir))
19+ maybe_patches = sorted(os.listdir(args.patchdir))
20 except OSError as e:
21 parser.error("Could not list patch directory: {}".format(e))
22 if not os.path.isdir(args.srctree):
23 parser.error("Source tree '{}' not a directory".format(args.srctree))
24+ patches = [f for f in maybe_patches if f.endswith(PATCH_EXTENSIONS)]
25 patch_count = len(patches)
26 print(gettext.ngettext(
27 u"Applying {} patch", u"Applying {} patches", patch_count).format(
28
29=== modified file 'tests/test_apply_patches.py'
30--- tests/test_apply_patches.py 2016-07-21 16:44:30 +0000
31+++ tests/test_apply_patches.py 2016-08-18 13:37:20 +0000
32@@ -129,7 +129,7 @@
33 with temp_dir() as basedir:
34 patchdir = os.path.join(basedir, "patches")
35 os.mkdir(patchdir)
36- patchfile = os.path.join(patchdir, "sample.patch")
37+ patchfile = os.path.join(patchdir, "sample.diff")
38 open(patchfile, "w").close()
39 with self.patch_output() as messages:
40 with mock.patch(
41@@ -138,7 +138,7 @@
42 main(["test", patchdir, basedir])
43 ap_mock.assert_called_once_with(patchfile, basedir, False, False)
44 self.assertEqual(messages, [
45- u"Applying 1 patch", u"Applied patch 'sample.patch'"
46+ u"Applying 1 patch", u"Applied patch 'sample.diff'"
47 ])
48
49 def test_bad_patches(self):
50@@ -158,3 +158,16 @@
51 self.assertEqual(messages, [
52 u"Applying 2 patches", u"Failed to apply patch 'a.patch'"
53 ])
54+
55+ def test_non_patch(self):
56+ with temp_dir() as basedir:
57+ patchdir = os.path.join(basedir, "patches")
58+ os.mkdir(patchdir)
59+ patch_a = os.path.join(patchdir, "readme.txt")
60+ open(patch_a, "w").close()
61+ with self.patch_output() as messages:
62+ with mock.patch(
63+ "apply_patches.apply_patch", autospec=True) as ap_mock:
64+ main(["test", "--verbose", patchdir, basedir])
65+ self.assertEqual(ap_mock.mock_calls, [])
66+ self.assertEqual(messages, [u"Applying 0 patches"])

Subscribers

People subscribed via source and target branches