如何在多个 github 存储库上强制使用 .clang-format
我正在使用多个 C++ github 存储库,它们都共享(作为公司标准)相同的 .clang 格式文件。 我们决定将此文件放在单独的存储库中,以便能够跟踪更改。我正在寻找一种方法将此文件中的修改发布到所有相关存储库。 手动执行此操作不是一个选项,因为我有很多存储库。
- 我想将此存储库作为 git 子模块,但在这个解决方案中,我无法在存储库的根目录中克隆子模块。
- 想要将其克隆到一个目录中并具有到子模块的符号链接,但是我可以在 Windows 中拥有符号链接吗?存储库在 Windows、Linux 和 Mac 之间共享
- 将所有存储库作为 clang 格式存储库的子模块,并拥有一个更新所有子模块并自动创建拉取请求的脚本。
- 与 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.
- 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.
- 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
- 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.
- Same as 3 but without the submodules, clone each repo and copy the new file
Do you have any other better option ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然子模块仍然是最好的选择(特别是带有关联的分支,这使得更新其内容就像
git submodule一样简单update --remote
),在构建之前您仍然需要一个预处理步骤。我通常会版本化
build.bat
脚本(例如 this例如)负责设置环境和构建项目。该脚本还可以检查根文件夹中是否存在 .clang-format ,如果不存在,则从子模块中复制它。
由于该存储库的每个用户都必须调用
build.bat
来...构建项目,他们甚至不必知道该预处理步骤。OP sagi 添加了 评论:
这就是
.gitattributes
文件中声明的内容过滤器驱动程序可以提供帮助的地方。您仍然需要每个用户首先键入命令:
并且您需要验证虚拟文件
.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:
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:
And you need to verion a dummy file
.clang-format.tpl
to associate that particular file with thesmudge
script.But the idea that the smudge script will be called on
git clone
orgit 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.