1#!/bin/sh2#3# Copyright (c) 2005 Junio C Hamano4#56test_description='See why rewinding head breaks send-pack78'9. ./test-lib.sh1011touch cpio-test12test_expect_success 'working cpio' 'echo cpio-test | cpio -o > /dev/null'1314cnt='1'15test_expect_success setup '16tree=$(git-write-tree) &&17commit=$(echo "Commit #0" | git-commit-tree $tree) &&18zero=$commit &&19parent=$zero &&20for i in $cnt21do22sleep 1 &&23commit=$(echo "Commit #$i" | git-commit-tree $tree -p $parent) &&24parent=$commit || return 125done &&26git-update-ref HEAD "$commit" &&27git-clone -l ./. victim &&28cd victim &&29git-log &&30cd .. &&31git-update-ref HEAD "$zero" &&32parent=$zero &&33for i in $cnt34do35sleep 1 &&36commit=$(echo "Rebase #$i" | git-commit-tree $tree -p $parent) &&37parent=$commit || return 138done &&39git-update-ref HEAD "$commit" &&40echo Rebase &&41git-log'4243test_expect_success \44'pushing rewound head should not barf but require --force' '45# should not fail but refuse to update.46if git-send-pack ./victim/.git/ master47then48# now it should fail with Pasky patch49echo >&2 Gaah, it should have failed.50false51else52echo >&2 Thanks, it correctly failed.53true54fi &&55if cmp victim/.git/refs/heads/master .git/refs/heads/master56then57# should have been left as it was!58false59else60true61fi &&62# this should update63git-send-pack --force ./victim/.git/ master &&64cmp victim/.git/refs/heads/master .git/refs/heads/master65'6667test_expect_success \68'push can be used to delete a ref' '69cd victim &&70git branch extra master &&71cd .. &&72test -f victim/.git/refs/heads/extra &&73git-send-pack ./victim/.git/ :extra master &&74! test -f victim/.git/refs/heads/extra75'7677unset GIT_CONFIG GIT_CONFIG_LOCAL78HOME=`pwd`/no-such-directory79export HOME ;# this way we force the victim/.git/config to be used.8081test_expect_success \82'pushing with --force should be denied with denyNonFastforwards' '83cd victim &&84git-repo-config receive.denyNonFastforwards true &&85cd .. &&86git-update-ref refs/heads/master master^ &&87git-send-pack --force ./victim/.git/ master &&88! diff -u .git/refs/heads/master victim/.git/refs/heads/master89'9091test_done