git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Feature Request: Support logic or shell execution to control values in .gitconfig
@ 2013-08-08 15:09 Morgan McClure
  2013-08-08 15:23 ` Matthieu Moy
  0 siblings, 1 reply; 4+ messages in thread
From: Morgan McClure @ 2013-08-08 15:09 UTC (permalink / raw)
  To: git

I sync all my dot files (including .gitconfig) among several machines
and it's currently not possible to put conditional logic in many
fields (any that aren't considered strings to be executed as shell
commands ie aliases, editor, etc).

My specific use case is the email address. Normally I want my email
address to read:
mcclurem@$HOSTNAME  <mcclure.morgan@gmail.com>

I use this to track which machine I'm committing from etc.

I propose using something reminiscent of bash syntax, either:
value = $(SOMETEXTTOEXECUTE)

or

value = `SOMETEXTTOEXECUTE`

Is this a feature others could get behind?

-Morgan McClure

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Feature Request: Support logic or shell execution to control values in .gitconfig
  2013-08-08 15:09 Feature Request: Support logic or shell execution to control values in .gitconfig Morgan McClure
@ 2013-08-08 15:23 ` Matthieu Moy
  2013-08-08 15:47   ` Greg Troxel
  2013-08-10 20:19   ` Jonathan Nieder
  0 siblings, 2 replies; 4+ messages in thread
From: Matthieu Moy @ 2013-08-08 15:23 UTC (permalink / raw)
  To: Morgan McClure; +Cc: git

Morgan McClure <mcclure.morgan@gmail.com> writes:

> I propose using something reminiscent of bash syntax, either:
> value = $(SOMETEXTTOEXECUTE)
>
> or
>
> value = `SOMETEXTTOEXECUTE`

That would mean executing SOMETEXTTOEXECUTE each time the config file is
read. This raises two issues:

* A security issue, as SOMETEXTTOEXECUTE could also be something
  dangerous. It would not be much worse than the current situation (if
  your config file is not trusted, then an attacker could put malicious
  code in core.editor for example), but still increase the security
  risk (as any command reading the config may trigger execution).

* A performance issue with the current git implementation, as the config
  file may be read many time for a single git execution.

> Is this a feature others could get behind?

I think it's unlikely that this ever be implemented. What I suggest
instead is to edit/track/share template configuration files like

~/.gitconfig.in
email = me@HOSTNAME@

and then script something like sed -e "s/@HOSTNAME@/$(hostname)/" <
~/.gitconfig.in > ~/.gitconfig.

You may also use the include.path functionality to share most of your
configuration, and include a small file which is different on each host.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Feature Request: Support logic or shell execution to control values in .gitconfig
  2013-08-08 15:23 ` Matthieu Moy
@ 2013-08-08 15:47   ` Greg Troxel
  2013-08-10 20:19   ` Jonathan Nieder
  1 sibling, 0 replies; 4+ messages in thread
From: Greg Troxel @ 2013-08-08 15:47 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Morgan McClure, git

[-- Attachment #1: Type: text/plain, Size: 1075 bytes --]


Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> What I suggest instead is to edit/track/share template configuration
> files like
>
> ~/.gitconfig.in
> email = me@HOSTNAME@
>
> and then script something like sed -e "s/@HOSTNAME@/$(hostname)/" <
> ~/.gitconfig.in > ~/.gitconfig.
>
> You may also use the include.path functionality to share most of your
> configuration, and include a small file which is different on each host.

For what it's worth, I

  keep dotfiles checked in as m4 sources, which is more or less
  equivalent to Matthieu's suggestion of sed

  don't try to keep .gitconfig under source control, but instead have a
  "git-config" alias that executes a lot of "git config --global"
  commands.

The downsides to the git-config shell function approach are:

  unwanted configurations are not removed

  one has to source (e.g.) .bash_aliases and then rerun git-config after
  updating the dotfile repo,


I suspect what's really needed is some sort of two-way macro
preprocessor that can take changes in an output file an back them into
the source.

[-- Attachment #2: Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Feature Request: Support logic or shell execution to control values in .gitconfig
  2013-08-08 15:23 ` Matthieu Moy
  2013-08-08 15:47   ` Greg Troxel
@ 2013-08-10 20:19   ` Jonathan Nieder
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Nieder @ 2013-08-10 20:19 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Morgan McClure, git

Matthieu Moy wrote:

> That would mean executing SOMETEXTTOEXECUTE each time the config file is
> read. This raises two issues:
>
> * A security issue, as SOMETEXTTOEXECUTE could also be something
>   dangerous. It would not be much worse than the current situation (if
>   your config file is not trusted, then an attacker could put malicious
>   code in core.editor for example), but still increase the security
>   risk (as any command reading the config may trigger execution).

I don't think the security issue is too bad.  As you say, the
combination of control over core.pager and pager.config is already
pretty dangerous.

> * A performance issue with the current git implementation, as the config
>   file may be read many time for a single git execution.

This issue is harder.

>> Is this a feature others could get behind?
>
> I think it's unlikely that this ever be implemented. What I suggest
> instead is to edit/track/share template configuration files like
>
> ~/.gitconfig.in
> email = me@HOSTNAME@
>
> and then script something like sed -e "s/@HOSTNAME@/$(hostname)/" <
> ~/.gitconfig.in > ~/.gitconfig.

Yeah, substitution scripts like this are probably the simplest way to
go.  Maybe some day it will make sense for commands to check the
timestamp or checksum of <foo>.in to automatically regenerate <foo> on
the fly when <foo>.in and other inputs change, but that sounds like
more complication than it's worth for git to take on.

Other alternatives might be to do that on the filesystem level (a FUSE
filesystem or Hurd-style translator generating determining the read(2)
result for <foo> on the fly), the editor level (vi knowing to
regenerate <foo> when you save <foo>.in), or the session management
level (bash via ~/.profile or ~/.bashrc or pam-login regenerating
<foo> at the start of each interactive session).

I wish there were an standard way to deal with such tasks instead of
running an update script manually, but now I'm getting off topic.

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-08-10 20:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-08 15:09 Feature Request: Support logic or shell execution to control values in .gitconfig Morgan McClure
2013-08-08 15:23 ` Matthieu Moy
2013-08-08 15:47   ` Greg Troxel
2013-08-10 20:19   ` Jonathan Nieder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).