Files
root/build-tools/merge-topic/README.md
Scott Little d10d5361e8 merge-topic.py
A tool to merge all gerrit reviews based on topic.

merge-topic.py repo --help

usage: merge-topic.py repo [-h]
         --topic TOPIC [--repo-root-dir REPO_ROOT_DIR]
         [--manifest MANIFEST]
         [--download-strategy {Pull,Cherry Pick,Branch,Checkout}]
         [--status {open,merged,abandoned}]
         [--merge-fixer MERGE_FIXER]
         [--avoid-re-download]
         [--dry-run]

optional arguments:
  -h, --help    show this help message and exit
  --topic TOPIC, -t TOPIC
                Gerrit topic... can be specified more than once
                (default: None)
  --repo-root-dir REPO_ROOT_DIR, -rr REPO_ROOT_DIR
                Path to repo root dir (default:
                /localdisk/designer/slittle1/WRCP_DEV)
  --manifest MANIFEST, -m MANIFEST
                File name of the manifest file (not path).  Otherwise
                use the manifest selected by the last "repo init"
                (default: None)
  --download-strategy {Pull,Cherry Pick,Branch,Checkout}
                Strategy to download the patch: Pull, Cherry Pick,
                Branch, Checkout (default: Cherry Pick)
  --status {open,merged,abandoned}, -s {open,merged,abandoned}
                Status of the review... can be specified more than
                once (default: ['open'])
  --merge-fixer MERGE_FIXER, -mf MERGE_FIXER
                Script to be run to attempt auto merge fixing, e.g.
                pick_both_merge_fixer.py (default: None)
  --avoid-re-download, -ard
                Avoid re-downloading a commit if it already exists in
                the git repo. (default: False)
  --dry-run     Simulate, but don't sync (default: False)

Signed-off-by: Scott Little <scott.little@windriver.com>
Change-Id: I2a11af26368fd10d9457ddb39101c7e136f478c9
2025-05-16 11:01:20 -04:00

2.8 KiB

gerrit-topic-picker

Features for repositories managed by repo tool

  • Can filter status

    merge-topic.py --status/-s open --status/-s merged .. --status/-s whatever
    
  • Can avoid re-downloading a review if a commit with the Change-Id is present

    merge-topic.py --avoid-re-download/-ard
    
  • Specify one or more topics

    merge-topic.py --topic target-topic-1 --topic target-topic-2
    merge-topic.py -t target-topic
    
  • gerrit URL is automatically discovered from the .gitreview file for each repo

  • Specify download strategy

    merge-topic.py --download-strategy/-ds "Cherry Pick"
    merge-topic.py --download-strategy/-ds "Pull"
    
  • Specify script to be run in case of merge conflict. A simple fixer is supplied by "pick_both_merge_fixer.py".
    Otherwise provide your own.

    merge-topic.py --merge-fixer pick_both_merge_fixer.py
    merge-topic.py --merge-fixer my_script.sh
    merge-topic.py --merge-fixer my_script.py
    merge-topic.py --merge-fixer my_script.runnable
    

Usage for repositories managed by repo tool:

Set the MY_REPO_ROOT_DIR environment variable to the repo root directory (the one which contains the .repo dir)

MY_REPO_ROOT_DIR=/path/to/repo/ python3 merge-topic.py repo --help

Example usage in real life:

MY_REPO_ROOT_DIR=/here \
    python3 merge-topic.py repo \
    --topic my-topic \
    --download-strategy "Cherry Pick" \
    --status open \
    --avoid-re-download
# OR short
MY_REPO_ROOT_DIR=/here \
    python3 merge-topic.py repo \
    -t my-topic \
    -ds "Cherry Pick" \
    -s open \
    -ard


# fails a cherry-pick: CalledProcessError(1, ' git cherry-pick FETCH_HEAD')

# resolve the cherry-pick merge errors
# then invoke the tool againg with the same parameters
# repeat the process until all commits are synced

Example usage for specifying a script that could automatically fix merge conflicts:

MY_REPO_ROOT_DIR=/here \
    python3 merge-topic.py repo \
    --topic my-topic \
    --download-strategy "Cherry Pick" \
    --status open \
    --avoid-re-download \
    --merge-fixer dummy_merge_fixer.py

Example real life usage with merge fixer that picks changes from both sources:

MY_REPO_ROOT_DIR=/here \
    python3 merge-topic.py repo \
    --topic my-topic \
    --download-strategy "Cherry Pick" \
    --status open \
    --avoid-re-download \
    --merge-fixer pick_both_merge_fixer.py

Example usage for syncing open and merged reviews:

MY_REPO_ROOT_DIR=/here \
    python3 merge-topic.py repo \
    --topic my-topic \
    --download-strategy "Cherry Pick" \
    --status open \
    --status merged \
    --avoid-re-download

Future Work

  • Pick relation chain
  • Improve merge fixer logging
  • Fully automate merge fixer