1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
56
test_description='See why rewinding head breaks send-pack
78
'
9. ./test-lib.sh
1011
touch cpio-test
12test_expect_success 'working cpio' 'echo cpio-test | cpio -o > /dev/null'
1314
cnt='1'
15test_expect_success setup '
16tree=$(git-write-tree) &&
17commit=$(echo "Commit #0" | git-commit-tree $tree) &&
18zero=$commit &&
19parent=$zero &&
20for i in $cnt
21do
22sleep 1 &&
23commit=$(echo "Commit #$i" | git-commit-tree $tree -p $parent) &&
24parent=$commit || return 1
25done &&
26git-update-ref HEAD "$commit" &&
27git-clone -l ./. victim &&
28cd victim &&
29git-log &&
30cd .. &&
31git-update-ref HEAD "$zero" &&
32parent=$zero &&
33for i in $cnt
34do
35sleep 1 &&
36commit=$(echo "Rebase #$i" | git-commit-tree $tree -p $parent) &&
37parent=$commit || return 1
38done &&
39git-update-ref HEAD "$commit" &&
40echo Rebase &&
41git-log'
4243
test_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/ master
47then
48# now it should fail with Pasky patch
49echo >&2 Gaah, it should have failed.
50false
51else
52echo >&2 Thanks, it correctly failed.
53true
54fi &&
55if cmp victim/.git/refs/heads/master .git/refs/heads/master
56then
57# should have been left as it was!
58false
59else
60true
61fi &&
62# this should update
63git-send-pack --force ./victim/.git/ master &&
64cmp victim/.git/refs/heads/master .git/refs/heads/master
65'
6667
test_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/extra
75'
7677
unset GIT_CONFIG GIT_CONFIG_LOCAL
78HOME=`pwd`/no-such-directory
79export HOME ;# this way we force the victim/.git/config to be used.
8081
test_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/master
89'
9091
test_done