{"thread":{"id":"45421","subject":"Is there a way to have a local version of a header file?","startedAt":"2017-03-18T14:30:18Z","lastAt":"2017-03-19T21:33:42Z","messageCount":11,"participants":["David Lang","Ævar Arnfjörð Bjarmason","Junio C Hamano","Jakub Narębski","Samuel Lijin","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"314499","messageId":"nycvar.QRO.7.75.62.1703180724490.3797@qynat-yncgbc","threadId":"45421","inReplyTo":null,"subject":"Is there a way to have a local version of a header file?","fromName":"David Lang","fromEmail":"david@lang.hm","sentAt":"2017-03-18T14:29:50Z","receivedAt":"2017-03-18T14:30:18Z","isPatch":false,"sender":{"key":"david@lang.hm","avatar":null},"body":"for an embedded project built inside the Arduino IDE, (alternate firmware for a \nhome automation project) there is a need to set a number of parameters that we \nreally don't want in the main repo (wifi network IDs/passwords)\n\nright now, we have these things set as #defines in a header file.\n\nWe need to distribute a base version of this file for new people to get started.\n\nIs there any way to have git define a file in such a way that if it doesn't \nexist in the worktree it gets populated, but if it does exist it doesn't get \noverwritten? (as I type this, I'm thinking a trigger may work, but we need it to \nwork on Linux, Windows and OSX)\n\nAny thoughts on a sane way to handle this situation?\n\nDavid Lang\n"},{"id":"314500","messageId":"CACBZZX5FMdjuxxNru+XfTQdSXEQ_b0OP2rngGZLf1sSHR_D8Ng@mail.gmail.com","threadId":"45421","inReplyTo":"nycvar.QRO.7.75.62.1703180724490.3797@qynat-yncgbc","subject":"Re: Is there a way to have a local version of a header file?","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-03-18T14:48:25Z","receivedAt":"2017-03-18T14:48:59Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Mar 18, 2017 at 3:29 PM, David Lang <david@lang.hm> wrote:\n> for an embedded project built inside the Arduino IDE, (alternate firmware\n> for a home automation project) there is a need to set a number of parameters\n> that we really don't want in the main repo (wifi network IDs/passwords)\n>\n> right now, we have these things set as #defines in a header file.\n>\n> We need to distribute a base version of this file for new people to get\n> started.\n>\n> Is there any way to have git define a file in such a way that if it doesn't\n> exist in the worktree it gets populated, but if it does exist it doesn't get\n> overwritten? (as I type this, I'm thinking a trigger may work, but we need\n> it to work on Linux, Windows and OSX)\n>\n> Any thoughts on a sane way to handle this situation?\n\nThere's no sane way to do what you're describing without renaming the file.\n\nBut the sanest way to do this is to have a config.h.example\n\nThen you have \"/config.h\" in the .gitignore file.\n\nAnd you tell the users to copy the *.example file to *.h, and your\nprogram then includes the *.h file.\n\nIf you wanted to provide defaults you could just #include the\nconfig.h.example first, so #defines in the *.h file would clobber\nthose in the *.example.\n"},{"id":"314501","messageId":"nycvar.QRO.7.75.62.1703180750460.3797@qynat-yncgbc","threadId":"45421","inReplyTo":"CACBZZX5FMdjuxxNru+XfTQdSXEQ_b0OP2rngGZLf1sSHR_D8Ng@mail.gmail.com","subject":"Re: Is there a way to have a local version of a header file?","fromName":"David Lang","fromEmail":"david@lang.hm","sentAt":"2017-03-18T14:58:14Z","receivedAt":"2017-03-18T15:10:00Z","isPatch":false,"sender":{"key":"david@lang.hm","avatar":null},"body":"On Sat, 18 Mar 2017, Ævar Arnfjörð Bjarmason wrote:\n\n> On Sat, Mar 18, 2017 at 3:29 PM, David Lang <david@lang.hm> wrote:\n>> for an embedded project built inside the Arduino IDE, (alternate firmware\n>> for a home automation project) there is a need to set a number of parameters\n>> that we really don't want in the main repo (wifi network IDs/passwords)\n>>\n>> right now, we have these things set as #defines in a header file.\n>>\n>> We need to distribute a base version of this file for new people to get\n>> started.\n>>\n>> Is there any way to have git define a file in such a way that if it doesn't\n>> exist in the worktree it gets populated, but if it does exist it doesn't get\n>> overwritten? (as I type this, I'm thinking a trigger may work, but we need\n>> it to work on Linux, Windows and OSX)\n>>\n>> Any thoughts on a sane way to handle this situation?\n>\n> There's no sane way to do what you're describing without renaming the file.\n>\n> But the sanest way to do this is to have a config.h.example\n>\n> Then you have \"/config.h\" in the .gitignore file.\n>\n> And you tell the users to copy the *.example file to *.h, and your\n> program then includes the *.h file.\n>\n> If you wanted to provide defaults you could just #include the\n> config.h.example first, so #defines in the *.h file would clobber\n> those in the *.example.\n\nThat's what we currently have (user_config.h and user_config_override.h)\n\nI was hoping to not have the situation where downloading and trying to compile \nwill complain about a missing include file (if the users don't copy \nuser_config_override_example.h to user_config_override.h) while letting us do a \n.gitignore on user_config_override.h\n\nfor many people using this project, this is the first time they have ever \ncompiled anything, and we have the typical set of people not reading \ninstructions :-/\n\nDarn, I was hoping that the scenario of needing to have a config file provided \nin the repo, while not overwriting local changes to it was common enough that \nthere were some tricks available. This is a little harder as the running code \ndoesn't have a filesystem so we are limited to what we can do in the compiler \nand git (no makefile even, the Arduino folks consider that too complicated, it \njust slurps up all .ino files in a directory and compiles them)\n"},{"id":"314507","messageId":"CACBZZX7G=C84kz4n26VTnWWUTKRv1rVvms=8AvELtMSCviu1kQ@mail.gmail.com","threadId":"45421","inReplyTo":"nycvar.QRO.7.75.62.1703180750460.3797@qynat-yncgbc","subject":"Re: Is there a way to have a local version of a header file?","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-03-18T17:08:27Z","receivedAt":"2017-03-18T17:08:52Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Mar 18, 2017 at 3:58 PM, David Lang <david@lang.hm> wrote:\n> On Sat, 18 Mar 2017, Ævar Arnfjörð Bjarmason wrote:\n>\n>> On Sat, Mar 18, 2017 at 3:29 PM, David Lang <david@lang.hm> wrote:\n>>>\n>>> for an embedded project built inside the Arduino IDE, (alternate firmware\n>>> for a home automation project) there is a need to set a number of\n>>> parameters\n>>> that we really don't want in the main repo (wifi network IDs/passwords)\n>>>\n>>> right now, we have these things set as #defines in a header file.\n>>>\n>>> We need to distribute a base version of this file for new people to get\n>>> started.\n>>>\n>>> Is there any way to have git define a file in such a way that if it\n>>> doesn't\n>>> exist in the worktree it gets populated, but if it does exist it doesn't\n>>> get\n>>> overwritten? (as I type this, I'm thinking a trigger may work, but we\n>>> need\n>>> it to work on Linux, Windows and OSX)\n>>>\n>>> Any thoughts on a sane way to handle this situation?\n>>\n>>\n>> There's no sane way to do what you're describing without renaming the\n>> file.\n>>\n>> But the sanest way to do this is to have a config.h.example\n>>\n>> Then you have \"/config.h\" in the .gitignore file.\n>>\n>> And you tell the users to copy the *.example file to *.h, and your\n>> program then includes the *.h file.\n>>\n>> If you wanted to provide defaults you could just #include the\n>> config.h.example first, so #defines in the *.h file would clobber\n>> those in the *.example.\n>\n>\n> That's what we currently have (user_config.h and user_config_override.h)\n>\n> I was hoping to not have the situation where downloading and trying to\n> compile will complain about a missing include file (if the users don't copy\n> user_config_override_example.h to user_config_override.h) while letting us\n> do a .gitignore on user_config_override.h\n>\n> for many people using this project, this is the first time they have ever\n> compiled anything, and we have the typical set of people not reading\n> instructions :-/\n>\n> Darn, I was hoping that the scenario of needing to have a config file\n> provided in the repo, while not overwriting local changes to it was common\n> enough that there were some tricks available. This is a little harder as the\n> running code doesn't have a filesystem so we are limited to what we can do\n> in the compiler and git (no makefile even, the Arduino folks consider that\n> too complicated, it just slurps up all .ino files in a directory and\n> compiles them)\n\nThere might be some way I haven't thought of, in particular maybe you\ncan use gitattributes to define a custom diff/merge driver that always\nreports no changes, or some ways to (ab)use the index to make git\nignore any changes to the file.\n"},{"id":"314517","messageId":"xmqqzigi31fl.fsf@gitster.mtv.corp.google.com","threadId":"45421","inReplyTo":"CACBZZX7G=C84kz4n26VTnWWUTKRv1rVvms=8AvELtMSCviu1kQ@mail.gmail.com","subject":"Re: Is there a way to have a local version of a header file?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-18T18:05:50Z","receivedAt":"2017-03-18T18:08:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n> There might be some way I haven't thought of, in particular maybe you\n> can use gitattributes to define a custom diff/merge driver that always\n> reports no changes, or some ways to (ab)use the index to make git\n> ignore any changes to the file.\n\nWhy does this have to be so difficult?\n\nShip a config.h.sample file, have a Makefile rule that is forced to\nrun before any compilation happens that checks if config.h exists\nand then created it if missing by copying config.h.sample over, and\nthen all other source files can include config.h without having to\nknow anything about config.h.sample's existence.\n\nDid I miss something?\n"},{"id":"314526","messageId":"35e8ef4e-9a72-28e5-6797-99ad639de591@gmail.com","threadId":"45421","inReplyTo":"CACBZZX7G=C84kz4n26VTnWWUTKRv1rVvms=8AvELtMSCviu1kQ@mail.gmail.com","subject":"Re: Is there a way to have a local version of a header file?","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2017-03-18T18:21:10Z","receivedAt":"2017-03-18T18:52:13Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"W dniu 18.03.2017 o 18:08, Ævar Arnfjörð Bjarmason pisze:\n\n> There might be some way I haven't thought of, in particular maybe you\n> can use gitattributes to define a custom diff/merge driver that always\n> reports no changes, or some ways to (ab)use the index to make git\n> ignore any changes to the file.\n\nThere is `git update-index --skip-worktree` (originally meant for\nsparse checkout), which you can use to kind of ignore changes to\ntracked file, in a safe way (though sometimes annoying, when it\nprevents stashing changes).\n\nThere is also an existing solution of a hook that prevents commiting\nfiles with passwords in them; I forgot the name...\n\nHTH,\n-- \nJakub Narębski\n\n"},{"id":"314567","messageId":"nycvar.QRO.7.75.62.1703181539310.3797@qynat-yncgbc","threadId":"45421","inReplyTo":"xmqqzigi31fl.fsf@gitster.mtv.corp.google.com","subject":"Re: Is there a way to have a local version of a header file?","fromName":"David Lang","fromEmail":"david@lang.hm","sentAt":"2017-03-18T22:40:08Z","receivedAt":"2017-03-18T22:41:57Z","isPatch":false,"sender":{"key":"david@lang.hm","avatar":null},"body":"On Sat, 18 Mar 2017, Junio C Hamano wrote:\n\n> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n>\n>> There might be some way I haven't thought of, in particular maybe you\n>> can use gitattributes to define a custom diff/merge driver that always\n>> reports no changes, or some ways to (ab)use the index to make git\n>> ignore any changes to the file.\n>\n> Why does this have to be so difficult?\n>\n> Ship a config.h.sample file, have a Makefile rule that is forced to\n> run before any compilation happens that checks if config.h exists\n> and then created it if missing by copying config.h.sample over, and\n> then all other source files can include config.h without having to\n> know anything about config.h.sample's existence.\n>\n> Did I miss something?\n\nThere is no makefile with the arduino IDE/build system :-(\n\nDavid Lang"},{"id":"314572","messageId":"xmqqy3w2yybt.fsf@gitster.mtv.corp.google.com","threadId":"45421","inReplyTo":"nycvar.QRO.7.75.62.1703181539310.3797@qynat-yncgbc","subject":"Re: Is there a way to have a local version of a header file?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-18T23:11:50Z","receivedAt":"2017-03-18T23:11:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Lang <david@lang.hm> writes:\n\n>> Ship a config.h.sample file, have a Makefile rule that is forced to\n>> run before any compilation happens that checks if config.h exists\n>> and then created it if missing by copying config.h.sample over, and\n>> then all other source files can include config.h without having to\n>> know anything about config.h.sample's existence.\n>>\n>> Did I miss something?\n>\n> There is no makefile with the arduino IDE/build system :-(\n\nHow does \"the build system\" you want to make it work with actually\nwork?  Is it incapable of \"compiling\" a \"source file\" into an\n\"object file\" that happens to be a text using an arbitrary\n\"compiler\"?\n\nI was hoping that readers are imaginative enough to replace Makefile\nwith whatever way things are normally built with when reading my\nmessage, and the reader can just replace \"source file\" with\n\"config.h.sample\", \"compiler\" with \"test -f config.h || cat\nconfig.h.sample >config.h\" and \"object file\" with \"config.h\".\n"},{"id":"314580","messageId":"CAJZjrdVxT7G+Cn+1_vqPBCtMOALmR_542jvP7nXXuvs74ko5qg@mail.gmail.com","threadId":"45421","inReplyTo":"xmqqy3w2yybt.fsf@gitster.mtv.corp.google.com","subject":"Re: Is there a way to have a local version of a header file?","fromName":"Samuel Lijin","fromEmail":"sxlijin@gmail.com","sentAt":"2017-03-18T23:22:32Z","receivedAt":"2017-03-18T23:30:34Z","isPatch":false,"sender":{"key":"sxlijin@gmail.com","avatar":"https://gravatar.com/avatar/01777bf1eae64e2b4dca97dcac182a6abbcf6fd8cb4d5b8fa33edf9f8cc21746?d=mp&s=160"},"body":"Arduino is basically a simplified/streamlined cross-compilation\ntoolchain with very tightly coupled IDE integration.\n\nI'd just provide a .sample and tell people what to do with it in the\nREADME. The alternative is to provide config.h as is and tell people\nto use \"git update-index --assume-unchanged\" immediately after cloning\nto ignore changes to the file, but this is prone to people\naccidentally committing credentials.\n\nOn Sat, Mar 18, 2017 at 6:11 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> David Lang <david@lang.hm> writes:\n>\n>>> Ship a config.h.sample file, have a Makefile rule that is forced to\n>>> run before any compilation happens that checks if config.h exists\n>>> and then created it if missing by copying config.h.sample over, and\n>>> then all other source files can include config.h without having to\n>>> know anything about config.h.sample's existence.\n>>>\n>>> Did I miss something?\n>>\n>> There is no makefile with the arduino IDE/build system :-(\n>\n> How does \"the build system\" you want to make it work with actually\n> work?  Is it incapable of \"compiling\" a \"source file\" into an\n> \"object file\" that happens to be a text using an arbitrary\n> \"compiler\"?\n>\n> I was hoping that readers are imaginative enough to replace Makefile\n> with whatever way things are normally built with when reading my\n> message, and the reader can just replace \"source file\" with\n> \"config.h.sample\", \"compiler\" with \"test -f config.h || cat\n> config.h.sample >config.h\" and \"object file\" with \"config.h\".\n"},{"id":"314581","messageId":"nycvar.QRO.7.75.62.1703181712100.3797@qynat-yncgbc","threadId":"45421","inReplyTo":"xmqqy3w2yybt.fsf@gitster.mtv.corp.google.com","subject":"Re: Is there a way to have a local version of a header file?","fromName":"David Lang","fromEmail":"david@lang.hm","sentAt":"2017-03-19T00:19:36Z","receivedAt":"2017-03-19T00:20:22Z","isPatch":false,"sender":{"key":"david@lang.hm","avatar":null},"body":"On Sat, 18 Mar 2017, Junio C Hamano wrote:\n\n> David Lang <david@lang.hm> writes:\n>\n>>> Ship a config.h.sample file, have a Makefile rule that is forced to\n>>> run before any compilation happens that checks if config.h exists\n>>> and then created it if missing by copying config.h.sample over, and\n>>> then all other source files can include config.h without having to\n>>> know anything about config.h.sample's existence.\n>>>\n>>> Did I miss something?\n>>\n>> There is no makefile with the arduino IDE/build system :-(\n>\n> How does \"the build system\" you want to make it work with actually\n> work?  Is it incapable of \"compiling\" a \"source file\" into an\n> \"object file\" that happens to be a text using an arbitrary\n> \"compiler\"?\n\nIt looks for all *.ino files (which need to contain C code) in the specified \n(\"project\") directory and compiles and links them all into one blob, it adds a \nsmidge of code at the beginning to run setup() followed by loop(). It then dumps \nthis blob (via serial/USB) into the flash of the device that will run it.\n\nit's a very dumbed down system, designed for non-programmers to do trivial \nthings (blink a few LEDs, etc) that's been pushed to far more sophisticated uses \nthan it was ever designed for.\n\nDavid Lang\n\n> I was hoping that readers are imaginative enough to replace Makefile\n> with whatever way things are normally built with when reading my\n> message, and the reader can just replace \"source file\" with\n> \"config.h.sample\", \"compiler\" with \"test -f config.h || cat\n> config.h.sample >config.h\" and \"object file\" with \"config.h\".\n>\n"},{"id":"314612","messageId":"5d06ba31-bec1-0172-cb00-10b4d2c4e648@kdbg.org","threadId":"45421","inReplyTo":"CAJZjrdVxT7G+Cn+1_vqPBCtMOALmR_542jvP7nXXuvs74ko5qg@mail.gmail.com","subject":"Re: Is there a way to have a local version of a header file?","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2017-03-19T21:33:33Z","receivedAt":"2017-03-19T21:33:42Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 19.03.2017 um 00:22 schrieb Samuel Lijin:\n> I'd just provide a .sample and tell people what to do with it in the\n> README. The alternative is to provide config.h as is and tell people\n> to use \"git update-index --assume-unchanged\" immediately after cloning\n> to ignore changes to the file, but this is prone to people\n> accidentally committing credentials.\n\nPlease do not suggest to use --assume-unchanged. It is not intended for \nthis purpose, and if used in the way you suggest, it will sooner or \nlater bite back.\n\n--assume-unchanged is a promise to Git that you do not change the file. \nIf you break the promise, you get what you deserve ;)\n\n-- Hannes\n\n"}]}