#!/bin/sh

EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904

# git-ubuntu sets this when it creates commits programmatically (e.g.
# during a delta rebase) where intermediate empty trees are expected.
if [ -n "$GIT_UBUNTU_SKIP_EMPTY_TREE_CHECK" ]; then
    exit 0
fi

if git ls-tree -r -d HEAD|awk '{print $3}'|grep -q $EMPTY_TREE; then
    echo "ERROR: Empty directories exist and will disappear on commit, causing" >&2
    echo "extraneous unintended changes:" >&2
    echo >&2
    git ls-tree -r -d HEAD|grep $EMPTY_TREE|awk '{print $4}' >&2
    echo >&2
    echo "See LP: #1687057." >&2
    echo 'Use "git commit --no-verify ..." to ignore this problem.' >&2
    echo >&2
    echo "pre-commit hook failed." >&2
    exit 1
fi
