Is it possible to share a single file in the root folder of multiple git repositories?
Asked Answered
A

2

6

Our team has multiple repositories for code and we're looking into ways to get a single location for some shared config files (specifically, the .editorconfig file).

Is there a way to share a single file, AT THE ROOT OF A GIT REPOSITORY, across multiple repositories? Is there any other ways that someone knows of, that don't involve having some script that "downloads" the same version of the file? Thanks a lot for any help, in advance.

Cheers

Appoggiatura answered 2/10, 2019 at 12:59 Comment(2)
Not a real nice solution, but as long as all of the developers do have the same directory structure, you could use a file ".editorconfig" in the root folder of your projects and use a symlink in the concrete projects. You should take care that you are using relative pathes and thils will most probably only work for mac os and linux.Ostwald
I would set an environment variable to set the pathOrsino
P
3

I've defined next way:

  1. Create a NuGet package with .editorconfig file inside.
  2. Add this into the NuGet package .csproj file.
<ItemGroup>
  <None Update=".editorconfig">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>
  1. Add a reference or install your NuGet pakcage into your project where you want to import your .editorconfig.
  2. Then add this target to the project.
<Target Name="CopyFile" AfterTargets="AfterBuild">
    <Copy SourceFiles="$(OutDir)/.editorconfig" DestinationFolder="./" />
</Target>

  1. Build your project and the .editorconfig will appear in the root of your project.

I believe there is a possibility to modify the .csproj file during NuGet package installing process. If it is true, then step 4 could be authomated.

Pastorale answered 12/3, 2020 at 12:52 Comment(3)
I tried to follow the same steps, but the .editorconfig is not added in the .nupkg, did you do something special to make sure the file is included in the nupkg?Babylon
@Babylon Unfortunatelly no, I just have my assembly locally and I just refer to it.Pastorale
@Babylon It seems you need to add the file to the "content" directory. #10786096Pastorale
C
2

You can't have a shared file among multiple repositories. However, editors should search up the directory hierarchy for an .editorconfig file, so if you have a directory in which all of your existing repositories live, you can install it in that directory, and it will apply to all repositories.

One way of doing this is to provide a repository which contains the .editorconfig and any other relevant development code, and checking out other code underneath it. GitLab uses this for their development environments.

Centenarian answered 2/10, 2019 at 22:37 Comment(1)
so far this seems to be the best chance for a shared file. We've also tested around with a submodule and symlinks, but git keeps seeing the file as changed. Might add it to .gitignore, but it'd be a couple of steps to set it up. I was really hoping for a quick and simple solution. Seems that your option is the best one so far.Appoggiatura

© 2022 - 2024 — McMap. All rights reserved.