Skip to content

Commit

Permalink
Stop using 'git checkout' in pre_receive.
Browse files Browse the repository at this point in the history
As of earlier this year, git no longer allows any ref updates in the
pre-receive hook.

This is intended to prevent corruption of your git tree, but it means
that we can't actually do a git checkout in pre-receive.

(See https://www.spinics.net/lists/git/msg300763.html for the git side
details.)

Instead, we are using git archive to dump the tree as of the new commit,
and we are decompressing that in our new temporary directory
(commit 6bbfc5f).

We then chdir to the temporary directory, do all of our checks, and
switch back to the repo directory before saving the list file.
  • Loading branch information
Zephaniah E. Loss-Cutler-Hull committed Nov 9, 2017
1 parent 5e572b8 commit 9031e62
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bin/gitzone
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,13 @@ sub pre_receive {
File::Path->remove_tree($tmp_dir, verbose => 1);
File::Path->make_path($tmp_dir, verbose => 1);

# checkout changes
git "checkout -qf $new";
# Extract the new commit.
# We do this with git archive, and then extract the resulting tar in the temporary directory.
# There really should be a better way to do this, but I can't find one.
git "archive $new | tar -C $tmp_dir -xf -";

# chdir into the temporary directory.
chdir $tmp_dir or die $!;

# Go read only, no actual changes in the pre-release hook.
$read_only = 1;
Expand All @@ -322,6 +327,8 @@ sub pre_receive {
load_repo_config;
process_files;

# Go back to the repo.
chdir $base_cwd;

# Save the file list, this is of questionable value at this point.
save_list_file;
Expand Down

0 comments on commit 9031e62

Please sign in to comment.