How to force .clang-format on multiple github repos

709 views Asked by At

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 ?
1

There are 1 answers

2
VonC On

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.