{"thread":{"id":"34641","subject":"Feature Request: Support logic or shell execution to control values in .gitconfig","startedAt":"2013-08-08T15:09:22Z","lastAt":"2013-08-10T20:19:32Z","messageCount":4,"participants":["Morgan McClure","Matthieu Moy","Greg Troxel","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"224818","messageId":"CANY-LFJZazieg-7gLq1=pv=nkED81Gck4=95ffgZ6tGVgX5ffg@mail.gmail.com","threadId":"34641","inReplyTo":null,"subject":"Feature Request: Support logic or shell execution to control values in .gitconfig","fromName":"Morgan McClure","fromEmail":"mcclure.morgan@gmail.com","sentAt":"2013-08-08T15:09:22Z","receivedAt":"2013-08-08T15:09:22Z","isPatch":false,"sender":{"key":"mcclure.morgan@gmail.com","avatar":null},"body":"I sync all my dot files (including .gitconfig) among several machines\nand it's currently not possible to put conditional logic in many\nfields (any that aren't considered strings to be executed as shell\ncommands ie aliases, editor, etc).\n\nMy specific use case is the email address. Normally I want my email\naddress to read:\nmcclurem@$HOSTNAME  <mcclure.morgan@gmail.com>\n\nI use this to track which machine I'm committing from etc.\n\nI propose using something reminiscent of bash syntax, either:\nvalue = $(SOMETEXTTOEXECUTE)\n\nor\n\nvalue = `SOMETEXTTOEXECUTE`\n\nIs this a feature others could get behind?\n\n-Morgan McClure\n"},{"id":"224820","messageId":"vpq1u64dx63.fsf@anie.imag.fr","threadId":"34641","inReplyTo":"CANY-LFJZazieg-7gLq1=pv=nkED81Gck4=95ffgZ6tGVgX5ffg@mail.gmail.com","subject":"Re: Feature Request: Support logic or shell execution to control values in .gitconfig","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-08-08T15:23:00Z","receivedAt":"2013-08-08T15:23:00Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Morgan McClure <mcclure.morgan@gmail.com> writes:\n\n> I propose using something reminiscent of bash syntax, either:\n> value = $(SOMETEXTTOEXECUTE)\n>\n> or\n>\n> value = `SOMETEXTTOEXECUTE`\n\nThat would mean executing SOMETEXTTOEXECUTE each time the config file is\nread. This raises two issues:\n\n* A security issue, as SOMETEXTTOEXECUTE could also be something\n  dangerous. It would not be much worse than the current situation (if\n  your config file is not trusted, then an attacker could put malicious\n  code in core.editor for example), but still increase the security\n  risk (as any command reading the config may trigger execution).\n\n* A performance issue with the current git implementation, as the config\n  file may be read many time for a single git execution.\n\n> Is this a feature others could get behind?\n\nI think it's unlikely that this ever be implemented. What I suggest\ninstead is to edit/track/share template configuration files like\n\n~/.gitconfig.in\nemail = me@HOSTNAME@\n\nand then script something like sed -e \"s/@HOSTNAME@/$(hostname)/\" <\n~/.gitconfig.in > ~/.gitconfig.\n\nYou may also use the include.path functionality to share most of your\nconfiguration, and include a small file which is different on each host.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"224823","messageId":"rmieha46v6b.fsf@fnord.ir.bbn.com","threadId":"34641","inReplyTo":"vpq1u64dx63.fsf@anie.imag.fr","subject":"Re: Feature Request: Support logic or shell execution to control values in .gitconfig","fromName":"Greg Troxel","fromEmail":"gdt@ir.bbn.com","sentAt":"2013-08-08T15:47:56Z","receivedAt":"2013-08-08T15:47:56Z","isPatch":false,"sender":{"key":"gdt@ir.bbn.com","avatar":null},"body":"\nMatthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:\n\n> What I suggest instead is to edit/track/share template configuration\n> files like\n>\n> ~/.gitconfig.in\n> email = me@HOSTNAME@\n>\n> and then script something like sed -e \"s/@HOSTNAME@/$(hostname)/\" <\n> ~/.gitconfig.in > ~/.gitconfig.\n>\n> You may also use the include.path functionality to share most of your\n> configuration, and include a small file which is different on each host.\n\nFor what it's worth, I\n\n  keep dotfiles checked in as m4 sources, which is more or less\n  equivalent to Matthieu's suggestion of sed\n\n  don't try to keep .gitconfig under source control, but instead have a\n  \"git-config\" alias that executes a lot of \"git config --global\"\n  commands.\n\nThe downsides to the git-config shell function approach are:\n\n  unwanted configurations are not removed\n\n  one has to source (e.g.) .bash_aliases and then rerun git-config after\n  updating the dotfile repo,\n\n\nI suspect what's really needed is some sort of two-way macro\npreprocessor that can take changes in an output file an back them into\nthe source.\n"},{"id":"225033","messageId":"20130810201932.GA3031@elie.Belkin","threadId":"34641","inReplyTo":"vpq1u64dx63.fsf@anie.imag.fr","subject":"Re: Feature Request: Support logic or shell execution to control values in .gitconfig","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-08-10T20:19:32Z","receivedAt":"2013-08-10T20:19:32Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Matthieu Moy wrote:\n\n> That would mean executing SOMETEXTTOEXECUTE each time the config file is\n> read. This raises two issues:\n>\n> * A security issue, as SOMETEXTTOEXECUTE could also be something\n>   dangerous. It would not be much worse than the current situation (if\n>   your config file is not trusted, then an attacker could put malicious\n>   code in core.editor for example), but still increase the security\n>   risk (as any command reading the config may trigger execution).\n\nI don't think the security issue is too bad.  As you say, the\ncombination of control over core.pager and pager.config is already\npretty dangerous.\n\n> * A performance issue with the current git implementation, as the config\n>   file may be read many time for a single git execution.\n\nThis issue is harder.\n\n>> Is this a feature others could get behind?\n>\n> I think it's unlikely that this ever be implemented. What I suggest\n> instead is to edit/track/share template configuration files like\n>\n> ~/.gitconfig.in\n> email = me@HOSTNAME@\n>\n> and then script something like sed -e \"s/@HOSTNAME@/$(hostname)/\" <\n> ~/.gitconfig.in > ~/.gitconfig.\n\nYeah, substitution scripts like this are probably the simplest way to\ngo.  Maybe some day it will make sense for commands to check the\ntimestamp or checksum of <foo>.in to automatically regenerate <foo> on\nthe fly when <foo>.in and other inputs change, but that sounds like\nmore complication than it's worth for git to take on.\n\nOther alternatives might be to do that on the filesystem level (a FUSE\nfilesystem or Hurd-style translator generating determining the read(2)\nresult for <foo> on the fly), the editor level (vi knowing to\nregenerate <foo> when you save <foo>.in), or the session management\nlevel (bash via ~/.profile or ~/.bashrc or pam-login regenerating\n<foo> at the start of each interactive session).\n\nI wish there were an standard way to deal with such tasks instead of\nrunning an update script manually, but now I'm getting off topic.\n\nThanks,\nJonathan\n"}]}