6

I have been using post-receive scripts in my git repositories with the following commands to checkout all of the files in the repository:

#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f

I am wanting to do something similar but only checkout the files that have been modified or added in the push. Once the files have been checked out the post-receive script will then run some other commands on these files and remove the files at the end so that the directory will be empty.

Is this possible?

pah
  • 4,700
  • 6
  • 28
  • 37
startupsmith
  • 5,554
  • 10
  • 50
  • 71

1 Answers1

5

you can use git diff to give you a list of files

git diff --name-only from..to

in a post-receive hook that'll be I think

git diff --name-only $1..$2

as this hook receives oldrev, newrev and ref on standard input

AD7six
  • 63,116
  • 12
  • 91
  • 123
  • I don't need a list of files I need to checkout the new files to a directory. I probably should mention that I am doing this using a bare repository hosted on a server. – startupsmith Mar 08 '12 at 08:21
  • Once you know which files are relevant [it's then possible to dump them wherever you want](https://github.com/AD7six/git-hooks/blob/develop/utils.php#L101). But you need to know which files to action first, and you aren't going to do a checkout at all. – AD7six Mar 08 '12 at 08:52
  • OK so can I pass the git diff output to your copyFiles php function form inside the post-receive hook script? – startupsmith Mar 09 '12 at 23:22