git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* RFE: version-controlled merge rules
@ 2018-12-27 20:16 H. Peter Anvin
  2018-12-27 23:55 ` Jonathan Nieder
  2018-12-28  8:42 ` Ævar Arnfjörð Bjarmason
  0 siblings, 2 replies; 7+ messages in thread
From: H. Peter Anvin @ 2018-12-27 20:16 UTC (permalink / raw)
  To: git

Right now, merge rules can get selected in .gitattributes, which is
version-controlled. However, there does not appear to be any way to *define*
custom merge rules which is version controlled.

There are a lot of different files which can benefit from custom merge rules,
especially ones that are in some ways cumulative or version/tree-dependent.
For example, I use this rule to merge version files:

[merge "version"]
        name = Version file merge driver
        driver = sort -V -r %O %A %B | head -1 > %A.tmp.1 && mv -f %A.tmp.1 %A

(Incidentally: the need for an explicit temp file here is frustrating. It
would be better if git could manage the temporary file. Overwriting %A
directly truncates the file too early.  See other email.)

However, I can't even put this in .gitattributes, because doing so would break
any user who *doesn't* have the previous rule defined locally. Even worse, if
this rule needs to change, propagating it to all new users has to be done
manually... never mind if it needs to vary by branch!

The simplest way to address this would presumably be to let the
repository/working directory contain a .gitconfig file that can contain rules
like that.  (Allowing it to be in the repository proper is probably a
requirement for merges to be handled correctly on bare repositories; I'm not
sure how .gitattributes is handled for that.)

	-hpa

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

* Re: RFE: version-controlled merge rules
  2018-12-27 20:16 RFE: version-controlled merge rules H. Peter Anvin
@ 2018-12-27 23:55 ` Jonathan Nieder
  2018-12-28  4:48   ` H. Peter Anvin
  2018-12-28 14:35   ` Junio C Hamano
  2018-12-28  8:42 ` Ævar Arnfjörð Bjarmason
  1 sibling, 2 replies; 7+ messages in thread
From: Jonathan Nieder @ 2018-12-27 23:55 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: git

Hi,

H. Peter Anvin wrote:

> [merge "version"]
>         name = Version file merge driver
>         driver = sort -V -r %O %A %B | head -1 > %A.tmp.1 && mv -f %A.tmp.1 %A
[...]
> However, I can't even put this in .gitattributes, because doing so would break
> any user who *doesn't* have the previous rule defined locally. Even worse, if
> this rule needs to change, propagating it to all new users has to be done
> manually... never mind if it needs to vary by branch!
>
> The simplest way to address this would presumably be to let the
> repository/working directory contain a .gitconfig file that can contain rules
> like that.  (Allowing it to be in the repository proper is probably a
> requirement for merges to be handled correctly on bare repositories; I'm not
> sure how .gitattributes is handled for that.)

The main issue I see is that this would make it a little *too* easy to
run arbitrary code on the user's machine.  Build systems often already
lead to that, but users are more familiar with the risks for build
than for version control.

See [1] for some related discussion.

That said, using the include.path feature (see git-config(1)), it's
possible to do something similar:

	[include]
		path = ../.gitconfig

Thanks and hope that helps,
Jonathan

[1] https://public-inbox.org/git/20171002234517.GV19555@aiede.mtv.corp.google.com/

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

* Re: RFE: version-controlled merge rules
  2018-12-27 23:55 ` Jonathan Nieder
@ 2018-12-28  4:48   ` H. Peter Anvin
  2018-12-28 16:03     ` Duy Nguyen
  2018-12-28 14:35   ` Junio C Hamano
  1 sibling, 1 reply; 7+ messages in thread
From: H. Peter Anvin @ 2018-12-28  4:48 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: git

