Skip to content

Commit a014e3c

Browse files
Merge pull request #217 from janjaapdriessen/master
Allow a later source option to override an earlier one
2 parents 17e28dd + 004e2fd commit a014e3c

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

CHANGES.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ Changelog
55
2.0.5 (unreleased)
66
------------------
77

8-
* Add ``subpath`` option to specify a subdirectory of a repository. [mamico]
8+
- Allow a later source option to override an earlier one instead of raising
9+
``ValueError: Key '...' already in source info.``. This lets a ``[sources]``
10+
entry refine a shared/extended definition, e.g. ``foo += branch=my-feature``
11+
overriding the ``branch`` set upstream. Fixes `#125
12+
<https://github.com/fschulze/mr.developer/issues/125>`_.
13+
[janjaapdriessen]
14+
15+
- Add ``subpath`` option to specify a subdirectory of a repository. [mamico]
916

1017

1118
2.0.4 (2025-07-17)

src/mr/developer/extension.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ def get_sources(self):
115115
if not key:
116116
raise ValueError("Option with no name '%s'." % option)
117117
if key in source:
118-
raise ValueError("Key '%s' already in source info." % key)
118+
# A later option overrides an earlier one, e.g.
119+
# ``foo += branch=my-feature`` refining the ``branch`` set
120+
# in a shared/extended source definition.
121+
logger.info(
122+
"Overriding '%s' for source '%s'." % (key, name))
119123
if key == 'path':
120124
value = os.path.join(value, name)
121125
if not os.path.isabs(value):

src/mr/developer/tests/test_extension.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,16 @@ def testOptionParsingBeforeURL(self, buildout, extension):
218218
assert sources['pkg.foo']['rev'] == '>=456ad138'
219219

220220
def testDuplicateOptionParsing(self, buildout, extension):
221+
# A duplicate option is not an error: the later value wins, so a
222+
# ``+=`` addition can override a value from a shared source definition
223+
# (e.g. ``pkg.foo += branch=feature``).
221224
buildout['sources'].update({
222225
'pkg.foo': 'git dummy://foo/trunk rev=456ad138 rev=blubber',
226+
'pkg.bar': 'git dummy://bar branch=main branch=feature',
223227
})
224-
pytest.raises(ValueError, extension.get_sources)
225-
226-
buildout['sources'].update({
227-
'pkg.foo': 'git dummy://foo/trunk kind=svn',
228-
})
229-
pytest.raises(ValueError, extension.get_sources)
228+
sources = extension.get_sources()
229+
assert sources['pkg.foo']['rev'] == 'blubber'
230+
assert sources['pkg.bar']['branch'] == 'feature'
230231

231232
def testInvalidOptionParsing(self, buildout, extension):
232233
buildout['sources'].update({

0 commit comments

Comments
 (0)