Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track config files of submodules in Git?

In Git, how can I organize work to track local config files of a library, which is a git submodule?

In details:

the library has normal files that are tracked, and default config files that are in it's folder, but not tracked, in order to avoid resetting or overwriting them (they're listed in .gitignore). All the files are in lib's folder or subfolders.

I started tracking one of the projects, that use this lib, in Git too. Now there's a dilemma:

  • if I make the lib in this project a submodule, I won't be able to track the config files (Git will ignore them, since they're in the submodule folder).

  • tracking everything as a big project is a bad idea, as I understand.

  • if I do track config files in the library, how can I avoid resetting them to default values? Do I make a branch in the working project and pull from master every time? Then, what if I edit the library and a config file in it? This must cause a merge conflict, doesn't it?

I guess this is not new, but I couldn't find any advice. I'll appreciate learning from your experience guys.

like image 862
culebrón Avatar asked Sep 15 '09 19:09

culebrón


People also ask

How do I manage git submodules?

Use the git submodule update command to set the submodules to the commit specified by the main repository. This means that if you pull in new changes into the submodules, you need to create a new commit in your main repository in order to track the updates of the nested submodules.

Where is git submodule hash stored?

It is stored in Git's object database directly.

Where is my .gitmodules file?

The . gitmodules file, located in the top-level directory of a Git working tree, is a text file with a syntax matching the requirements of git-config[1].

What recurse submodules?

If you pass --recurse-submodules to the git clone command, it will automatically initialize and update each submodule in the repository, including nested submodules if any of the submodules in the repository have submodules themselves.


2 Answers

When using a submodule, you should avoid making any modification because of the container (here: the project using the lib), because it will create a new revision on the history of the submodule.

It would be possible, for instance, for the lib, to reference config template files that can be the base for :

  • default value config files generation (the lib has a default value file archived, which can be used to generate a complete but not tracked config file)
  • or a custom config file generation (the project has its own config file values, and use it to generate at the same place within the lib a non-tracked config file)

A "config file template with tokenized values in it, and a script transforming that config.template file into a private (and ignored) config file" is the approach I suggested in this SO question about merge management.

Other more general advices on config files can be found in this SO question.

like image 153
VonC Avatar answered Oct 17 '22 03:10

VonC


track your config file in main project directory and put a symlink into library subdirectory?

git add lib.conf
ln -s ../lib.conf lib/

or do I miss something?

like image 36
Michael Krelin - hacker Avatar answered Oct 17 '22 05:10

Michael Krelin - hacker