t2101: modernize test style
[gitweb.git] / t / t5570-git-daemon.sh
index d76269a8fc96a874042cd2e070794e2c56577468..0d4c52016b2b3651fa638fcc416f22d236c87fc2 100755 (executable)
@@ -6,6 +6,12 @@ test_description='test fetching over git protocol'
 . "$TEST_DIRECTORY"/lib-git-daemon.sh
 start_git_daemon
 
+check_verbose_connect () {
+       grep -F "Looking up 127.0.0.1 ..." stderr &&
+       grep -F "Connecting to 127.0.0.1 (port " stderr &&
+       grep -F "done." stderr
+}
+
 test_expect_success 'setup repository' '
        git config push.default matching &&
        echo content >file &&
@@ -24,7 +30,8 @@ test_expect_success 'create git-accessible bare repository' '
 '
 
 test_expect_success 'clone git repository' '
-       git clone "$GIT_DAEMON_URL/repo.git" clone &&
+       git clone -v "$GIT_DAEMON_URL/repo.git" clone 2>stderr &&
+       check_verbose_connect &&
        test_cmp file clone/file
 '
 
@@ -32,10 +39,21 @@ test_expect_success 'fetch changes via git protocol' '
        echo content >>file &&
        git commit -a -m two &&
        git push public &&
-       (cd clone && git pull) &&
+       (cd clone && git pull -v) 2>stderr &&
+       check_verbose_connect &&
        test_cmp file clone/file
 '
 
+test_expect_success 'no-op fetch -v stderr is as expected' '
+       (cd clone && git fetch -v) 2>stderr &&
+       check_verbose_connect
+'
+
+test_expect_success 'no-op fetch without "-v" is quiet' '
+       (cd clone && git fetch 2>../stderr) &&
+       ! test -s stderr
+'
+
 test_expect_success 'remote detects correct HEAD' '
        git push public master:other &&
        (cd clone &&
@@ -149,23 +167,48 @@ test_expect_success 'access repo via interpolated hostname' '
        git init --bare "$repo" &&
        git push "$repo" HEAD &&
        >"$repo"/git-daemon-export-ok &&
-       rm -rf tmp.git &&
        GIT_OVERRIDE_VIRTUAL_HOST=localhost \
-               git clone --bare "$GIT_DAEMON_URL/interp.git" tmp.git &&
-       rm -rf tmp.git &&
+               git ls-remote "$GIT_DAEMON_URL/interp.git" &&
        GIT_OVERRIDE_VIRTUAL_HOST=LOCALHOST \
-               git clone --bare "$GIT_DAEMON_URL/interp.git" tmp.git
+               git ls-remote "$GIT_DAEMON_URL/interp.git"
 '
 
 test_expect_success 'hostname cannot break out of directory' '
-       rm -rf tmp.git &&
        repo="$GIT_DAEMON_DOCUMENT_ROOT_PATH/../escape.git" &&
        git init --bare "$repo" &&
        git push "$repo" HEAD &&
        >"$repo"/git-daemon-export-ok &&
        test_must_fail \
                env GIT_OVERRIDE_VIRTUAL_HOST=.. \
-               git clone --bare "$GIT_DAEMON_URL/escape.git" tmp.git
+               git ls-remote "$GIT_DAEMON_URL/escape.git"
+'
+
+test_expect_success 'daemon log records all attributes' '
+       cat >expect <<-\EOF &&
+       Extended attribute "host": localhost
+       Extended attribute "protocol": version=1
+       EOF
+       >daemon.log &&
+       GIT_OVERRIDE_VIRTUAL_HOST=localhost \
+               git -c protocol.version=1 \
+                       ls-remote "$GIT_DAEMON_URL/interp.git" &&
+       grep -i extended.attribute daemon.log | cut -d" " -f2- >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
+       {
+               printf "git-upload-pack /interp.git\n\0host=localhost" | packetize
+               printf "0000"
+       } >input &&
+       fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&
+       depacketize <output >output.raw &&
+
+       # just pick out the value of master, which avoids any protocol
+       # particulars
+       perl -lne "print \$1 if m{^(\\S+) refs/heads/master}" <output.raw >actual &&
+       git -C "$repo" rev-parse master >expect &&
+       test_cmp expect actual
 '
 
 stop_git_daemon