跳转到主要内容

一个将来自不同远程的git分支聚合到一个统一的程序

项目描述

License: AGPL-3 https://github.com/acsone/git-aggregator/actions/workflows/ci.yml/badge.svg pre-commit.ci status https://img.shields.io/pypi/pyversions/git-aggregator

git-aggregator

管理来自不同远程的git分支的聚合,以构建一个统一的分支。

配置文件

创建一个 repos.yamlrepos.yml 文件

./product_attribute:
    remotes:
        oca: https://github.com/OCA/product-attribute.git
        acsone: git+ssh://git@github.com/acsone/product-attribute.git
    merges:
        - oca 8.0
        - oca refs/pull/105/head
        - oca refs/pull/106/head

./connector-interfaces:
    remotes:
        oca:  https://github.com/OCA/connector-interfaces.git
        acsone:  https://github.com/acsone/connector-interfaces.git
    merges:
        - oca 6054de2c4e669f85cec380da90d746061967dc83
        - acsone 8.0-connector_flow
        - acsone 80_connector_flow_ir_cron_able-lmi
        - acsone 8.0_connector_flow_improve_eval_config
    target: acsone aggregated_branch_name
    fetch_all:
        - oca

如果选择正确的选项,此文件内的环境变量将被展开。

所有 合并 都将被合并到一个单一的分支中。默认情况下,此分支名为 _git_aggregated,但在 目标 部分中可以指定另一个名称。

仅获取所需的分支

如果你的合并操作中引用了特定的提交,你可能需要从相应的远程获取所有远程或使用其他策略来获取该获取操作,但我们建议简单地像上面示例那样添加

fetch_all:
    - oca
    - other-remote

你可以使用以下命令指定要获取所有远程定义的引用:

fetch_all: true

浅克隆仓库

为了节省大量的带宽和磁盘空间,你可以使用浅克隆。这些只下载根据某些标准限制的提交数量。可用选项有 depthshallow-sinceshallow-exclude

您可以在 defaults 部分中使用这些选项以在所有地方应用它们,或者指定在相应的 merges 部分,在这种情况下,您必须使用 dict 的备用构造。如果您需要在 merges 中禁用默认项,请将其设置为 false

./odoo:
    defaults:
        depth: 20
    remotes:
        odoo: https://github.com/odoo/odoo.git
        ocb: https://github.com/OCA/OCB.git
        acsone: https://github.com/acsone/odoo.git
    merges:
        -
            remote: ocb
            ref: "9.0"
            depth: 1000
        -
            remote: odoo
            ref: refs/pull/14859/head
    target: acsone 9.0

请记住,您需要获取所有合并的公共祖先才能成功。

触发器

还可能指定在聚合(推送之前)后执行命令或 shell 命令列表。这些命令在聚合目录中执行。

./product_attribute:
    remotes:
        oca: https://github.com/OCA/product-attribute.git
        acsone: git+ssh://git@github.com/acsone/product-attribute.git
    merges:
        - oca 8.0
    target: acsone aggregated_branch_name
    shell_command_after: echo 'my command'

./connector-interfaces:
    remotes:
        oca:  https://github.com/OCA/connector-interfaces.git
        acsone:  https://github.com/acsone/connector-interfaces.git
    merges:
        - oca 9.0
    target: acsone aggregated_branch_name
    shell_command_after:
        - echo 'a first command'
        - echo 'a second command'

实际应用示例:应用补丁

./odoo:
    remotes:
        oca: https://github.com/OCA/OCB.git
        acsone: git@github.com/acsone/OCB.git
    merges:
        - oca 9.0
    target: acsone aggregated_branch_name
    shell_command_after:
        - git am "$(git format-patch -1 XXXXXX -o ../patches)"

命令行用法

根据上面示例中的 repos.yaml 文件,您可以随时聚合您的仓库

$ gitaggregate -c repos.yaml

在加载时展开配置文件中的环境变量

$ gitaggregate -c repos.yaml --expand-env

配置文件中的变量可以以下方式指定

  • $VARIABLE

  • ${VARIABLE}

有关更多信息,请参阅 Python 的 string.Template 文档。

在展开时使用文件中的额外变量

$ gitaggregate -c repos.yaml --expand-env --env-file .env

env 文件应包含 VAR=value 行。以 # 开头的行将被忽略。

如果配置了 target 选项,您还可以聚合并将结果自动推送到目标位置

$ gitaggregate -c repos.yaml -p

仅使用 fnmatch 聚合特定仓库

$ gitaggregate -c repos.yaml -p -d connector-interfaces

显示 GitHub 拉取请求

gitaggregate 有一种机制来识别与合并或关闭的 GitHub 拉取请求对应的合并。

此类合并的形式为 refs/pull/NNN/head,其中 NNN 是拉取请求编号,具有 https://github.comgit@github.com 远程。

为了解决 API 限制,您必须首先生成一个 GitHub API 令牌

$ export GITHUB_TOKEN=...
$ gitaggregate -c repos.yaml show-all-prs
$ gitaggregate -c repos.yaml show-closed-prs

更改

4.0 (2023-07-22)

  • [破坏性更改] 移除对除了 yaml 之外的其他配置文件格式的支持

  • 确保始终以快进模式执行 git pull

  • 移除对 python 3.6 的支持,使用 python 3.11 进行测试,停止对 pypy 的测试

3.0.1 (2022-09-21)

  • 修复 git clone 与 git < 2.17 的兼容性问题

3.0.0 (2022-09-20)

  • 在更新远程时,现在的日志消息现在显示 Updating remote 而不是 Remote remote

  • 添加 --no-color 选项以禁用彩色输出

  • 使用 git clone –filter=blob:none + 获取策略以提高性能并从 git-autoshare(如果已安装)中受益

2.1(2021 年 8 月 26 日)

2.0(2021 年 8 月 17 日)

  • 移除对 python < 3.6 的支持

  • 不要在 KeyboardInterrupt 时退出成功

  • 使 target 选项可选。

1.8.1(2020 年 8 月 28 日)

  • 配置文件支持环境变量。

1.7.1(2019年9月30日)

  • 如果发生错误,记录它在哪个仓库发生。在并行运行时很有帮助。

1.7.0(2019年8月14日)

  • 修复了--show-all-prs中的错误,该错误会打印错误的PR URL。

  • --show-all-prs中显示PR标签。

1.6.0(2019年3月4日)

  • 添加了–show-all-prs命令,用于列出在合并部分中使用的所有GitHub拉取请求。

1.5.0(2018年12月7日)

  • 添加–force。如果设置,则脏仓库将无法聚合。

1.4.0(2018年9月13日)

  • 添加–jobs选项以进行多进程操作。

1.3.0(2018年8月21日)

  • 通过模仿Kaptan通过扩展名解析处理器的行为来改进配置文件解析(#22)

1.2.1(2018年7月12日)

  • show-closed-prs现在显示合并状态

  • 一些文档改进

1.2.0(2017年5月17日)

  • 支持.yml配置文件扩展名

  • 添加了show-closed-prs命令,用于显示已不再开放的GitHub拉取请求;在合并部分中必须将GitHub拉取请求引用为refs/pull/NNN/head

1.1.0(2017年2月1日)

1.0.0(2016年1月19日)

  • 第一个版本

致谢

作者

贡献者

维护者

ACSONE SA/NV

该项目由ACSONE SA/NV维护。

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

git_aggregator-4.0.1.tar.gz (37.6 kB 查看散列)

上传时间

构建分布

git_aggregator-4.0.1-py3-none-any.whl (30.4 kB 查看散列)

上传时间 Python 3

支持