Merge branch 'ew/git-svn-http-tests'
authorJunio C Hamano <gitster@pobox.com>
Mon, 8 Aug 2016 21:48:34 +0000 (14:48 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Aug 2016 21:48:34 +0000 (14:48 -0700)
Tests for "git svn" have been taught to reuse the lib-httpd test
infrastructure when testing the subversion integration that
interacts with subversion repositories served over the http://
protocol.

* ew/git-svn-http-tests:
git svn: migrate tests to use lib-httpd
t/t91*: do not say how to avoid the tests

1  2 
t/lib-git-svn.sh
t/lib-httpd.sh
t/lib-httpd/apache.conf
t/t9100-git-svn-basic.sh
t/t9120-git-svn-clone-with-percent-escapes.sh
diff --combined t/lib-git-svn.sh
index fb8823224e9ed2452c32e847bf53dbc4da116f1b,9bd06131d65ec41cd93c5d6006850d52c10b8a1d..688313ed5cc40e22b2412c57f98df06e4f3ac0ea
@@@ -1,5 -1,8 +1,5 @@@
  . ./test-lib.sh
  
 -remotes_git_svn=remotes/git""-svn
 -git_svn_id=git""-svn-id
 -
  if test -n "$NO_SVN_TESTS"
  then
        skip_all='skipping git svn tests, NO_SVN_TESTS defined'
@@@ -65,81 -68,22 +65,22 @@@ svn_cmd () 
        svn "$orig_svncmd" --config-dir "$svnconf" "$@"
  }
  
- prepare_httpd () {
-       for d in \
-               "$SVN_HTTPD_PATH" \
-               /usr/sbin/apache2 \
-               /usr/sbin/httpd \
-       ; do
-               if test -f "$d"
-               then
-                       SVN_HTTPD_PATH="$d"
-                       break
-               fi
-       done
-       if test -z "$SVN_HTTPD_PATH"
-       then
-               echo >&2 '*** error: Apache not found'
-               return 1
-       fi
-       for d in \
-               "$SVN_HTTPD_MODULE_PATH" \
-               /usr/lib/apache2/modules \
-               /usr/libexec/apache2 \
-       ; do
-               if test -d "$d"
-               then
-                       SVN_HTTPD_MODULE_PATH="$d"
-                       break
-               fi
-       done
-       if test -z "$SVN_HTTPD_MODULE_PATH"
-       then
-               echo >&2 '*** error: Apache module dir not found'
-               return 1
-       fi
-       if test ! -f "$SVN_HTTPD_MODULE_PATH/mod_dav_svn.so"
-       then
-               echo >&2 '*** error: Apache module "mod_dav_svn" not found'
-               return 1
-       fi
-       repo_base_path="${1-svn}"
-       mkdir "$GIT_DIR"/logs
-       cat > "$GIT_DIR/httpd.conf" <<EOF
- ServerName "git svn test"
- ServerRoot "$GIT_DIR"
- DocumentRoot "$GIT_DIR"
- PidFile "$GIT_DIR/httpd.pid"
- LockFile logs/accept.lock
- Listen 127.0.0.1:$SVN_HTTPD_PORT
- LoadModule dav_module $SVN_HTTPD_MODULE_PATH/mod_dav.so
- LoadModule dav_svn_module $SVN_HTTPD_MODULE_PATH/mod_dav_svn.so
- <Location /$repo_base_path>
-       DAV svn
-       SVNPath "$rawsvnrepo"
- </Location>
- EOF
- }
- start_httpd () {
-       if test -z "$SVN_HTTPD_PORT"
-       then
-               echo >&2 'SVN_HTTPD_PORT is not defined!'
-               return
-       fi
-       prepare_httpd "$1" || return 1
-       "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start
-       svnrepo="http://127.0.0.1:$SVN_HTTPD_PORT/$repo_base_path"
- }
- stop_httpd () {
-       test -z "$SVN_HTTPD_PORT" && return
-       test ! -f "$GIT_DIR/httpd.conf" && return
-       "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k stop
+ maybe_start_httpd () {
+       loc=${1-svn}
+       test_tristate GIT_SVN_TEST_HTTPD
+       case $GIT_SVN_TEST_HTTPD in
+       true)
+               . "$TEST_DIRECTORY"/lib-httpd.sh
+               LIB_HTTPD_SVN="$loc"
+               start_httpd
+               ;;
+       *)
+               stop_httpd () {
+                       : noop
+               }
+               ;;
+       esac
  }
  
  convert_to_rev_db () {
diff --combined t/lib-httpd.sh
index ac2cbee250887759b67898e4a2ce9d9c2708b7bc,ad87e2b9f41524f2a5920eb25e74d1da95e11d0d..435a37465a702c35a5d53d8809f0ef700ae9ff83
@@@ -24,7 -24,7 +24,7 @@@
  #    LIB_HTTPD_MODULE_PATH       web server modules path
  #    LIB_HTTPD_PORT              listening port
  #    LIB_HTTPD_DAV               enable DAV
- #    LIB_HTTPD_SVN               enable SVN
+ #    LIB_HTTPD_SVN               enable SVN at given location (e.g. "svn")
  #    LIB_HTTPD_SSL               enable SSL
  #
  # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
@@@ -162,8 -162,10 +162,10 @@@ prepare_httpd() 
                if test -n "$LIB_HTTPD_SVN"
                then
                        HTTPD_PARA="$HTTPD_PARA -DSVN"
-                       rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo"
-                       svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn"
+                       LIB_HTTPD_SVNPATH="$rawsvnrepo"
+                       svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/"
+                       svnrepo="$svnrepo$LIB_HTTPD_SVN"
+                       export LIB_HTTPD_SVN LIB_HTTPD_SVNPATH
                fi
        fi
  }
