All of lore.kernel.org
 help / color / mirror / Atom feed
* HowTo distribute a hook with the reposity.
@ 2016-12-28  1:34 John P. Hartmann
  2016-12-28  5:32 ` Jacob Keller
  0 siblings, 1 reply; 9+ messages in thread
From: John P. Hartmann @ 2016-12-28  1:34 UTC (permalink / raw)
  To: git

I would like a hook in .got/hooks to be made available to all who clone 
or pull a particular project.  I'd also like the hook to be under git 
control (changes committed &c).  I added a hook, but git status does not 
show it.  Presumably git excludes its files in .git/ from version 
control lest there be a chiken-and-egg situation.

Is there a way to achieve this?  Or a better way to do it?

Thanks,  j.

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

* Re: HowTo distribute a hook with the reposity.
  2016-12-28  1:34 HowTo distribute a hook with the reposity John P. Hartmann
@ 2016-12-28  5:32 ` Jacob Keller
  2016-12-28  6:08   ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: Jacob Keller @ 2016-12-28  5:32 UTC (permalink / raw)
  To: John P. Hartmann; +Cc: Git mailing list

On Tue, Dec 27, 2016 at 5:34 PM, John P. Hartmann <jphartmann@gmail.com> wrote:
> I would like a hook in .got/hooks to be made available to all who clone or
> pull a particular project.  I'd also like the hook to be under git control
> (changes committed &c).  I added a hook, but git status does not show it.
> Presumably git excludes its files in .git/ from version control lest there
> be a chiken-and-egg situation.
>
> Is there a way to achieve this?  Or a better way to do it?
>
> Thanks,  j.

Best way I found, was add a script with an "installme" shell script or
similar that you tell all users of the repository that they are
expected to run this to install the scripts. You can' make it happen
automatically.

Thanks,
Jake

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

* Re: HowTo distribute a hook with the reposity.
  2016-12-28  5:32 ` Jacob Keller
@ 2016-12-28  6:08   ` Jeff King
  2016-12-28  8:42     ` John P. Hartmann
  2016-12-28 18:53     ` Jacob Keller
  0 siblings, 2 replies; 9+ messages in thread
From: Jeff King @ 2016-12-28  6:08 UTC (permalink / raw)
  To: Jacob Keller; +Cc: John P. Hartmann, Git mailing list

On Tue, Dec 27, 2016 at 09:32:22PM -0800, Jacob Keller wrote:

> On Tue, Dec 27, 2016 at 5:34 PM, John P. Hartmann <jphartmann@gmail.com> wrote:
> > I would like a hook in .got/hooks to be made available to all who clone or
> > pull a particular project.  I'd also like the hook to be under git control
> > (changes committed &c).  I added a hook, but git status does not show it.
> > Presumably git excludes its files in .git/ from version control lest there
> > be a chiken-and-egg situation.
> >
> > Is there a way to achieve this?  Or a better way to do it?
> >
> > Thanks,  j.
> 
> Best way I found, was add a script with an "installme" shell script or
> similar that you tell all users of the repository that they are
> expected to run this to install the scripts. You can' make it happen
> automatically.

I agree that is the best way to do it.

I didn't dig up previous discussions, but the gist is usually:

  1. Cloning a repository should not run arbitrary code from the remote
     without the user on the cloning side taking some further affirmative
     action.

     This is for security reasons. Obviously the next step is quite often
     to run "make" which does run arbitrary code, but that counts as an
     action.

  2. We could write a feature in git that manages hooks (or config, etc).
     But ultimately you would still be running "git clone
     --trust-remote-hooks" or something to satisfy point (1).

  3. There's not much point in doing point (2), because you can just
     spell it as "git clone && cd clone && ./install-hooks" and then git
     does not have to care at all about your scripts.

  4. A hook (or config) management system could do fancy things like
     merging your custom local config, picking up changes from the
     remote, etc. But all of that can happen outside of Git totally (and
     quite often you want to manage things in contributors setups
     _besides_ Git data anyway).

     An example system is:

       https://github.com/Autodesk/enterprise-config-for-git

     (with the disclaimer that I've never used it myself, so I have no
     idea how good it is).

I think you probably know all that, Jake, but I am laying it out for the
benefit of the OP and the list. :)

-Peff

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

* Re: HowTo distribute a hook with the reposity.
  2016-12-28  6:08   ` Jeff King
@ 2016-12-28  8:42     ` John P. Hartmann
  2016-12-28  8:52       ` Jeff King
  2016-12-28 18:53     ` Jacob Keller
  1 sibling, 1 reply; 9+ messages in thread
From: John P. Hartmann @ 2016-12-28  8:42 UTC (permalink / raw)
  To: Jeff King, Jacob Keller; +Cc: Git mailing list

Thanks; your point is taken.  One final wrinkle:

This project is hosted on github.  If I put the hook into the repository 
manually (if I can; I don't know that), is it true that the hook would 
be distributed on a clone action, but not on a pull?

	j.

On 28/12/16 06:08, Jeff King wrote:
> On Tue, Dec 27, 2016 at 09:32:22PM -0800, Jacob Keller wrote:
>
>> On Tue, Dec 27, 2016 at 5:34 PM, John P. Hartmann <jphartmann@gmail.com> wrote:
>>> I would like a hook in .got/hooks to be made available to all who clone or
>>> pull a particular project.  I'd also like the hook to be under git control
>>> (changes committed &c).  I added a hook, but git status does not show it.
>>> Presumably git excludes its files in .git/ from version control lest there
>>> be a chiken-and-egg situation.
>>>
>>> Is there a way to achieve this?  Or a better way to do it?
>>>
>>> Thanks,  j.
>>
>> Best way I found, was add a script with an "installme" shell script or
>> similar that you tell all users of the repository that they are
>> expected to run this to install the scripts. You can' make it happen
>> automatically.
>
> I agree that is the best way to do it.
>
> I didn't dig up previous discussions, but the gist is usually:
>
>   1. Cloning a repository should not run arbitrary code from the remote
>      without the user on the cloning side taking some further affirmative
>      action.
>
>      This is for security reasons. Obviously the next step is quite often
>      to run "make" which does run arbitrary code, but that counts as an
>      action.
>
>   2. We could write a feature in git that manages hooks (or config, etc).
>      But ultimately you would still be running "git clone
>      --trust-remote-hooks" or something to satisfy point (1).
>
>   3. There's not much point in doing point (2), because you can just
>      spell it as "git clone && cd clone && ./install-hooks" and then git
>      does not have to care at all about your scripts.
>
>   4. A hook (or config) management system could do fancy things like
>      merging your custom local config, picking up changes from the
>      remote, etc. But all of that can happen outside of Git totally (and
>      quite often you want to manage things in contributors setups
>      _besides_ Git data anyway).
>
>      An example system is:
>
>        https://github.com/Autodesk/enterprise-config-for-git
>
>      (with the disclaimer that I've never used it myself, so I have no
>      idea how good it is).
>
> I think you probably know all that, Jake, but I am laying it out for the
> benefit of the OP and the list. :)
>
> -Peff
>

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

* Re: HowTo distribute a hook with the reposity.
  2016-12-28  8:42     ` John P. Hartmann
@ 2016-12-28  8:52       ` Jeff King
  2016-12-28  9:09         ` John P. Hartmann
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2016-12-28  8:52 UTC (permalink / raw)
  To: John P. Hartmann; +Cc: Jacob Keller, Git mailing list

On Wed, Dec 28, 2016 at 08:42:25AM +0000, John P. Hartmann wrote:

> This project is hosted on github.  If I put the hook into the repository
> manually (if I can; I don't know that), is it true that the hook would be
> distributed on a clone action, but not on a pull?

I'm not sure what you mean by "into the repository". If you mean "into
the .git directory", then no, you can't do that. Git will not add ".git"
directory contents to a repository, you cannot manipulate the contents
of ".git" directories on GitHub, and a client wouldn't ever look at them
on clone or fetch anyway.

Did you mean something else?

-Peff

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

* Re: HowTo distribute a hook with the reposity.
  2016-12-28  8:52       ` Jeff King
@ 2016-12-28  9:09         ` John P. Hartmann
  2016-12-28  9:20           ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: John P. Hartmann @ 2016-12-28  9:09 UTC (permalink / raw)
  To: Jeff King; +Cc: Jacob Keller, Git mailing list

Thanks, Peff, for your lucid answer to my question and much more.  All 
is now clear to me.

The problem I am grappling with is how to obtain the latest git commit 
hash and enter it into the generated code.  Configure/make would appear 
to the the time, but by then the user may not have git installed (e.g., 
extracted the project as .zip from github), so it needs to be done "back 
at the farm".

I hear that the best I can do is create a normal script in the repro and 
add to the developer handbook that "btw, here is a git hook that will 
run it automatically if you so choose".

Thank you both for your prompt and exhaustive answers.

	j.

On 28/12/16 08:52, Jeff King wrote:
> On Wed, Dec 28, 2016 at 08:42:25AM +0000, John P. Hartmann wrote:
>
>> This project is hosted on github.  If I put the hook into the repository
>> manually (if I can; I don't know that), is it true that the hook would be
>> distributed on a clone action, but not on a pull?
>
> I'm not sure what you mean by "into the repository". If you mean "into
> the .git directory", then no, you can't do that. Git will not add ".git"
> directory contents to a repository, you cannot manipulate the contents
> of ".git" directories on GitHub, and a client wouldn't ever look at them
> on clone or fetch anyway.
>
> Did you mean something else?
>
> -Peff
>

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

* Re: HowTo distribute a hook with the reposity.
  2016-12-28  9:09         ` John P. Hartmann