On 12/27/18 3:55 PM, Jonathan Nieder wrote:
> Hi,
> 
> H. Peter Anvin wrote:
> 
>> [merge "version"]
>>         name = Version file merge driver
>>         driver = sort -V -r %O %A %B | head -1 > %A.tmp.1 && mv -f %A.tmp.1 %A
> [...]
>> However, I can't even put this in .gitattributes, because doing so would break
>> any user who *doesn't* have the previous rule defined locally. Even worse, if
>> this rule needs to change, propagating it to all new users has to be done
>> manually... never mind if it needs to vary by branch!
>>
>> The simplest way to address this would presumably be to let the
>> repository/working directory contain a .gitconfig file that can contain rules
>> like that.  (Allowing it to be in the repository proper is probably a
>> requirement for merges to be handled correctly on bare repositories; I'm not
>> sure how .gitattributes is handled for that.)
> 
> The main issue I see is that this would make it a little *too* easy to
> run arbitrary code on the user's machine.  Build systems often already
> lead to that, but users are more familiar with the risks for build
> than for version control.
> 
> See [1] for some related discussion.
> 
> That said, using the include.path feature (see git-config(1)), it's
> possible to do something similar:
> 
> 	[include]
> 		path = ../.gitconfig
> 
> Thanks and hope that helps,
> Jonathan
> 

That would be great, except that it doesn't work if the worktree isn't in
"..".  This is one of many cases where it would be great to have environment
variable interpolation.

	-hpa


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

* Re: RFE: version-controlled merge rules
  2018-12-27 20:16 RFE: version-controlled merge rules H. Peter Anvin
  2018-12-27 23:55 ` Jonathan Nieder
@ 2018-12-28  8:42 ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 7+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-12-28  8:42 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: git


On Thu, Dec 27 2018, H. Peter Anvin wrote:

> Right now, merge rules can get selected in .gitattributes, which is
> version-controlled. However, there does not appear to be any way to *define*
> custom merge rules which is version controlled.
>
> There are a lot of different files which can benefit from custom merge rules,
> especially ones that are in some ways cumulative or version/tree-dependent.
> For example, I use this rule to merge version files:
>
> [merge "version"]
>         name = Version file merge driver
>         driver = sort -V -r %O %A %B | head -1 > %A.tmp.1 && mv -f %A.tmp.1 %A
>
> (Incidentally: the need for an explicit temp file here is frustrating. It
> would be better if git could manage the temporary file. Overwriting %A
> directly truncates the file too early.  See other email.)
>
> However, I can't even put this in .gitattributes, because doing so would break
> any user who *doesn't* have the previous rule defined locally. Even worse, if
> this rule needs to change, propagating it to all new users has to be done
> manually... never mind if it needs to vary by branch!
>
> The simplest way to address this would presumably be to let the
> repository/working directory contain a .gitconfig file that can contain rules
> like that.  (Allowing it to be in the repository proper is probably a
> requirement for merges to be handled correctly on bare repositories; I'm not
> sure how .gitattributes is handled for that.)

This would fall under the general umbrella of allowing repos to set
configuration, see
https://public-inbox.org/git/?q=87zi6eakkt.fsf%40evledraar.gmail.com for
some previous discussion.

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

* Re: RFE: version-controlled merge rules
  2018-12-27 23:55 ` Jonathan Nieder
  2018-12-28  4:48   ` H. Peter Anvin
@ 2018-12-28 14:35   ` Junio C Hamano
  2018-12-29  9:14     ` hpa
  1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2018-12-28 14:35 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: H. Peter Anvin, git

Jonathan Nieder <jrnieder@gmail.com> writes:

> The main issue I see is that this would make it a little *too* easy to
> run arbitrary code on the user's machine.  Build systems often already
> lead to that, but users are more familiar with the risks for build
> than for version control.
>
> See [1] for some related discussion.
>
> That said, using the include.path feature (see git-config(1)), it's
> possible to do something similar:
>
> 	[include]
> 		path = ../.gitconfig
>
> Thanks and hope that helps,

The issue the arrangement to specify what kind of files they are in
the attribute system and to specify what exact commands to be run in
the configuration addresses is twofold.  The security issue is one
and poking a hole with include.path mechanism is probably OK as
there is end-user consent, but I tend to agree that a similar risk
already exists by a project shipping Makefile et al.

There is the other side of the issue.

The arrangement allows project not to be monoculture by leaving the
exact command sequence to use on the kind of files (specified by the
project with the attribute system) up to the end-user in their
configuration.  While Peter may feel that sort piped to head may be
available on all the reasonable UNIX systems, his merge driver would
not work on other platforms.  There already is a similar reliance of
monoculture by a project shipping Makefile et al, which is an
interesting parallel.

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

* Re: RFE: version-controlled merge rules
  2018-12-28  4:48   ` H. Peter Anvin