@@@ -180,7 -182,6 +182,7 @@@ start_httpd() 
        if test $? -ne 0
        then
                trap 'die' EXIT
 +              cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
                test_skip_or_die $GIT_TEST_HTTPD "web server setup failed"
        fi
  }
diff --combined t/lib-httpd/apache.conf
index 018a83a5a18431f120672b7cd8874bfb72e8d8fb,70c8ee21cbd34ccbadbc95cef9f6b67686557784..c3e631394f4a47f32e62e266431607861929f328
@@@ -102,10 -102,6 +102,10 @@@ Alias /auth/dumb/ www/auth/dumb
        SetEnv GIT_HTTP_EXPORT_ALL
        Header set Set-Cookie name=value
  </LocationMatch>
 +<LocationMatch /smart_headers/>
 +      SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
 +      SetEnv GIT_HTTP_EXPORT_ALL
 +</LocationMatch>
  ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
  ScriptAlias /broken_smart/ broken-smart-http.sh/
  ScriptAlias /error/ error.sh/
@@@ -132,18 -128,6 +132,18 @@@ RewriteRule ^/ftp-redir/(.*)$ ftp://loc
  RewriteRule ^/loop-redir/x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-(.*) /$1 [R=302]
  RewriteRule ^/loop-redir/(.*)$ /loop-redir/x-$1 [R=302]
  
 +# Apache 2.2 does not understand <RequireAll>, so we use RewriteCond.
 +# And as RewriteCond does not allow testing for non-matches, we match
 +# the desired case first (one has abra, two has cadabra), and let it
 +# pass by marking the RewriteRule as [L], "last rule, do not process
 +# any other matching RewriteRules after this"), and then have another
 +# RewriteRule that matches all other cases and lets them fail via '[F]',
 +# "fail the request".
 +RewriteCond %{HTTP:x-magic-one} =abra
 +RewriteCond %{HTTP:x-magic-two} =cadabra
 +RewriteRule ^/smart_headers/.* - [L]
 +RewriteRule ^/smart_headers/.* - [F]
 +
  <IfDefine SSL>
  LoadModule ssl_module modules/mod_ssl.so
  
