t / t5545-push-options.shon commit test-lib: make "-x" work with "--verbose-log" (f5ba2de)
   1#!/bin/sh
   2
   3test_description='pushing to a repository using push options'
   4
   5. ./test-lib.sh
   6
   7mk_repo_pair () {
   8        rm -rf workbench upstream &&
   9        test_create_repo upstream &&
  10        test_create_repo workbench &&
  11        (
  12                cd upstream &&
  13                git config receive.denyCurrentBranch warn &&
  14                mkdir -p .git/hooks &&
  15                cat >.git/hooks/pre-receive <<-'EOF' &&
  16                #!/bin/sh
  17                if test -n "$GIT_PUSH_OPTION_COUNT"; then
  18                        i=0
  19                        >hooks/pre-receive.push_options
  20                        while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
  21                                eval "value=\$GIT_PUSH_OPTION_$i"
  22                                echo $value >>hooks/pre-receive.push_options
  23                                i=$((i + 1))
  24                        done
  25                fi
  26                EOF
  27                chmod u+x .git/hooks/pre-receive
  28
  29                cat >.git/hooks/post-receive <<-'EOF' &&
  30                #!/bin/sh
  31                if test -n "$GIT_PUSH_OPTION_COUNT"; then
  32                        i=0
  33                        >hooks/post-receive.push_options
  34                        while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
  35                                eval "value=\$GIT_PUSH_OPTION_$i"
  36                                echo $value >>hooks/post-receive.push_options
  37                                i=$((i + 1))
  38                        done
  39                fi
  40                EOF
  41                chmod u+x .git/hooks/post-receive
  42        ) &&
  43        (
  44                cd workbench &&
  45                git remote add up ../upstream
  46        )
  47}
  48
  49# Compare the ref ($1) in upstream with a ref value from workbench ($2)
  50# i.e. test_refs second HEAD@{2}
  51test_refs () {
  52        test $# = 2 &&
  53        git -C upstream rev-parse --verify "$1" >expect &&
  54        git -C workbench rev-parse --verify "$2" >actual &&
  55        test_cmp expect actual
  56}
  57
  58test_expect_success 'one push option works for a single branch' '
  59        mk_repo_pair &&
  60        git -C upstream config receive.advertisePushOptions true &&
  61        (
  62                cd workbench &&
  63                test_commit one &&
  64                git push --mirror up &&
  65                test_commit two &&
  66                git push --push-option=asdf up master
  67        ) &&
  68        test_refs master master &&
  69        echo "asdf" >expect &&
  70        test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
  71        test_cmp expect upstream/.git/hooks/post-receive.push_options
  72'
  73
  74test_expect_success 'push option denied by remote' '
  75        mk_repo_pair &&
  76        git -C upstream config receive.advertisePushOptions false &&
  77        (
  78                cd workbench &&
  79                test_commit one &&
  80                git push --mirror up &&
  81                test_commit two &&
  82                test_must_fail git push --push-option=asdf up master
  83        ) &&
  84        test_refs master HEAD@{1}
  85'
  86
  87test_expect_success 'two push options work' '
  88        mk_repo_pair &&
  89        git -C upstream config receive.advertisePushOptions true &&
  90        (
  91                cd workbench &&
  92                test_commit one &&
  93                git push --mirror up &&
  94                test_commit two &&
  95                git push --push-option=asdf --push-option="more structured text" up master
  96        ) &&
  97        test_refs master master &&
  98        printf "asdf\nmore structured text\n" >expect &&
  99        test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
 100        test_cmp expect upstream/.git/hooks/post-receive.push_options
 101'
 102
 103test_expect_success 'push options and submodules' '
 104        test_when_finished "rm -rf parent" &&
 105        test_when_finished "rm -rf parent_upstream" &&
 106        mk_repo_pair &&
 107        git -C upstream config receive.advertisePushOptions true &&
 108        cp -r upstream parent_upstream &&
 109        test_commit -C upstream one &&
 110
 111        test_create_repo parent &&
 112        git -C parent remote add up ../parent_upstream &&
 113        test_commit -C parent one &&
 114        git -C parent push --mirror up &&
 115
 116        git -C parent submodule add ../upstream workbench &&
 117        git -C parent/workbench remote add up ../../upstream &&
 118        git -C parent commit -m "add submoule" &&
 119
 120        test_commit -C parent/workbench two &&
 121        git -C parent add workbench &&
 122        git -C parent commit -m "update workbench" &&
 123
 124        git -C parent push \
 125                --push-option=asdf --push-option="more structured text" \
 126                --recurse-submodules=on-demand up master &&
 127
 128        git -C upstream rev-parse --verify master >expect &&
 129        git -C parent/workbench rev-parse --verify master >actual &&
 130        test_cmp expect actual &&
 131
 132        git -C parent_upstream rev-parse --verify master >expect &&
 133        git -C parent rev-parse --verify master >actual &&
 134        test_cmp expect actual &&
 135
 136        printf "asdf\nmore structured text\n" >expect &&
 137        test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
 138        test_cmp expect upstream/.git/hooks/post-receive.push_options &&
 139        test_cmp expect parent_upstream/.git/hooks/pre-receive.push_options &&
 140        test_cmp expect parent_upstream/.git/hooks/post-receive.push_options
 141'
 142
 143. "$TEST_DIRECTORY"/lib-httpd.sh
 144start_httpd
 145
 146test_expect_success 'push option denied properly by http server' '
 147        test_when_finished "rm -rf test_http_clone" &&
 148        test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
 149        mk_repo_pair &&
 150        git -C upstream config receive.advertisePushOptions false &&
 151        git -C upstream config http.receivepack true &&
 152        cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
 153        git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
 154        test_commit -C test_http_clone one &&
 155        test_must_fail git -C test_http_clone push --push-option=asdf origin master 2>actual &&
 156        test_i18ngrep "the receiving end does not support push options" actual &&
 157        git -C test_http_clone push origin master
 158'
 159
 160test_expect_success 'push options work properly across http' '
 161        test_when_finished "rm -rf test_http_clone" &&
 162        test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
 163        mk_repo_pair &&
 164        git -C upstream config receive.advertisePushOptions true &&
 165        git -C upstream config http.receivepack true &&
 166        cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
 167        git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
 168
 169        test_commit -C test_http_clone one &&
 170        git -C test_http_clone push origin master &&
 171        git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
 172        git -C test_http_clone rev-parse --verify master >actual &&
 173        test_cmp expect actual &&
 174
 175        test_commit -C test_http_clone two &&
 176        git -C test_http_clone push --push-option=asdf --push-option="more structured text" origin master &&
 177        printf "asdf\nmore structured text\n" >expect &&
 178        test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options &&
 179        test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options &&
 180
 181        git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
 182        git -C test_http_clone rev-parse --verify master >actual &&
 183        test_cmp expect actual
 184'
 185
 186stop_httpd
 187
 188test_done