Shawn O. Pearce | 7da4e22 | 2009-10-30 17:47:47 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at> |
| 4 | # |
| 5 | |
| 6 | test_description='test smart pushing over http via http-backend' |
| 7 | . ./test-lib.sh |
| 8 | |
| 9 | if test -n "$NO_CURL"; then |
Ævar Arnfjörð Bjarmason | fadb515 | 2010-06-24 17:44:48 +0000 | [diff] [blame] | 10 | skip_all='skipping test, git built without http support' |
Shawn O. Pearce | 7da4e22 | 2009-10-30 17:47:47 -0700 | [diff] [blame] | 11 | test_done |
| 12 | fi |
| 13 | |
| 14 | ROOT_PATH="$PWD" |
| 15 | LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'} |
| 16 | . "$TEST_DIRECTORY"/lib-httpd.sh |
| 17 | start_httpd |
| 18 | |
| 19 | test_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 | |
Tay Ray Chuan | 9ee6bcd | 2010-04-08 10:15:16 +0800 | [diff] [blame] | 37 | cat >exp <<EOF |
| 38 | GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200 |
| 39 | POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200 |
| 40 | EOF |
Tay Ray Chuan | d8fab07 | 2010-04-08 10:15:18 +0800 | [diff] [blame] | 41 | test_expect_success 'no empty path components' ' |
Tay Ray Chuan | 9ee6bcd | 2010-04-08 10:15:16 +0800 | [diff] [blame] | 42 | # In the URL, add a trailing slash, and see if git appends yet another |
| 43 | # slash. |
Shawn O. Pearce | 7da4e22 | 2009-10-30 17:47:47 -0700 | [diff] [blame] | 44 | cd "$ROOT_PATH" && |
Tay Ray Chuan | 9ee6bcd | 2010-04-08 10:15:16 +0800 | [diff] [blame] | 45 | git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone && |
| 46 | |
| 47 | sed -e " |
| 48 | s/^.* \"// |
| 49 | s/\"// |
| 50 | s/ [1-9][0-9]*\$// |
| 51 | s/^GET /GET / |
| 52 | " >act <"$HTTPD_ROOT_PATH"/access.log && |
| 53 | |
| 54 | # Clear the log, so that it does not affect the "used receive-pack |
| 55 | # service" test which reads the log too. |
| 56 | # |
| 57 | # We do this before the actual comparison to ensure the log is cleared. |
| 58 | echo > "$HTTPD_ROOT_PATH"/access.log && |
| 59 | |
| 60 | test_cmp exp act |
| 61 | ' |
| 62 | |
| 63 | test_expect_success 'clone remote repository' ' |
| 64 | rm -rf test_repo_clone && |
Shawn O. Pearce | 7da4e22 | 2009-10-30 17:47:47 -0700 | [diff] [blame] | 65 | git clone $HTTPD_URL/smart/test_repo.git test_repo_clone |
| 66 | ' |
| 67 | |
| 68 | test_expect_success 'push to remote repository' ' |
| 69 | cd "$ROOT_PATH"/test_repo_clone && |
| 70 | : >path2 && |
| 71 | git add path2 && |
| 72 | test_tick && |
| 73 | git commit -m path2 && |
| 74 | HEAD=$(git rev-parse --verify HEAD) && |
| 75 | git push && |
| 76 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && |
| 77 | test $HEAD = $(git rev-parse --verify HEAD)) |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'push already up-to-date' ' |
| 81 | git push |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'create and delete remote branch' ' |
| 85 | cd "$ROOT_PATH"/test_repo_clone && |
| 86 | git checkout -b dev && |
| 87 | : >path3 && |
| 88 | git add path3 && |
| 89 | test_tick && |
| 90 | git commit -m dev && |
| 91 | git push origin dev && |
| 92 | git push origin :dev && |
| 93 | test_must_fail git show-ref --verify refs/remotes/origin/dev |
| 94 | ' |
| 95 | |
| 96 | cat >exp <<EOF |
Tay Ray Chuan | 9ee6bcd | 2010-04-08 10:15:16 +0800 | [diff] [blame] | 97 | |
Shawn O. Pearce | 7da4e22 | 2009-10-30 17:47:47 -0700 | [diff] [blame] | 98 | GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200 |
| 99 | POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200 |
| 100 | GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 |
| 101 | POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200 |
| 102 | GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 |
| 103 | GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 |
| 104 | POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200 |
| 105 | GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 |
| 106 | POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200 |
| 107 | EOF |
| 108 | test_expect_success 'used receive-pack service' ' |
| 109 | sed -e " |
| 110 | s/^.* \"// |
| 111 | s/\"// |
| 112 | s/ [1-9][0-9]*\$// |
| 113 | s/^GET /GET / |
| 114 | " >act <"$HTTPD_ROOT_PATH"/access.log && |
| 115 | test_cmp exp act |
| 116 | ' |
| 117 | |
Tay Ray Chuan | 6cbd6e9 | 2010-03-02 18:49:26 +0800 | [diff] [blame] | 118 | test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
| 119 | "$ROOT_PATH"/test_repo_clone master |
Tay Ray Chuan | 1945237 | 2010-01-08 10:12:40 +0800 | [diff] [blame] | 120 | |
Tay Ray Chuan | 08d63a4 | 2010-01-08 10:12:44 +0800 | [diff] [blame] | 121 | test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' ' |
Tay Ray Chuan | 7b69079 | 2010-01-08 10:12:41 +0800 | [diff] [blame] | 122 | # create a dissimilarly-named remote ref so that git is unable to match the |
| 123 | # two refs (viz. local, remote) unless an explicit refspec is provided. |
| 124 | git push origin master:retsam |
| 125 | |
| 126 | echo "change changed" > path2 && |
| 127 | git commit -a -m path2 --amend && |
| 128 | |
| 129 | # push master too; this ensures there is at least one '"'push'"' command to |
| 130 | # the remote helper and triggers interaction with the helper. |
Brandon Casey | 77b5be2 | 2010-07-20 13:27:55 -0500 | [diff] [blame] | 131 | test_must_fail git push -v origin +master master:retsam >output 2>&1 && |
Tay Ray Chuan | 7b69079 | 2010-01-08 10:12:41 +0800 | [diff] [blame] | 132 | |
| 133 | grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output && |
| 134 | grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output && |
| 135 | |
Tay Ray Chuan | 9567f08 | 2010-01-25 15:42:23 +0800 | [diff] [blame] | 136 | grep "To prevent you from losing history, non-fast-forward updates were rejected" \ |
| 137 | output |
Tay Ray Chuan | 7b69079 | 2010-01-08 10:12:41 +0800 | [diff] [blame] | 138 | ' |
| 139 | |
Shawn O. Pearce | 7da4e22 | 2009-10-30 17:47:47 -0700 | [diff] [blame] | 140 | stop_httpd |
| 141 | test_done |