Files
pre-commit/pre_commit/resources/pre-push-tmpl
Sam Duke 1bfd108593 Properly detect if commit is a root commit
Fix bad check for ancestor root commits.
2018-01-24 14:01:59 +00:00

32 lines
1.2 KiB
Plaintext

z40=0000000000000000000000000000000000000000
while read local_ref local_sha remote_ref remote_sha
do
if [ "$local_sha" != $z40 ]; then
if [ "$remote_sha" = $z40 ]; then
# First ancestor not found in remote
first_ancestor=$(git rev-list --topo-order --reverse "$local_sha" --not --remotes="$1" | head -n 1)
if [ -n "$first_ancestor" ]; then
# Check that the ancestor has at least one parent
git rev-list --max-parents=0 "$local_sha" | grep "$first_ancestor" > /dev/null
if [ $? -eq 0 ]; then
# Pushing the whole tree, including the root commit, so run on all files
args="--all-files"
else
source=$(git rev-parse "$first_ancestor"^)
args="--origin $local_sha --source $source"
fi
fi
else
args="--origin $local_sha --source $remote_sha"
fi
fi
done
if [ "$args" != "" ]; then
args="$args --hook-stage push"
else
# If args is empty, then an attempt to push on an empty
# changeset is being made. In this case, just exit cleanly
exit 0
fi