@ 2018-12-28 16:03     ` Duy Nguyen
  0 siblings, 0 replies; 7+ messages in thread
From: Duy Nguyen @ 2018-12-28 16:03 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Jonathan Nieder, Git Mailing List

On Fri, Dec 28, 2018 at 4:46 PM H. Peter Anvin <hpa@zytor.com> wrote:
>
> On 12/27/18 3:55 PM, Jonathan Nieder wrote:
> > Hi,
> >
> > H. Peter Anvin wrote:
> >
> >> [merge "version"]
> >>         name = Version file merge driver
> >>         driver = sort -V -r %O %A %B | head -1 > %A.tmp.1 && mv -f %A.tmp.1 %A
> > [...]
> >> However, I can't even put this in .gitattributes, because doing so would break
> >> any user who *doesn't* have the previous rule defined locally. Even worse, if
> >> this rule needs to change, propagating it to all new users has to be done
> >> manually... never mind if it needs to vary by branch!
> >>
> >> The simplest way to address this would presumably be to let the
> >> repository/working directory contain a .gitconfig file that can contain rules
> >> like that.  (Allowing it to be in the repository proper is probably a
> >> requirement for merges to be handled correctly on bare repositories; I'm not
> >> sure how .gitattributes is handled for that.)
> >
> > The main issue I see is that this would make it a little *too* easy to
> > run arbitrary code on the user's machine.  Build systems often already
> > lead to that, but users are more familiar with the risks for build
> > than for version control.
> >
> > See [1] for some related discussion.
> >
> > That said, using the include.path feature (see git-config(1)), it's
> > possible to do something similar:
> >
> >       [include]
> >               path = ../.gitconfig
> >
> > Thanks and hope that helps,
> > Jonathan
> >
>
> That would be great, except that it doesn't work if the worktree isn't in
> "..".  This is one of many cases where it would be great to have environment
> variable interpolation.

It's been discussed, see [1] and others in the same thread. The
feeling I got was it seemed good idea, but we're just not sure about
the exact syntax and some corner cases, and most importantly nobody
has stepped up to implement it.

[1] https://public-inbox.org/git/20181109101918.GC7410@sigill.intra.peff.net/
-- 
Duy

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

* Re: RFE: version-controlled merge rules
  2018-12-28 14:35   ` Junio C Hamano
@ 2018-12-29  9:14     ` hpa
  0 siblings, 0 replies; 7+ messages in thread
From: hpa @ 2018-12-29  9:14 UTC (permalink / raw)
  To: Junio C Hamano, Jonathan Nieder; +Cc: git

On December 28, 2018 6:35:23 AM PST, Junio C Hamano <gitster@pobox.com> wrote:
>Jonathan Nieder <jrnieder@gmail.com> writes:
>
>> The main issue I see is that this would make it a little *too* easy
>to
>> run arbitrary code on the user's machine.  Build systems often
>already
>> lead to that, but users are more familiar with the risks for build
>> than for version control.
>>
>> See [1] for some related discussion.
>>
>> That said, using the include.path feature (see git-config(1)), it's
>> possible to do something similar:
>>
>> 	[include]
>> 		path = ../.gitconfig
>>
>> Thanks and hope that helps,
>
>The issue the arrangement to specify what kind of files they are in
>the attribute system and to specify what exact commands to be run in
>the configuration addresses is twofold.  The security issue is one
>and poking a hole with include.path mechanism is probably OK as
>there is end-user consent, but I tend to agree that a similar risk
>already exists by a project shipping Makefile et al.
>
>There is the other side of the issue.
>
>The arrangement allows project not to be monoculture by leaving the
>exact command sequence to use on the kind of files (specified by the
>project with the attribute system) up to the end-user in their
>configuration.  While Peter may feel that sort piped to head may be
>available on all the reasonable UNIX systems, his merge driver would
>not work on other platforms.  There already is a similar reliance of
>monoculture by a project shipping Makefile et al, which is an
>interesting parallel.

This is actually a further good reason for doing it this way: it means that more genal drivers can be written using files in the repo, depending on what the baseline of the project is.
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

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

end of thread, other threads:[~2018-12-29  9:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-27 20:16 RFE: version-controlled merge rules H. Peter Anvin
2018-12-27 23:55 ` Jonathan Nieder
2018-12-28  4:48   ` H. Peter Anvin
2018-12-28 16:03     ` Duy Nguyen
2018-12-28 14:35   ` Junio C Hamano
2018-12-29  9:14     ` hpa
2018-12-28  8:42 ` Ævar Arnfjörð Bjarmason

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).