All of lore.kernel.org
 help / color / mirror / Atom feed
* pre-receive hook ; how to detect file and append code ?
@ 2012-06-22 13:07 J. Bakshi
  2012-06-22 13:41 ` Thomas Adam
  2012-06-22 18:02 ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: J. Bakshi @ 2012-06-22 13:07 UTC (permalink / raw)
  To: git

Dear list,

How can I detect a specific file during push, if it is modified or not ?
And how can I then append a block of code into that file; if modified
during push ? I think pre-receive hook is the best for this operation.

Thanks

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

* Re: pre-receive hook ; how to detect file and append code ?
  2012-06-22 13:07 pre-receive hook ; how to detect file and append code ? J. Bakshi
@ 2012-06-22 13:41 ` Thomas Adam
  2012-06-22 18:02 ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Adam @ 2012-06-22 13:41 UTC (permalink / raw)
  To: J. Bakshi; +Cc: git

On 22 June 2012 14:07, J. Bakshi <joydeep.bakshi@infoservices.in> wrote:
> Dear list,
>
> How can I detect a specific file during push, if it is modified or not ?
> And how can I then append a block of code into that file; if modified
> during push ? I think pre-receive hook is the best for this operation.

Umm, what problem are you trying to solve?  This is a solution to an
unnamed problem, see "XY problem".

-- Thomas Adam

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

* Re: pre-receive hook ; how to detect file and append code ?
  2012-06-22 13:07 pre-receive hook ; how to detect file and append code ? J. Bakshi
  2012-06-22 13:41 ` Thomas Adam
@ 2012-06-22 18:02 ` Junio C Hamano
  2012-06-25  7:48   ` J. Bakshi
  1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2012-06-22 18:02 UTC (permalink / raw)
  To: J. Bakshi; +Cc: git

"J. Bakshi" <joydeep.bakshi@infoservices.in> writes:

> How can I detect a specific file during push, if it is modified or not ?
> And how can I then append a block of code into that file; if modified
> during push ? I think pre-receive hook is the best for this operation.

The purpose of the "pre-receive" hook is to either approve or reject
a proposed change made by the push.  When it runs, the repository
already has received all the objects necessary to inspect the
proposed change locally (from the receiving repository's point of
view).

A proposed change comes in the form of <old> <new> <refname> that
says "The pusher saw <old> at <refname> when he started this push,
and it wants to update the ref to <new>".  So any of the following
standard techniques (note: not exhaustive) to inspect the changes
between <old> and <new> can be used:

    # are log messages sane?
    git log <old>..<new>

    # are the changes sane?
    git diff <old>..<new>

    # does it leave forbidden paths intact
    git diff --name-only <old>..<new>

If your script likes the proposed change, exit with 0.  If it does
not, exit with non-zero.

That is all it can do.  It is not supposed to change <new> to some
other value, and there is no interface to do so.

If you want to rewrite the history pushed into the repository after
a push is accepted, you would want to run it from post-receive or
something.  All the usual warning about rewriting published history
will apply if you do so, however.  After all, the history is already
published immediately before post-recieve (or post-update) runs.

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

* Re: pre-receive hook ; how to detect file and append code ?
  2012-06-22 18:02 ` Junio C Hamano
@ 2012-06-25  7:48   ` J. Bakshi
  0 siblings, 0 replies; 4+ messages in thread
From: J. Bakshi @ 2012-06-25  7:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Fri, 22 Jun 2012 11:02:41 -0700
Junio C Hamano <gitster@pobox.com> wrote:

> "J. Bakshi" <joydeep.bakshi@infoservices.in> writes:
> 
> > How can I detect a specific file during push, if it is modified or not ?
> > And how can I then append a block of code into that file; if modified
> > during push ? I think pre-receive hook is the best for this operation.
> 
> The purpose of the "pre-receive" hook is to either approve or reject
> a proposed change made by the push.  When it runs, the repository
> already has received all the objects necessary to inspect the
> proposed change locally (from the receiving repository's point of
> view).
> 
> A proposed change comes in the form of <old> <new> <refname> that
> says "The pusher saw <old> at <refname> when he started this push,
> and it wants to update the ref to <new>".  So any of the following
> standard techniques (note: not exhaustive) to inspect the changes
> between <old> and <new> can be used:
> 
>     # are log messages sane?
>     git log <old>..<new>
> 
>     # are the changes sane?
>     git diff <old>..<new>
> 
>     # does it leave forbidden paths intact
>     git diff --name-only <old>..<new>
> 
> If your script likes the proposed change, exit with 0.  If it does
> not, exit with non-zero.
> 
> That is all it can do.  It is not supposed to change <new> to some
> other value, and there is no interface to do so.
> 
> If you want to rewrite the history pushed into the repository after
> a push is accepted, you would want to run it from post-receive or
> something.  All the usual warning about rewriting published history
> will apply if you do so, however.  After all, the history is already
> published immediately before post-recieve (or post-update) runs.

Thanks a lot for the clarifications....

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

end of thread, other threads:[~2012-06-25  7:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-22 13:07 pre-receive hook ; how to detect file and append code ? J. Bakshi
2012-06-22 13:41 ` Thomas Adam
2012-06-22 18:02 ` Junio C Hamano
2012-06-25  7:48   ` J. Bakshi

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.