@ 2016-12-28  9:20           ` Jeff King
  0 siblings, 0 replies; 9+ messages in thread
From: Jeff King @ 2016-12-28  9:20 UTC (permalink / raw)
  To: John P. Hartmann; +Cc: Jacob Keller, Git mailing list

On Wed, Dec 28, 2016 at 09:09:04AM +0000, John P. Hartmann wrote:

> The problem I am grappling with is how to obtain the latest git commit hash
> and enter it into the generated code.  Configure/make would appear to the
> the time, but by then the user may not have git installed (e.g., extracted
> the project as .zip from github), so it needs to be done "back at the farm".
> 
> I hear that the best I can do is create a normal script in the repro and add
> to the developer handbook that "btw, here is a git hook that will run it
> automatically if you so choose".

Yes, if you want the information to be conveyed in a .zip from GitHub,
then you'll have to commit the value to the repository. For example,
the script in Git itself looks like this:

  https://github.com/git/git/blob/master/GIT-VERSION-GEN

We pull the value from the Git repository if we have one, then fallback
to a .version file which is generated when release tarballs are
generated, and then finally fall back to a baked-in DEF_VER variable
that is updated manually after each release (and that last is what you'd
get if you had, say, a .zip file from GitHub).

I'm not sure you would want to update that DEF_VER for _every_ commit,
though, even if you could do so with a hook. It would mean every commit
would update the version field. And of course it could not have the git
commit id, because that is generated from a hash of the contents that
includes the contents of that version field.

If you're mostly interested in building straight from GitHub .zip files,
those do include the commit id (or tag name) in the directory name, so
your Makefile could deduce it at runtime from that information.

-Peff

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

* Re: HowTo distribute a hook with the reposity.
  2016-12-28  6:08   ` Jeff King
  2016-12-28  8:42     ` John P. Hartmann
@ 2016-12-28 18:53     ` Jacob Keller
  2016-12-29 10:29       ` Lars Schneider
  1 sibling, 1 reply; 9+ messages in thread
From: Jacob Keller @ 2016-12-28 18:53 UTC (permalink / raw)
  To: Jeff King; +Cc: John P. Hartmann, Git mailing list

On Tue, Dec 27, 2016 at 10:08 PM, Jeff King <peff@peff.net> wrote:
>
>        https://github.com/Autodesk/enterprise-config-for-git
>
>      (with the disclaimer that I've never used it myself, so I have no
>      idea how good it is).
>
> I think you probably know all that, Jake, but I am laying it out for the
> benefit of the OP and the list. :)
>

Heh, well I didn't know about this last part so it's still useful to
me! I knew of the larger description for why not but wasn't exactly
clear how to word it so I am glad you filled that in. Thanks!

Regards,
Jake

> -Peff

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

* Re: HowTo distribute a hook with the reposity.
  2016-12-28 18:53     ` Jacob Keller
@ 2016-12-29 10:29       ` Lars Schneider
  0 siblings, 0 replies; 9+ messages in thread
From: Lars Schneider @ 2016-12-29 10:29 UTC (permalink / raw)
  To: Jacob Keller; +Cc: Jeff King, John P. Hartmann, Git mailing list


> On 28 Dec 2016, at 19:53, Jacob Keller <jacob.keller@gmail.com> wrote:
> 
> On Tue, Dec 27, 2016 at 10:08 PM, Jeff King <peff@peff.net> wrote:
>> 
>>       https://github.com/Autodesk/enterprise-config-for-git
>> 
>>     (with the disclaimer that I've never used it myself, so I have no
>>     idea how good it is).
>> 
>> I think you probably know all that, Jake, but I am laying it out for the
>> benefit of the OP and the list. :)
>> 
> 
> Heh, well I didn't know about this last part so it's still useful to
> me! I knew of the larger description for why not but wasn't exactly
> clear how to word it so I am glad you filled that in. Thanks!

Author of the "enterprise-config-for-git" here. The version in the public
Git repo is a stripped down version of the one we use at my day job for
our engineering workforce. I tried to extract the "generally useful bits".
Unfortunately it cannot be used "as-is". Don't hesitate to ping me if you
want to learn more about it and/or if you have an idea how to make it
better suited for open source collaboration.

Cheers,
Lars


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

end of thread, other threads:[~2016-12-29 10:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-28  1:34 HowTo distribute a hook with the reposity John P. Hartmann
2016-12-28  5:32 ` Jacob Keller
2016-12-28  6:08   ` Jeff King
2016-12-28  8:42     ` John P. Hartmann
2016-12-28  8:52       ` Jeff King
2016-12-28  9:09         ` John P. Hartmann
2016-12-28  9:20           ` Jeff King
2016-12-28 18:53     ` Jacob Keller
2016-12-29 10:29       ` Lars Schneider

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.