@@@ -208,8 -192,8 +208,8 @@@ RewriteRule ^/half-auth-complete/ - [E=
  <IfDefine SVN>
        LoadModule dav_svn_module modules/mod_dav_svn.so
  
-       <Location /svn>
+       <Location /${LIB_HTTPD_SVN}>
                DAV svn
-               SVNPath svnrepo
+               SVNPath "${LIB_HTTPD_SVNPATH}"
        </Location>
  </IfDefine>
diff --combined t/t9100-git-svn-basic.sh
index d29f60108a4235feae1068a6ea1a89cc7bee5b4b,4ad5087a12751129dec01b1e4b9513949d7162e2..92a3aa8063f810bd2b8df68f3f0f30c2faf3bdc6
@@@ -8,8 -8,6 +8,6 @@@ GIT_SVN_LC_ALL=${LC_ALL:-$LANG
  
  . ./lib-git-svn.sh
  
- say 'define NO_SVN_TESTS to skip git svn tests'
  case "$GIT_SVN_LC_ALL" in
  *.UTF-8)
        test_set_prereq UTF8
        ;;
  esac
  
 +deepdir=nothing-above
 +ceiling=$PWD
 +
 +test_expect_success 'git svn --version works anywhere' '
 +      mkdir -p "$deepdir" && (
 +              GIT_CEILING_DIRECTORIES="$ceiling" &&
 +              export GIT_CEILING_DIRECTORIES &&
 +              cd "$deepdir" &&
 +              git svn --version
 +      )
 +'
 +
 +test_expect_success 'git svn help works anywhere' '
 +      mkdir -p "$deepdir" && (
 +              GIT_CEILING_DIRECTORIES="$ceiling" &&
 +              export GIT_CEILING_DIRECTORIES &&
 +              cd "$deepdir" &&
 +              git svn help
 +      )
 +'
 +
  test_expect_success \
      'initialize git svn' '
        mkdir import &&
@@@ -66,13 -43,13 +64,13 @@@ test_expect_success "checkout from svn
  
  name='try a deep --rmdir with a commit'
  test_expect_success "$name" '
 -      git checkout -f -b mybranch ${remotes_git_svn} &&
 +      git checkout -f -b mybranch remotes/git-svn &&
        mv dir/a/b/c/d/e/file dir/file &&
        cp dir/file file &&
        git update-index --add --remove dir/a/b/c/d/e/file dir/file file &&
        git commit -m "$name" &&
        git svn set-tree --find-copies-harder --rmdir \
 -              ${remotes_git_svn}..mybranch &&
 +              remotes/git-svn..mybranch &&
        svn_cmd up "$SVN_TREE" &&
        test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'
  
@@@ -86,14 -63,14 +84,14 @@@ test_expect_success "$name" 
        git update-index --add dir/file/file &&
        git commit -m '$name' &&
        test_must_fail git svn set-tree --find-copies-harder --rmdir \
 -              ${remotes_git_svn}..mybranch
 +              remotes/git-svn..mybranch
  "
  
  
  name='detect node change from directory to file #1'
  test_expect_success "$name" '
        rm -rf dir "$GIT_DIR"/index &&
 -      git checkout -f -b mybranch2 ${remotes_git_svn} &&
 +      git checkout -f -b mybranch2 remotes/git-svn &&
        mv bar/zzz zzz &&
        rm -rf bar &&
        mv zzz bar &&
        git update-index --add -- bar &&
        git commit -m "$name" &&
        test_must_fail git svn set-tree --find-copies-harder --rmdir \
 -              ${remotes_git_svn}..mybranch2
 +              remotes/git-svn..mybranch2
  '
  
  
  name='detect node change from file to directory #2'
  test_expect_success "$name" '
        rm -f "$GIT_DIR"/index &&
 -      git checkout -f -b mybranch3 ${remotes_git_svn} &&
 +      git checkout -f -b mybranch3 remotes/git-svn &&
        rm bar/zzz &&
        git update-index --remove bar/zzz &&
        mkdir bar/zzz &&
        git update-index --add bar/zzz/yyy &&
        git commit -m "$name" &&
        git svn set-tree --find-copies-harder --rmdir \
 -              ${remotes_git_svn}..mybranch3 &&
 +              remotes/git-svn..mybranch3 &&
        svn_cmd up "$SVN_TREE" &&
        test -d "$SVN_TREE"/bar/zzz &&
        test -e "$SVN_TREE"/bar/zzz/yyy
  name='detect node change from directory to file #2'
  test_expect_success "$name" '
        rm -f "$GIT_DIR"/index &&
 -      git checkout -f -b mybranch4 ${remotes_git_svn} &&
 +      git checkout -f -b mybranch4 remotes/git-svn &&
        rm -rf dir &&
        git update-index --remove -- dir/file &&
        touch dir &&
        git update-index --add -- dir &&
        git commit -m "$name" &&
        test_must_fail git svn set-tree --find-copies-harder --rmdir \
 -              ${remotes_git_svn}..mybranch4
 +              remotes/git-svn..mybranch4
  '
  
  
  name='remove executable bit from a file'
  test_expect_success POSIXPERM "$name" '
        rm -f "$GIT_DIR"/index &&
 -      git checkout -f -b mybranch5 ${remotes_git_svn} &&
 +      git checkout -f -b mybranch5 remotes/git-svn &&
        chmod -x exec.sh &&
        git update-index exec.sh &&
        git commit -m "$name" &&
        git svn set-tree --find-copies-harder --rmdir \
 -              ${remotes_git_svn}..mybranch5 &&
 +              remotes/git-svn..mybranch5 &&
        svn_cmd up "$SVN_TREE" &&
        test ! -x "$SVN_TREE"/exec.sh'
  
@@@ -156,7 -133,7 +154,7 @@@ test_expect_success POSIXPERM "$name" 
        git update-index exec.sh &&
        git commit -m "$name" &&
        git svn set-tree --find-copies-harder --rmdir \
 -              ${remotes_git_svn}..mybranch5 &&
 +              remotes/git-svn..mybranch5 &&
        svn_cmd up "$SVN_TREE" &&
        test -x "$SVN_TREE"/exec.sh'
  
@@@ -168,7 -145,7 +166,7 @@@ test_expect_success SYMLINKS "$name" 
        git update-index exec.sh &&
        git commit -m "$name" &&
        git svn set-tree --find-copies-harder --rmdir \
 -              ${remotes_git_svn}..mybranch5 &&
 +              remotes/git-svn..mybranch5 &&
        svn_cmd up "$SVN_TREE" &&
        test -h "$SVN_TREE"/exec.sh'
  
@@@ -180,7 -157,7 +178,7 @@@ test_expect_success POSIXPERM,SYMLINKS 
        git update-index --add file exec-2.sh &&
        git commit -m "$name" &&
        git svn set-tree --find-copies-harder --rmdir \
 -              ${remotes_git_svn}..mybranch5 &&
 +              remotes/git-svn..mybranch5 &&
        svn_cmd up "$SVN_TREE" &&
        test -x "$SVN_TREE"/file &&
        test -h "$SVN_TREE"/exec-2.sh'
@@@ -193,7 -170,7 +191,7 @@@ test_expect_success POSIXPERM,SYMLINKS 
        git update-index exec-2.sh &&
        git commit -m "$name" &&
        git svn set-tree --find-copies-harder --rmdir \
 -              ${remotes_git_svn}..mybranch5 &&
 +              remotes/git-svn..mybranch5 &&
        svn_cmd up "$SVN_TREE" &&
        test -f "$SVN_TREE"/exec-2.sh &&
        test ! -h "$SVN_TREE"/exec-2.sh &&
@@@ -215,7 -192,7 +213,7 @@@ GIT_SVN_ID=al
  export GIT_SVN_ID
  test_expect_success "$name" \
      'git svn init "$svnrepo" && git svn fetch &&
 -     git rev-list --pretty=raw ${remotes_git_svn} | grep ^tree | uniq > a &&
 +     git rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a &&
       git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
       test_cmp a b'
  
@@@ -238,17 -215,17 +236,17 @@@ EO
  
  test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp a expected"
  
 -test_expect_success 'exit if remote refs are ambigious' "
 +test_expect_success 'exit if remote refs are ambigious' '
          git config --add svn-remote.svn.fetch \
 -                              bar:refs/${remotes_git_svn} &&
 +              bar:refs/remotes/git-svn &&
        test_must_fail git svn migrate
 -"
 +'
  
  test_expect_success 'exit if init-ing a would clobber a URL' '
          svnadmin create "${PWD}/svnrepo2" &&
          svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
          git config --unset svn-remote.svn.fetch \
 -                                "^bar:refs/${remotes_git_svn}$" &&
 +              "^bar:refs/remotes/git-svn$" &&
        test_must_fail git svn init "${svnrepo}2/bar"
          '
  
@@@ -258,7 -235,7 +256,7 @@@ test_expect_success 
          git config --get svn-remote.svn.fetch \
                                "^bar:refs/remotes/bar$" &&
          git config --get svn-remote.svn.fetch \
 -                              "^:refs/${remotes_git_svn}$"
 +                            "^:refs/remotes/git-svn$"
          '
  
  test_expect_success 'dcommit $rev does not clobber current branch' '
        git branch -D my-bar
        '
  
 -test_expect_success 'able to dcommit to a subdirectory' "
 +test_expect_success 'able to dcommit to a subdirectory' '
        git svn fetch -i bar &&
        git checkout -b my-bar refs/remotes/bar &&
        echo abc > d &&
        git update-index --add d &&
 -      git commit -m '/bar/d should be in the log' &&
 +      git commit -m "/bar/d should be in the log" &&
        git svn dcommit -i bar &&
 -      test -z \"\$(git diff refs/heads/my-bar refs/remotes/bar)\" &&
 +      test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
        mkdir newdir &&
        echo new > newdir/dir &&
        git update-index --add newdir/dir &&
 -      git commit -m 'add a new directory' &&
 +      git commit -m "add a new directory" &&
        git svn dcommit -i bar &&
 -      test -z \"\$(git diff refs/heads/my-bar refs/remotes/bar)\" &&
 +      test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
        echo foo >> newdir/dir &&
        git update-index newdir/dir &&
 -      git commit -m 'modify a file in new directory' &&
 +      git commit -m "modify a file in new directory" &&
        git svn dcommit -i bar &&
 -      test -z \"\$(git diff refs/heads/my-bar refs/remotes/bar)\"
 -      "
 +      test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
 +'
  
  test_expect_success 'dcommit should not fail with a touched file' '
        test_commit "commit-new-file-foo2" foo2 &&
@@@ -312,13 -289,13 +310,13 @@@ test_expect_success 'rebase should not 
        git svn rebase
  '
  
 -test_expect_success 'able to set-tree to a subdirectory' "
 +test_expect_success 'able to set-tree to a subdirectory' '
        echo cba > d &&
        git update-index d &&
 -      git commit -m 'update /bar/d' &&
 +      git commit -m "update /bar/d" &&
        git svn set-tree -i bar HEAD &&
 -      test -z \"\$(git diff refs/heads/my-bar refs/remotes/bar)\"
 -      "
 +      test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
 +'
  
  test_expect_success 'git-svn works in a bare repository' '
        mkdir bare-repo &&
index 59465b147eb9cdc7da1fb891ff695cbc4442209a,f911a68f9e35f1855b7c0896f6902fd51c617299..b28a1741e3f52296dcab35ed6d51fa01c2628652
@@@ -15,14 -15,14 +15,14 @@@ test_expect_success 'setup svnrepo' 
        svn_cmd cp -m "tag" "$svnrepo/pr ject/trunk" \
          "$svnrepo/pr ject/tags/v1" &&
        rm -rf project &&
-       start_httpd
+       maybe_start_httpd
  '
  
  test_expect_success 'test clone with percent escapes' '
        git svn clone "$svnrepo/pr%20ject" clone &&
        (
                cd clone &&
 -              git rev-parse refs/${remotes_git_svn}
 +              git rev-parse refs/remotes/git-svn
        )
  '
  
@@@ -42,7 -42,7 +42,7 @@@ test_expect_success 'test clone trunk w
        git svn clone --minimize-url "$svnrepo/pr%20ject/trunk" minimize &&
        (
                cd minimize &&
 -              git rev-parse refs/${remotes_git_svn}
 +              git rev-parse refs/remotes/git-svn
        )
  '
  
@@@ -50,7 -50,7 +50,7 @@@ test_expect_success 'test clone trunk w
        git svn clone "$svnrepo/pr%20ject/trunk" trunk &&
        (
                cd trunk &&
 -              git rev-parse refs/${remotes_git_svn}
 +              git rev-parse refs/remotes/git-svn
        )
  '