]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5541-http-push.sh
t5541-http-push: check that ref is unchanged for non-ff test
[thirdparty/git.git] / t / t5541-http-push.sh
CommitLineData
7da4e228
SP
1#!/bin/sh
2#
3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4#
5
6test_description='test smart pushing over http via http-backend'
7. ./test-lib.sh
8
9if test -n "$NO_CURL"; then
10 say 'skipping test, git built without http support'
11 test_done
12fi
13
14ROOT_PATH="$PWD"
15LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'}
16. "$TEST_DIRECTORY"/lib-httpd.sh
17start_httpd
18
19test_expect_success 'setup remote repository' '
20 cd "$ROOT_PATH" &&
21 mkdir test_repo &&
22 cd test_repo &&
23 git init &&
24 : >path1 &&
25 git add path1 &&
26 test_tick &&
27 git commit -m initial &&
28 cd - &&
29 git clone --bare test_repo test_repo.git &&
30 cd test_repo.git &&
31 git config http.receivepack true &&
32 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
33 cd - &&
34 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
35'
36
37test_expect_success 'clone remote repository' '
38 cd "$ROOT_PATH" &&
39 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
40'
41
42test_expect_success 'push to remote repository' '
43 cd "$ROOT_PATH"/test_repo_clone &&
44 : >path2 &&
45 git add path2 &&
46 test_tick &&
47 git commit -m path2 &&
48 HEAD=$(git rev-parse --verify HEAD) &&
49 git push &&
50 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
51 test $HEAD = $(git rev-parse --verify HEAD))
52'
53
54test_expect_success 'push already up-to-date' '
55 git push
56'
57
58test_expect_success 'create and delete remote branch' '
59 cd "$ROOT_PATH"/test_repo_clone &&
60 git checkout -b dev &&
61 : >path3 &&
62 git add path3 &&
63 test_tick &&
64 git commit -m dev &&
65 git push origin dev &&
66 git push origin :dev &&
67 test_must_fail git show-ref --verify refs/remotes/origin/dev
68'
69
70cat >exp <<EOF
71GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
72POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
73GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
74POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
75GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
76GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
77POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
78GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
79POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
80EOF
81test_expect_success 'used receive-pack service' '
82 sed -e "
83 s/^.* \"//
84 s/\"//
85 s/ [1-9][0-9]*\$//
86 s/^GET /GET /
87 " >act <"$HTTPD_ROOT_PATH"/access.log &&
88 test_cmp exp act
89'
90
42328267 91test_expect_success 'non-fast-forward push fails' '
fe4bc2a5
TRC
92 cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
93 HEAD=$(git rev-parse --verify HEAD) &&
94
19452374
TRC
95 cd "$ROOT_PATH"/test_repo_clone &&
96 git checkout master &&
97 echo "changed" > path2 &&
98 git commit -a -m path2 --amend &&
99
19452374
TRC
100 !(git push -v origin >output 2>&1) &&
101 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
fe4bc2a5 102 test $HEAD = $(git rev-parse --verify HEAD))
19452374
TRC
103'
104
20e8b465 105test_expect_success 'non-fast-forward push show ref status' '
19452374
TRC
106 grep "^ ! \[rejected\][ ]*master -> master (non-fast-forward)$" output
107'
108
42328267 109test_expect_success 'non-fast-forward push shows help message' '
9567f082
TRC
110 grep "To prevent you from losing history, non-fast-forward updates were rejected" \
111 output
19452374
TRC
112'
113
08d63a42 114test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
7b69079b
TRC
115 # create a dissimilarly-named remote ref so that git is unable to match the
116 # two refs (viz. local, remote) unless an explicit refspec is provided.
117 git push origin master:retsam
118
119 echo "change changed" > path2 &&
120 git commit -a -m path2 --amend &&
121
122 # push master too; this ensures there is at least one '"'push'"' command to
123 # the remote helper and triggers interaction with the helper.
124 !(git push -v origin +master master:retsam >output 2>&1) &&
125
126 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
127 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output &&
128
9567f082
TRC
129 grep "To prevent you from losing history, non-fast-forward updates were rejected" \
130 output
7b69079b
TRC
131'
132
7da4e228
SP
133stop_httpd
134test_done