git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Is there a way to have a local version of a header file?

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 18, 2017, 17:08 UTC
Message-ID
<CACBZZX7G=C84kz4n26VTnWWUTKRv1rVvms=8AvELtMSCviu1kQ@mail.gmail.com>
In-Reply-To
<nycvar.QRO.7.75.62.1703180750460.3797@qynat-yncgbc>
On Sat, Mar 18, 2017 at 3:58 PM, David Lang <david@lang.hm> wrote:
Show 58 quoted lines
> On Sat, 18 Mar 2017, Ævar Arnfjörð Bjarmason wrote:
>
>> On Sat, Mar 18, 2017 at 3:29 PM, David Lang <david@lang.hm> wrote:
>>>
>>> for an embedded project built inside the Arduino IDE, (alternate firmware
>>> for a home automation project) there is a need to set a number of
>>> parameters
>>> that we really don't want in the main repo (wifi network IDs/passwords)
>>>
>>> right now, we have these things set as #defines in a header file.
>>>
>>> We need to distribute a base version of this file for new people to get
>>> started.
>>>
>>> Is there any way to have git define a file in such a way that if it
>>> doesn't
>>> exist in the worktree it gets populated, but if it does exist it doesn't
>>> get
>>> overwritten? (as I type this, I'm thinking a trigger may work, but we
>>> need
>>> it to work on Linux, Windows and OSX)
>>>
>>> Any thoughts on a sane way to handle this situation?
>>
>>
>> There's no sane way to do what you're describing without renaming the
>> file.
>>
>> But the sanest way to do this is to have a config.h.example
>>
>> Then you have "/config.h" in the .gitignore file.
>>
>> And you tell the users to copy the *.example file to *.h, and your
>> program then includes the *.h file.
>>
>> If you wanted to provide defaults you could just #include the
>> config.h.example first, so #defines in the *.h file would clobber
>> those in the *.example.
>
>
> That's what we currently have (user_config.h and user_config_override.h)
>
> I was hoping to not have the situation where downloading and trying to
> compile will complain about a missing include file (if the users don't copy
> user_config_override_example.h to user_config_override.h) while letting us
> do a .gitignore on user_config_override.h
>
> for many people using this project, this is the first time they have ever
> compiled anything, and we have the typical set of people not reading
> instructions :-/
>
> Darn, I was hoping that the scenario of needing to have a config file
> provided in the repo, while not overwriting local changes to it was common
> enough that there were some tricks available. This is a little harder as the
> running code doesn't have a filesystem so we are limited to what we can do
> in the compiler and git (no makefile even, the Arduino folks consider that
> too complicated, it just slurps up all .ino files in a directory and
> compiles them)

There might be some way I haven't thought of, in particular maybe you can use gitattributes to define a custom diff/merge driver that always reports no changes, or some ways to (ab)use the index to make git ignore any changes to the file.

Previous: David LangNext: Junio C Hamano
Message 4 of 11 in “Is there a way to have a local version of a header file?”
  1. David LangMar 18, 2017
  2. Ævar Arnfjörð BjarmasonMar 18, 2017
  3. David LangMar 18, 2017
  4. Ævar Arnfjörð BjarmasonMar 18, 2017
  5. Junio C HamanoMar 18, 2017
  6. David LangMar 18, 2017
  7. Junio C HamanoMar 18, 2017
  8. Samuel LijinMar 18, 2017
  9. Johannes SixtMar 19, 2017
  10. David LangMar 19, 2017
  11. Jakub NarębskiMar 18, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.