series = PatchSeries()
if 'patch' in self._tags:
tags = self._patches()
- macros = {}
+ applied = []
for macro in self._special_directives['patch']:
- macros[macro['id']] = macro['args']
- ignored = [] if ignored else self.ignorepatches
-
- for num, tag in sorted(tags.iteritems()):
- strip = 0
- if num in macros:
- opts = self._patch_macro_opts(macros[num])
+ if macro['id'] in tags:
+ applied.append((macro['id'], macro['args']))
+ ignored = set() if ignored else set(self.ignorepatches)
+
+ # Put all patches that are applied first in the series
+ for num, args in applied:
+ if num not in ignored:
+ opts = self._patch_macro_opts(args)
strip = int(opts.strip) if opts.strip else 0
- if (unapplied or (num in macros)) and num not in ignored:
- filename = os.path.basename(tag['linevalue'])
+ filename = os.path.basename(tags[num]['linevalue'])
series.append(Patch(os.path.join(self.specdir, filename),
strip=strip))
+ # Finally, append all unapplied patches to the series, if requested
+ if unapplied:
+ applied_nums = set([num for num, _args in applied])
+ unapplied = set(tags.keys()).difference(applied_nums)
+ for num in sorted(unapplied):
+ if num not in ignored:
+ filename = os.path.basename(tags[num]['linevalue'])
+ series.append(Patch(os.path.join(self.specdir,
+ filename), strip=0))
return series
def _guess_orig_prefix(self, orig):
assert len(spec.patchseries(ignored=True)) == 1
series = spec.patchseries(unapplied=True, ignored=True)
assert len(series) == 2
- assert os.path.basename(series[-1].path) == '4.patch'
+ assert os.path.basename(series[-1].path) == '1.patch'
+
+ def test_patch_series_quirks(self):
+ """Patches are applied in order different from the patch numbering"""
+ spec_filepath = os.path.join(SPEC_DIR, 'gbp-test-quirks.spec')
+ spec = SpecFileTester(spec_filepath)
+
+ # Check series is returned in the order the patches are applied
+ files = [os.path.basename(patch.path) for patch in spec.patchseries()]
+ assert files == ['05.patch', '01.patch']
+ # Also ignored patches are returned in the correct order
+ files = [os.path.basename(patch.path) for patch in
+ spec.patchseries(ignored=True)]
+ assert files == ['05.patch', '02.patch', '01.patch']
+ # Unapplied patches are added to the end of the series
+ files = [os.path.basename(patch.path) for patch in
+ spec.patchseries(unapplied=True)]
+ assert files == ['05.patch', '01.patch', '03.patch']
+ # Return all patches (for which tag is found)
+ files = [os.path.basename(patch.path) for patch in
+ spec.patchseries(unapplied=True, ignored=True)]
+ assert files == ['05.patch', '02.patch', '01.patch', '03.patch',
+ '04.patch']
class TestUtilityFunctions(object):
Release: 1.2
License: GPLv2
Source1: foobar.tar.gz
+# Gbp-Ignore-Patches: 2 4 888
+Patch1: 01.patch
+Patch2: 02.patch
+Patch3: 03.patch
+Patch4: 04.patch
+Patch5: 05.patch
%description
Spec for testing some quirks of spec parsing. No intended for building an RPM.
# We don't have Source0 so rpmbuild would fail, but gbp shouldn't crash
%setup -q
+# Patches are applied out-of-order wrt. numbering
+%patch5
+%patch2
+%patch1
+# Patch 999 does not exist, rpmbuild would fail but GBP should not
+%patch999