On Mon, 16 May 2016 08:10:32 -0700 (PDT)
Sanjiv Kumar <devopsarchitect...@gmail.com> wrote:

> > I wanted to avoid push if any of the files is deleted from the
> > local git clone area. Can anyone please help me with that?
> >
> > I am using Stash for repository management.
> On our side we need to reject the push if any file is deleted.

OK, so you need to write and install a pre-push hook in your local

Start with reading the githooks manual page (run `git help hooks`).

The hook is a program (or, in the simplest case, a script) which gets
run when some specific event happens in the repository.  The Git
instance which is running the hook communicates with the process
running it via the command-line parameters and standard input stream.
The hook communicates with Git via its exit code; whatever it prints
to its standard output and error streams is sent to the client.
The section describing each kind of hook in the manual page describes
what exactly is submitted to the hooks of that kind, and what is
expected in exchange.

Exiting with a non-zero exit code from the pre-push hook fails the
operation, and no push will be attempted.  This is what you're after.

Now you need to write the hook's code.

The hook gets passed one or more lines describing what is about to be
pushed, and what data to update with the push.  See the manual for more

IMO the simplest thing you can do is to is to run `git diff` for each
input line and catch with it any change which deleted any files.

Something along this lines could be a good start:

  set -e -u
  while read _ our _ their; do
    out=`git diff --name-status --diff-filter=D $their $our`
    test -z "$out" && exit 1
  exit 0

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to