如何在多个 github 存储库上强制使用 .clang-format

发布于 2025-01-12 01:07:15 字数 405 浏览 0 评论 0原文

我正在使用多个 C++ github 存储库,它们都共享(作为公司标准)相同的 .clang 格式文件。 我们决定将此文件放在单独的存储库中,以便能够跟踪更改。我正在寻找一种方法将此文件中的修改发布到所有相关存储库。 手动执行此操作不是一个选项,因为我有很多存储库。

  1. 我想将此存储库作为 git 子模块,但在这个解决方案中,我无法在存储库的根目录中克隆子模块。
  2. 想要将其克隆到一个目录中并具有到子模块的符号链接,但是我可以在 Windows 中拥有符号链接吗?存储库在 Windows、Linux 和 Mac 之间共享
  3. 将所有存储库作为 clang 格式存储库的子模块,并拥有一个更新所有子模块并自动创建拉取请求的脚本。
  4. 与 3 相同,但没有子模块,克隆每个存储库并复制新文件 您还有其他更好的选择吗?

I'm using multiple C++ github repositories, they all share (as a company standard) the same .clang-format file.
We decided to put this file in a separate repository in order to be able to track changes. I'm looking for a way to publish modifications in this file to all relevant repositories.
Doing that manually is not and option because I have many repositories.

  1. I thought to have this repository as a git submodule but in this solution I can't clone the submodule in the root of the repo.
  2. Thought to clone it into a directory and have a symbolic link to the submodule, but can I have symbolic links in Windows ? the repos are shared between Windows and Linux and Mac
  3. Have all the repos as a submodules of the clang-format repository and have a script which update all the submodules and create a pull-request automatically.
  4. Same as 3 but without the submodules, clone each repo and copy the new file
    Do you have any other better option ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的往事 2025-01-19 01:07:15

虽然子模块仍然是最好的选择(特别是带有关联的分支,这使得更新其内容就像git submodule一样简单update --remote),在构建之前您仍然需要一个预处理步骤。

我通常会版本化 build.bat 脚本(例如 this例如)负责设置环境和构建项目。

该脚本还可以检查根文件夹中是否存在 .clang-format ,如果不存在,则从子模块中复制它。

由于该存储库的每个用户都必须调用 build.bat 来...构建项目,他们甚至不必知道该预处理步骤。


OP sagi 添加了 评论

但是构建阶段可能会有点晚,因为我希望在编码时在 IDE 中进行格式化。

这就是 .gitattributes 文件中声明的内容过滤器驱动程序可以提供帮助的地方。

您仍然需要每个用户首​​先键入命令:

git config --global filter.clang.smudge 'script_install_clang'

并且您需要验证虚拟文件 .clang-format.tpl 以便将该特定文件与 smudge 脚本关联起来。

但是 smudge 脚本将在 git clone 或 git checkout/git switch 上自动调用,并且可以设置任何丢失的文件你。

这样,一旦您启动 IDE,格式文件就准备好了。

While submodule remains the best option (especially with an associated branch, which makes updating its content as easy as git submodule update --remote), you would still need a preprocessing step before building.

I usually version a build.bat script (like this one for instance) in charge of setting up the environment and building the project.

That script can also check if the .clang-format is present at the root folder and, if not, copy it from the submodule.

Since every user of that repository will have to call build.bat to... build the project, they won't even have to be aware of that preprocessing step.


The OP sagi adds in the comments:

but build phase might be a little late because I want the formatting to happen in the IDE while coding.

That is where a content filter driver declared in a .gitattributes file can help.

You still need to each user to type a command first:

git config --global filter.clang.smudge 'script_install_clang'

And you need to verion a dummy file .clang-format.tpl to associate that particular file with the smudge script.

But the idea that the smudge script will be called on git clone or git checkout/git switch automatically, and can set up any missing file for you.

That way, the format file is ready as soon as you are launching your IDE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文