diff --git a/tools/batch-rebase b/tools/batch-rebase index 164f44ec3ed73b43aef0148a9682107e5d0bfd53..849e31814f2e0c29fa316e88ea6da8206c1bcb8a 100755 --- a/tools/batch-rebase +++ b/tools/batch-rebase @@ -23,6 +23,7 @@ import argparse import subprocess import sys from collections.abc import Mapping +from collections import Counter import tempfile from pathlib import Path import datetime @@ -253,11 +254,32 @@ def _do_cherry_pick(repo, conf, persistent_tags, tags_suffix): git(['tag', '-f', '--', tag_name]) return tag_name + def resolve_action(topic): + return topic.get('action', 'cherry-pick') + + def resolve_name(topic): + action = resolve_action(topic) + if action == 'tag': + return topic['name'] + elif action == 'cherry-pick': + return topic.get('name', topic['tip']) + else: + raise ValueError(f'Could not handle action={action} in topic: {topic}') + persistent_refs = set() - topics = conf['topics'] + topics = conf['topics'].copy() for topic in topics: - topic.setdefault('name', topic['tip']) + topic.update( + action=resolve_action(topic), + name=resolve_name(topic), + ) + + for key, cnt in Counter(topic['name'] for topic in topics).items(): + if cnt > 1: + raise ValueError( + f'Found {cnt} topics named "{key}", but names must be unique.' + ) # If we are resuming after a conflict if 'conflict-topic' in conf['resume']: @@ -296,7 +318,7 @@ def _do_cherry_pick(repo, conf, persistent_tags, tags_suffix): # Cherry pick topic branches in the specified order for topic in topics: - action = topic.get('action', 'cherry-pick') + action = topic['action'] name = topic['name'] if action == 'tag': @@ -500,7 +522,7 @@ def main(): topics: - - name: foo + name: foo # The name will default to the value of "tip" if not provided remote: myremote base: mybase tip: mytip