diff options
Diffstat (limited to 'tests')
29 files changed, 918 insertions, 81 deletions
diff --git a/tests/buildfile b/tests/buildfile index 1d7ede2..4716658 100644 --- a/tests/buildfile +++ b/tests/buildfile @@ -5,7 +5,8 @@ define common: file common{*}: extension = test -commons = common config auth remote +commons = common config auth remote \ + remote-git rep-fetch-git rep-fetch-git-branch rep-fetch-git-commit # The common/ directory contains repositories that are reused, being symlinked # in source repositories specific for testscripts. diff --git a/tests/common/git/README b/tests/common/git/README new file mode 100644 index 0000000..eac6765 --- /dev/null +++ b/tests/common/git/README @@ -0,0 +1,104 @@ +1. Local repositories. + +To modify the repositories that are used for git repository tests run + +$ ./init --unpack + +before modification, and + +$ ./pack + +afterwrds. + +Also note that config files under .git/ subdirectory refer to the submodule +repositories using absolute paths. So prior to pulling in subproject directory +(say in state0/libfoo.git/doc/style) you need to run the following commands, +to make sure that the repository references match their current locations: + +$ git -C style.git submodule sync --recursive +$ git -C libfoo.git submodule sync --recursive + + +2. Remote repositories. + +To bootstrap the remote repositories run the following commands on build2.org +host. + +$ cd /var/scm + +Create repositories, providing the proper project description: + +# bpkg test repository with doc basic style library (initial state) +# +$ ./mkrepo testing/bpkg/unadv/rep-fetch/state0/style-basic.git + +# bpkg test repository with doc style library (initial state) +# +$ ./mkrepo testing/bpkg/unadv/rep-fetch/state0/style.git + +# bpkg test repository with libbar library (initial state) +# +$ ./mkrepo testing/bpkg/unadv/rep-fetch/state0/libbar.git + +# bpkg test repository with libfoo library (initial state) +# +$ ./mkrepo testing/bpkg/unadv/rep-fetch/state0/libfoo.git + +# bpkg test repository with doc basic style library (final state) +# +$ ./mkrepo testing/bpkg/unadv/rep-fetch/state1/style-basic.git + +# bpkg test repository with doc style library (final state) +# +$ ./mkrepo testing/bpkg/unadv/rep-fetch/state1/style.git + +# bpkg test repository with libbaz library (final state) +# +$ ./mkrepo testing/bpkg/unadv/rep-fetch/state1/libbaz.git + +# bpkg test repository with libfoo library (final state) +# +$ ./mkrepo testing/bpkg/unadv/rep-fetch/state1/libfoo.git + + +# bpkg test repository with doc basic style library (advonly, initial state) +# +$ ./mkrepo testing/bpkg/advonly/rep-fetch/state0/style-basic.git + +# bpkg test repository with doc style library (advonly, initial state) +# +$ ./mkrepo testing/bpkg/advonly/rep-fetch/state0/style.git + +# bpkg test repository with libbar library (advonly, initial state) +# +$ ./mkrepo testing/bpkg/advonly/rep-fetch/state0/libbar.git + +# bpkg test repository with libfoo library (advonly, initial state) +# +$ ./mkrepo testing/bpkg/advonly/rep-fetch/state0/libfoo.git + +# bpkg test repository with doc basic style library (advonly, final state) +# +$ ./mkrepo testing/bpkg/advonly/rep-fetch/state1/style-basic.git + +# bpkg test repository with doc style library (advonly, final state) +# +$ ./mkrepo testing/bpkg/advonly/rep-fetch/state1/style.git + +# bpkg test repository with libbaz library (advonly, final state) +# +$ ./mkrepo testing/bpkg/advonly/rep-fetch/state1/libbaz.git + +# bpkg test repository with libfoo library (advonly, final state) +# +$ ./mkrepo testing/bpkg/advonly/rep-fetch/state1/libfoo.git + +Add configuration options: + +$ for d in $(find . -type d -regex '\./testing/bpkg/.*/[^/]+\.git'); do \ + git -C $d config receive.denyDeleteCurrent ignore \ +done + +$ for d in $(find . -type d -regex '\./testing/bpkg/advonly/.*/[^/]+\.git'); do \ + git -C $d config uploadpack.allowAnySHA1InWant false \ +done diff --git a/tests/common/git/init b/tests/common/git/init new file mode 100755 index 0000000..c999347 --- /dev/null +++ b/tests/common/git/init @@ -0,0 +1,171 @@ +#! /bin/sh + +# Create git repositories from project directories/tarballs. +# +# Usage example: +# +# ./init [--unpack] +# +owd=`pwd` +trap "{ cd $owd; exit 1; }" ERR +set -o errtrace # Trap in functions. + +function info () { echo "$*" 1>&2; } +function error () { info "error: $*"; exit 1; } +function trace () { if [ "$verbose" == 'y' ]; then info "trace: $*"; fi } + +unpack= + +while [ $# -gt 0 ]; do + case $1 in + --unpack) + unpack='y' + shift + ;; + *) + error "invalid option $1" + ;; + esac +done + +# Unpack repositories if requested. +# +if [ -n "$unpack" ]; then + for f in */*.tar; do + rm -r -f ${f%.tar}.git + tar xf $f; + done +fi + +# Create the initial state of the repositories libfoo.git, libbar.git, +# style.git, and style-basic.git. +# +cd state0 + +rm -f -r libfoo.git/.git +rm -f libfoo.git/.gitmodules +rm -f libfoo.git/README +rm -f -r libfoo.git/libbar +rm -f -r libfoo.git/doc/style + +rm -f -r libbar.git/.git + +rm -f -r style.git/.git +rm -f -r style.git/basic + +rm -f -r style-basic.git/.git +rm -f style-basic.git/README +rm -f style-basic.git/INSTALL + +# Create master branch for style-basic.git. +# +git -C style-basic.git init +git -C style-basic.git add '*' +git -C style-basic.git commit -am 'Create' + +# Create stable branch for style-basic. +# +git -C style-basic.git branch stable +git -C style-basic.git checkout stable +touch style-basic.git/README +git -C style-basic.git add README +git -C style-basic.git commit -am 'README' + +# Create master branch for style.git, adding style-basic.git as a submodule. +# +git -C style.git init +git -C style.git add '*' +git -C style.git submodule add ../style-basic.git basic # The stable branch. +git -C style.git commit -am 'Create' + +# Make style.git to refer an unadvertised reference, commiting into the stable +# branch of style-basic.git. +# +touch style-basic.git/INSTALL +git -C style-basic.git add INSTALL +git -C style-basic.git commit -am 'INSTALL' +git -C style-basic.git checkout master + +# Create master branch for libbar.git. +# +git -C libbar.git init +git -C libbar.git add '*' +git -C libbar.git commit -am 'Create' + +# Create master branch for libfoo.git, adding style.git and libbar.git as +# submodules. +# +git -C libfoo.git init +git -C libfoo.git add '*' +git -C libfoo.git submodule add ../style.git doc/style +git -C libfoo.git submodule add ../libbar.git libbar +git -C libfoo.git submodule update --init --recursive # Updates doc/style/basic. +git -C libfoo.git commit -am 'Create' + +# Add tags for libfoo.git. +# +git -C libfoo.git tag 'lightweight_tag' +git -C libfoo.git tag -a 'annotated_tag' -m 'annotated_tag' + +# Advance the master branch to make tags not to mark a branch tip. +# +touch libfoo.git/README +git -C libfoo.git add README +git -C libfoo.git commit -am 'README' + +# Create the modified state of the repositories, replacing libbar.git submodule +# of libfoo with the newly created libbaz.git repository. Also advance master +# branches and tags for libfoo.git and it's submodule style.git. +# +cd ../state1 + +# Copy repositories initial state. +# +for d in ../state0/*.git; do + rm -f -r $(basename $d) + cp -r $d . +done + +# Create libbaz.git repository. +# +rm -f -r libbaz.git/.git + +git -C libbaz.git init +git -C libbaz.git add '*' +git -C libbaz.git commit -am 'Create' + +# Sync submodule references with their new locations. +# +for d in *.git; do + git -C $d submodule sync --recursive +done + +# Advance style.git master branch. +# +touch style.git/README +git -C style.git add README +git -C style.git commit -am 'README' + +# Advance libfoo.git master branch. +# +git -C libfoo.git submodule update --init --remote # Pull style only. +git -C libfoo.git commit -am 'Update style' + +git -C libfoo.git rm -r tests +git -C libfoo.git commit -am 'Remove tests' + +git -C libfoo.git submodule deinit libbar +git -C libfoo.git rm libbar +git -C libfoo.git commit -am 'Remove libbar' +rm -f -r libbar.git + +git -C libfoo.git submodule add ../libbaz.git libbaz +git -C libfoo.git submodule update --init libbaz +git -C libfoo.git commit -am 'Add libbaz' + +git -C libfoo.git tag -f 'lightweight_tag' +git -C libfoo.git tag -f -a 'annotated_tag' -m 'annotated_tag' + +touch libfoo.git/INSTALL +git -C libfoo.git add INSTALL +git -C libfoo.git commit -am 'INSTALL' diff --git a/tests/common/git/pack b/tests/common/git/pack new file mode 100755 index 0000000..f53e794 --- /dev/null +++ b/tests/common/git/pack @@ -0,0 +1,29 @@ +#! /bin/sh + +# Move git projects to tar archives. +# +# Usage example: +# +# ./pack +# +owd=`pwd` +trap "{ cd $owd; exit 1; }" ERR +set -o errtrace # Trap in functions. + +function info () { echo "$*" 1>&2; } +function error () { info "$*"; exit 1; } + +projects=('state0/libfoo' 'state0/libbar' 'state0/style' 'state0/style-basic' \ + 'state1/libfoo' 'state1/libbaz' 'state1/style' 'state1/style-basic') + +for p in "${projects[@]}"; do + d=$p.git + if [ ! -d $d ]; then + error "$d directory not found" + fi + + git -C $d submodule sync --recursive + + tar cf $p.tar $d + rm -r -f $d +done diff --git a/tests/common/git/state0/libbar.tar b/tests/common/git/state0/libbar.tar Binary files differnew file mode 100644 index 0000000..4eff7d2 --- /dev/null +++ b/tests/common/git/state0/libbar.tar diff --git a/tests/common/git/state0/libfoo.tar b/tests/common/git/state0/libfoo.tar Binary files differnew file mode 100644 index 0000000..3938070 --- /dev/null +++ b/tests/common/git/state0/libfoo.tar diff --git a/tests/common/git/state0/style-basic.tar b/tests/common/git/state0/style-basic.tar Binary files differnew file mode 100644 index 0000000..aabbbcd --- /dev/null +++ b/tests/common/git/state0/style-basic.tar diff --git a/tests/common/git/state0/style.tar b/tests/common/git/state0/style.tar Binary files differnew file mode 100644 index 0000000..1821210 --- /dev/null +++ b/tests/common/git/state0/style.tar diff --git a/tests/common/git/state1/libbaz.tar b/tests/common/git/state1/libbaz.tar Binary files differnew file mode 100644 index 0000000..de6e3d9 --- /dev/null +++ b/tests/common/git/state1/libbaz.tar diff --git a/tests/common/git/state1/libfoo.tar b/tests/common/git/state1/libfoo.tar Binary files differnew file mode 100644 index 0000000..ac5d10d --- /dev/null +++ b/tests/common/git/state1/libfoo.tar diff --git a/tests/common/git/state1/style-basic.tar b/tests/common/git/state1/style-basic.tar Binary files differnew file mode 100644 index 0000000..94dc12b --- /dev/null +++ b/tests/common/git/state1/style-basic.tar diff --git a/tests/common/git/state1/style.tar b/tests/common/git/state1/style.tar Binary files differnew file mode 100644 index 0000000..9e997ae --- /dev/null +++ b/tests/common/git/state1/style.tar diff --git a/tests/common/libfoo-1.1.0/build/bootstrap.build b/tests/common/libfoo-1.1.0/build/bootstrap.build index 54f267e..eb90fee 100644 --- a/tests/common/libfoo-1.1.0/build/bootstrap.build +++ b/tests/common/libfoo-1.1.0/build/bootstrap.build @@ -1,2 +1,2 @@ -project = fetch-libfoo +project = libfoo using config diff --git a/tests/pkg-clean.test b/tests/pkg-clean.test index 18c2a79..6f393af 100644 --- a/tests/pkg-clean.test +++ b/tests/pkg-clean.test @@ -67,7 +67,8 @@ $* 2>>EOE != 0 : { +$clone_cfg - +$rep_add $rep/hello && $rep_fetch --trust $cert_fp &cfg/.bpkg/certs/*** + +$rep_add $rep/hello + +$rep_fetch --trust $cert_fp &cfg/.bpkg/certificates/** : no-such-package : diff --git a/tests/pkg-configure.test b/tests/pkg-configure.test index d67e289..4253cf5 100644 --- a/tests/pkg-configure.test +++ b/tests/pkg-configure.test @@ -101,7 +101,8 @@ $* libhello libhello 2>>EOE != 0 : { +$clone_cfg - +$rep_add $rep/hello && $rep_fetch --trust $cert_fp &cfg/.bpkg/certs/*** + +$rep_add $rep/hello + +$rep_fetch --trust $cert_fp &cfg/.bpkg/certificates/** : no-such-package : diff --git a/tests/pkg-fetch.test b/tests/pkg-fetch.test index 3d5b40b..6ee2043 100644 --- a/tests/pkg-fetch.test +++ b/tests/pkg-fetch.test @@ -187,7 +187,8 @@ $* libfoo/1.0.0 2>>/EOE != 0 : { $clone_cfg; - $rep_add $rep/hello && $rep_fetch --trust $cert_fp &cfg/.bpkg/certs/***; + $rep_add $rep/hello; + $rep_fetch --trust $cert_fp &cfg/.bpkg/certificates/**; $* libhello/1.0.0 2>>~%EOE%; %.* diff --git a/tests/pkg-unpack.test b/tests/pkg-unpack.test index 83fa9a6..236744f 100644 --- a/tests/pkg-unpack.test +++ b/tests/pkg-unpack.test @@ -185,7 +185,7 @@ $* 2>>EOE != 0 : { $clone_cfg; - $rep_add $rep/hello && $rep_fetch --trust $cert_fp &cfg/.bpkg/certs/***; + $rep_add $rep/hello && $rep_fetch --trust $cert_fp &cfg/.bpkg/certificates/**; $pkg_fetch libhello/1.0.0; $* libhello 2>'unpacked libhello/1.0.0'; diff --git a/tests/pkg-update.test b/tests/pkg-update.test index 4e92650..2d82934 100644 --- a/tests/pkg-update.test +++ b/tests/pkg-update.test @@ -71,7 +71,8 @@ $* 2>>EOE != 0 : { +$clone_cfg - +$rep_add $rep/hello && $rep_fetch --trust $cert_fp &cfg/.bpkg/certs/*** + +$rep_add $rep/hello + +$rep_fetch --trust $cert_fp &cfg/.bpkg/certificates/** : no-such-package : diff --git a/tests/publish b/tests/publish index 3a6b0d8..253c703 100755 --- a/tests/publish +++ b/tests/publish @@ -1,4 +1,4 @@ -#!/bin/sh +#! /usr/bin/env bash # Some commonly useful addtional options that can be specified via the # command line: @@ -6,6 +6,24 @@ # --dry-run # --progress # +owd=`pwd` +trap "{ cd $owd; exit 1; }" ERR +set -o errtrace # Trap in functions. + +echo_git= + +# Keep arguments intact for the future use with rsync. +# +for o in "$@"; do + case $o in + --dry-run) + echo_git=echo + ;; + esac +done + +# Publish bpkg test repositories. +# rsync -v -rlpt --copy-unsafe-links \ --prune-empty-dirs --delete-after --delete-excluded $* \ --include '*/' \ @@ -15,3 +33,53 @@ rsync -v -rlpt --copy-unsafe-links \ --include 'signature' \ --exclude '*' \ test/*/pkg/1/build2.org/ build2.org:/var/pkg/1/ + +# Publish git test repositories. +# +urls=('git.build2.org:/var/scm/testing/bpkg/unadv' \ + 'git.build2.org:/var/scm/testing/bpkg/advonly') + +# Find git repository directories to publish. +# +for r in $(find test -type d -regex '.*/git/.*/[^/]+\.git'); do + br="${r/\/git\//\/git-bare\/}" # Bare repository directory. + + # Make base repositories from the test ones. + # + rm -r -f $br + mkdir -p $(dirname $br) + + git clone --bare $r $br + + # Subdirectory that is relative to git-bare/. + # + d=$(echo $br | sed -n -e 's%.*/git-bare/\(.*\)%\1%p') + + for u in "${urls[@]}"; do + + # Point the bare repository origin to the remote repository. + # + git -C $br config remote.origin.url "$u/$d" + + # Delete all remote branches and tags. + # + while read commit ref; do + $echo_git git -C $br push origin ":$ref" + done < <(git -C $br ls-remote --refs origin) + + # Push local branches. + # + while read branch; do + $echo_git git -C $br push --tags origin "$branch:$branch" + done < <(git -C $br for-each-ref --format='%(refname:short)' 'refs/heads/') + done + + # Prepare the bare repository for serving via the HTTPS dumb protocol. + # + git -C $br update-server-info --force +done + +# Publish git repositories that are served via the HTTPS dumb protocol. +# +rsync -v -rlpt --copy-unsafe-links --delete-after $* \ +test/*/git-bare/ build2.org:/var/pkg/git/ diff --git a/tests/remote-git.test b/tests/remote-git.test new file mode 100644 index 0000000..24b31e4 --- /dev/null +++ b/tests/remote-git.test @@ -0,0 +1,35 @@ +# file : tests/remote-git.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Tests for commands that accept git repository location must be able to run +# regardless whether the repository is local or remote. They also must be able +# to create the repository used for testing at the specified path, so being +# published to build2.org it can be used for the remote testing. Note that +# prior to publishing repositories tests must be performed with the +# config.test.output=keep variable override, so their working directories (that +# contain repositories produced) are not cleaned up. +# + +# Output directory path that testscripts must use to prepare repositories +# required by tests they contains. +# +out_git = $canonicalize([dir_path] $~/git/$cmd) + +# If $remote is true then remote repositories locations must be used for +# tests. +# +remote = $config.bpkg.test.remote + ++if ($remote != true) + rep_git_local = ($cxx.target.class != 'windows' \ + ? "file://$out_git" \ + : "file:/$regex.replace($out_git, '\\', '/')") + + mkdir -p $out_git +else + rep_git_https_dumb = "https://build2.org/bpkg/git/$cmd" + rep_git_https_smart = "https://git.build2.org/testing/bpkg/advonly/$cmd" + rep_git_https_smart_unadv = "https://git.build2.org/testing/bpkg/unadv/$cmd" + rep_git_git = "git://git.build2.org/testing/bpkg/unadv/$cmd" +end diff --git a/tests/remote.test b/tests/remote.test index fdd3fbb..581d8be 100644 --- a/tests/remote.test +++ b/tests/remote.test @@ -2,7 +2,7 @@ # copyright : Copyright (c) 2014-2017 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -# Tests for commands that accept repository location must be able to run +# Tests for commands that accept bpkg repository location must be able to run # regardless whether the repository is local or remote. They also must be able # to create the repository used for testing at the specified path, so being # published to build2.org it can be used for the remote testing. Note that diff --git a/tests/rep-add.test b/tests/rep-add.test index 4e203cc..a84f725 100644 --- a/tests/rep-add.test +++ b/tests/rep-add.test @@ -38,7 +38,7 @@ : git-no-branch : $* 'git://example.org/repo' 2>>EOE != 0 - error: invalid git repository location 'git://example.org/repo': missing branch/tag for git repository + error: invalid git repository location 'git://example.org/repo': missing branch/tag or commit id for git repository EOE : bpkg-git-scheme @@ -88,7 +88,7 @@ $clone_cfg && mkdir -p repo/.git; $* 'repo' 2>>~%EOE% != 0 - %error: invalid git repository location '.+repo': missing branch/tag for git repository% + %error: invalid git repository location '.+repo': missing branch/tag or commit id for git repository% EOE : file-bpkg @@ -107,11 +107,11 @@ $clone_cfg; $* ./1/bar/stable 2>>/~%EOE%; - %added repository .+/relative-path/bar/stable% + %added repository bpkg:.+/relative-path/bar/stable% EOE $* ./1/../1/bar/stable 2>>/~%EOE% != 0 - %error: .+/relative-path/bar/stable is already a repository of this configuration% + %error: bpkg:.+/relative-path/bar/stable is already a repository of this configuration% EOE } @@ -121,17 +121,21 @@ $clone_cfg; $* $~/1/foo/stable 2>>/~%EOE%; - %added repository .+/absolute-path/foo/stable% + %added repository bpkg:.+/absolute-path/foo/stable% EOE $* $~/1/../1/foo/stable 2>>/~%EOE% != 0 - %error: .+/absolute-path/foo/stable is already a repository of this configuration% + %error: bpkg:.+/absolute-path/foo/stable is already a repository of this configuration% EOE } : remote-url : { + +$clone_cfg + + : bpkg + : $clone_cfg; $* 'http://pkg.example.org/1/testing' 2>>~%EOE%; @@ -141,4 +145,16 @@ $* 'https://www.example.org/1/testing' 2>>~%EOE% != 0 %error: bpkg:example.org/testing is already a repository of this configuration% EOE + + : git + : + $clone_cfg; + + $* 'git://example.org/testing#master' 2>>~%EOE%; + %added repository git:example.org/testing% + EOE + + $* 'git://www.example.org/testing#master' 2>>~%EOE% != 0 + %error: git:example.org/testing is already a repository of this configuration% + EOE } diff --git a/tests/rep-auth.test b/tests/rep-auth.test index 5fa3568..b0c28cf 100644 --- a/tests/rep-auth.test +++ b/tests/rep-auth.test @@ -165,7 +165,7 @@ sc = " " # Space character to append to here-document line when required. : { +$clone_root_cfg && $rep_add $rep/signed - rep_fetch += --auth all &?cfg/.bpkg/certs/*** + rep_fetch += --auth all &?cfg/.bpkg/certificates/** : no-auth : @@ -312,8 +312,11 @@ sc = " " # Space character to append to here-document line when required. $clone_root_cfg; rep_info += -d cfg; - $rep_info --trust "$cert_fp" &cfg/.bpkg/certs/*** >'name:build2.org'; - $rep_info >'name:build2.org' + $rep_info --trust "$cert_fp" &cfg/.bpkg/certificates/** >>EOO; + name:build2.org + EOO + + $rep_info >'name:build2.org' } } diff --git a/tests/rep-fetch-git-branch.test b/tests/rep-fetch-git-branch.test new file mode 100644 index 0000000..94ca70e --- /dev/null +++ b/tests/rep-fetch-git-branch.test @@ -0,0 +1,152 @@ +# file : tests/rep-fetch-git-branch.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +reason_dumb = ' (dumb HTTP)' +reason_unadv = ' (unadvertised commit)' + +warn_dumb=' +warning: fetching over dumb HTTP, no progress will be displayed' + +: clone +: +{ + $clone_root_cfg && $rep_add "$rep/state0/libfoo.git#$branch"; + + # Note that the commit for doc/style/basic submodule is not at the branch tip + # and so is not advertised. + # + if ($git_protocol == 'local' || \ + $git_protocol == 'https-smart' || \ + $git_protocol == 'git') + warn1 = '%.{0}' + warn2 = '%.{0}' + warn3 = "warning: fetching whole repository history for submodule 'doc/style/basic'$reason_unadv" + fetch = '%.{0}' + warn4 = '%.{0}' + elif ($git_protocol == 'https-dumb') + warn1 = "warning: fetching whole branch history$reason_dumb$warn_dumb" + warn2 = "warning: fetching whole repository history for submodule 'doc/style'$reason_dumb$warn_dumb" + warn3 = "warning: fetching whole repository history for submodule 'doc/style/basic'$reason_dumb$warn_dumb" + fetch = '%.{0}' + warn4 = "warning: fetching whole repository history for submodule 'libbar'$reason_dumb$warn_dumb" + elif ($git_protocol == 'https-smart-unadv') + warn1 = '%.{0}' + warn2 = '%.{0}' + warn3 = '%.{0}' + fetch = "%Fetching in '.+style/basic'.+%" + warn4 = '%.{0}' + end; + + $* 2>>~"%EOE%" + %fetching git:.+libfoo% + $warn1 + %Cloning into '.+$branch'.+% + %Submodule 'doc/style' .+ registered for path 'doc/style'% + %Submodule 'libbar' .+ registered for path 'libbar'% + $warn2 + %Cloning into '.+doc/style'.+% + %Submodule path 'doc/style': checked out .+% + %Submodule 'basic' .+ registered for path 'doc/style/basic'% + $warn3 + %Cloning into '.+doc/style/basic'.+% + $fetch + %Submodule path 'doc/style/basic': checked out .+% + $warn4 + %Cloning into '.+libbar'.+% + %Submodule path 'libbar': checked out .+% + 0 package\(s\) in 1 repository\(s\) + EOE +} + +: fetch +: +{ + : unchanged + : + { + $clone_root_cfg && $rep_add "$rep/state0/libfoo.git#$branch"; + $* >! 2>!; + + if ($git_protocol == 'https-dumb') + warn = "warning: fetching whole branch history$reason_dumb$warn_dumb" + else + warn = '%.{0}' + end; + + $* 2>>~"%EOE%" + %fetching git:.+libfoo% + $warn + %Fetching in '.+$branch'.+% + 0 package\(s\) in 1 repository\(s\) + EOE + } + + : changed + : + { + g = git -C + u = "$rep_git/state1" + + $clone_root_cfg && $rep_add "$rep/state0/libfoo.git#$branch"; + + # Extract the repository path from the output line like this: + # + # Cloning into 'cfg\.bpkg\tmp\f9be881264703b5d\master'... + # + $* 2>&1 | sed -n -e "s/Cloning into '\(.+$branch\)'\.{3}/\$1/p" | \ + sed -n -e 's%(.+[\\/])tmp([\\/].+)%$1repositories$2%p' | \ + set r; + + $g "$r" config remote.origin.url "$u/libfoo.git"; + + $g "$r" config submodule.libbar.url "$u/libbar.git"; + $g "$r" config submodule.doc/style.url "$u/style.git"; + + $g "$r/libbar" config remote.origin.url "$u/libbar.git"; + + $g "$r/doc/style" config remote.origin.url "$u/style.git"; + $g "$r/doc/style" config submodule.basic.url "$u/style-basic.git"; + + $g "$r/doc/style/basic" config remote.origin.url "$u/style-basic.git"; + + # Preconditions. + # + test -f $r/tests/TODO; + test -f $r/libbar/manifest; + test -f $r/doc/style/README != 0; + test -d $r/libbaz != 0; + + if ($git_protocol == 'https-dumb') + warn1 = "warning: fetching whole branch history$reason_dumb$warn_dumb" + warn2 = "warning: fetching whole repository history for submodule 'doc/style'$reason_dumb$warn_dumb" + warn3 = "warning: fetching whole repository history for submodule 'libbaz'$reason_dumb$warn_dumb" + else + warn1 = '%.{0}' + warn2 = '%.{0}' + warn3 = '%.{0}' + end; + + $* 2>>~"%EOE%" 1>&2; + %fetching git:.+libfoo% + $warn1 + %Fetching in '.+$branch'.+% + %warning: unable to rmdir '?libbar'?:.+% + %Submodule 'libbaz' .+ registered for path 'libbaz'% + $warn2 + %Fetching in '.+doc/style'.+% + %Submodule path 'doc/style': checked out .+% + $warn3 + %Cloning into '.+libbaz'.+% + %Submodule path 'libbaz': checked out .+% + 0 package\(s\) in 1 repository\(s\) + EOE + + # Postconditions. + # + test -d $r/tests != 0; + test -d $r/libbar != 0; + test -f $r/doc/style/README; + test -f $r/libbaz/manifest + } +} diff --git a/tests/rep-fetch-git-commit.test b/tests/rep-fetch-git-commit.test new file mode 100644 index 0000000..d0d757c --- /dev/null +++ b/tests/rep-fetch-git-commit.test @@ -0,0 +1,124 @@ +# file : tests/rep-fetch-git-commit.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +reason_dumb = ' (dumb HTTP)' +reason_unadv = ' (unadvertised commit)' + +warn_dumb=' +warning: fetching over dumb HTTP, no progress will be displayed' + + +git clone "$rep_git/state0/style-basic.git" 2>! &style-basic/*** + +: unadvertised +: +{ + +git -C ../style-basic log '--pretty=format:%H' --all --grep='README' | \ + set commit + + : no-branch + : + { + $clone_root_cfg && $rep_add "$rep/state0/style-basic.git#@$commit"; + + if ($git_protocol == 'https-smart-unadv') + warn = '%.{0}' + fetch = "%Fetching in '.+$commit'.+%" + else + warn = "warning: fetching whole repository history" + + if ($git_protocol == 'https-dumb') + warn = "$warn$reason_dumb$warn_dumb" + else + warn = "$warn$reason_unadv" + end + + fetch = '%.{0}' + end; + + $* 2>>~"%EOE%" + %fetching git:.+style-basic% + $warn + %Cloning into '.+$commit'.+% + $fetch + 0 package\(s\) in 1 repository\(s\) + EOE + } + + : branch + : + { + $clone_root_cfg && $rep_add "$rep/state0/style-basic.git#stable@$commit"; + + if ($git_protocol == 'https-smart-unadv') + warn = '%.{0}' + fetch = "%Fetching in '.+stable'.+%" + else + warn = "warning: fetching whole branch history" + + if ($git_protocol == 'https-dumb') + warn = "$warn$reason_dumb$warn_dumb" + else + warn = "$warn$reason_unadv" + end + + fetch = '%.{0}' + end; + + $* 2>>~"%EOE%" + %fetching git:.+style-basic% + $warn + %Cloning into '.+stable'.+% + $fetch + 0 package\(s\) in 1 repository\(s\) + EOE + } +} + +: advertised +: +{ + +git -C ../style-basic log '--pretty=format:%H' --all --grep='INSTALL' | \ + set commit + + : no-branch + : + { + $clone_root_cfg && $rep_add "$rep/state0/style-basic.git#@$commit"; + + if ($git_protocol == 'https-dumb') + warn = "warning: fetching whole repository history$reason_dumb$warn_dumb" + fetch = '%.{0}' + else + warn = '%.{0}' + fetch = "%Fetching in '.+$commit'.+%" + end; + + $* 2>>~"%EOE%" + %fetching git:.+style-basic% + $warn + %Cloning into '.+$commit'.+% + $fetch + 0 package\(s\) in 1 repository\(s\) + EOE + } + + : branch + : + { + $clone_root_cfg && $rep_add "$rep/state0/style-basic.git#stable@$commit"; + + if ($git_protocol == 'https-dumb') + warn ="warning: fetching whole branch history$reason_dumb$warn_dumb" + else + warn = '%.{0}' + end; + + $* 2>>~"%EOE%" + %fetching git:.+style-basic% + $warn + %Cloning into '.+stable'.+% + 0 package\(s\) in 1 repository\(s\) + EOE + } +} diff --git a/tests/rep-fetch-git.test b/tests/rep-fetch-git.test new file mode 100644 index 0000000..1330d20 --- /dev/null +++ b/tests/rep-fetch-git.test @@ -0,0 +1,62 @@ +# file : tests/rep-fetch-git.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# All tests use the same repository infrastructure present in the initial and +# the final states. See tests/common/git/init script for more details. +# + +rep_add += --type git -d cfg 2>! +test.cleanups += &cfg/.bpkg/repositories/*/*** + ++if ($git_protocol == 'local') + rep = "$rep_git_local" +elif ($git_protocol == 'https-dumb') + rep = "$rep_git_https_dumb" +elif ($git_protocol == 'https-smart') + rep = "$rep_git_https_smart" +elif ($git_protocol == 'https-smart-unadv') + rep = "$rep_git_https_smart_unadv" +elif ($git_protocol == 'git') + rep = "$rep_git_git" +else + exit "unexpected git protocol '$git_protocol'" +end + +# Repository URL prefix for use with git commands. +# +# Note that git supports none of the standard 'file:' URL notations on Windows, +# so we produce one that is acceptable for git. +# ++if ($git_protocol == 'local' && $cxx.target.class == 'windows') + rep_git = "$regex.replace($rep, '^file:/', 'file://')" +else + rep_git = "$rep" +end + +: branch +: +{ + branch = 'master' + .include rep-fetch-git-branch.test +} + +: lightweight-tag +: +{ + branch = 'lightweight_tag' + .include rep-fetch-git-branch.test +} + +: annotated-tag +: +{ + branch = 'annotated_tag' + .include rep-fetch-git-branch.test +} + +: commit +: +{ + .include rep-fetch-git-commit.test +} diff --git a/tests/rep-fetch.test b/tests/rep-fetch.test index c9f026d..e18c8fa 100644 --- a/tests/rep-fetch.test +++ b/tests/rep-fetch.test @@ -2,7 +2,7 @@ # copyright : Copyright (c) 2014-2017 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -.include common.test auth.test config.test remote.test +.include common.test auth.test config.test remote.test remote-git.test # Source repository: # @@ -19,6 +19,7 @@ # | | ../foo/testing (prerequisite) # | |-- libbar-1.1.1.tar.gz -> libfoo >= 1.1.0 # | `-- repositories +# | # |-- foo # | |-- stable # | | |-- libfoo-1.0.0.tar.gz @@ -26,9 +27,12 @@ # | `-- testing -> stable (complement) # | |-- libfoo-1.1.0.tar.gz # | `-- repositories +# | # `-- hello -# |-- libhello-1.0.0.tar.gz -# `-- repositories +# | |-- libhello-1.0.0.tar.gz +# | `-- repositories +# | +# `-- git/* (see rep-fetch-git.test) # Prepare repositories used by tests if running in the local mode. # @@ -53,11 +57,27 @@ $rep_create $out/bar/stable &$out/bar/stable/packages $rep_create $out/bar/testing &$out/bar/testing/packages $rep_create $out/bar/unstable &$out/bar/unstable/packages -end - -test.options += --auth all -rep_add += -d cfg 2>! + # Create git repositories. + # + # Note that we can expect that the tar program is present on the platform. We + # will use the same options as we do for unpacking of bpkg packages (see + # pkg-unpack.cxx). + # + x = ($cxx.target.class != 'windows' \ + ? tar -C $out_git -xf \ + : tar -C $regex.replace($out_git, '\\', '/') --force-local -xf) + + $x $src/git/state0/libfoo.tar + $x $src/git/state0/libbar.tar + $x $src/git/state0/style.tar + $x $src/git/state0/style-basic.tar &$out_git/state0/*** + + $x $src/git/state1/libfoo.tar + $x $src/git/state1/libbaz.tar + $x $src/git/state1/style.tar + $x $src/git/state1/style-basic.tar &$out_git/state1/*** +end : no-repositories : @@ -67,68 +87,114 @@ $* 2>>/EOE != 0 info: use 'bpkg rep-add' to add a repository EOE -: hello +: bpkg-repositories : { - $clone_cfg && $rep_add $rep/hello; - - $* --trust $cert_fp 2>>EOE &cfg/.bpkg/certs/***; - fetching bpkg:build2.org/rep-fetch/hello - 1 package(s) in 1 repository(s) - EOE - - $* 2>>EOE - fetching bpkg:build2.org/rep-fetch/hello - 1 package(s) in 1 repository(s) - EOE + test.options += --auth all + + rep_add += -d cfg 2>! + + : hello + : + { + $clone_root_cfg && $rep_add $rep/hello; + + $* --trust $cert_fp 2>>EOE &cfg/.bpkg/certificates/**; + fetching bpkg:build2.org/rep-fetch/hello + 1 package(s) in 1 repository(s) + EOE + + $* 2>>EOE + fetching bpkg:build2.org/rep-fetch/hello + 1 package(s) in 1 repository(s) + EOE + } + + : bar-unstable + : + { + $clone_root_cfg && $rep_add $rep/bar/unstable; + + $* --trust-yes 2>>EOE; + fetching bpkg:build2.org/rep-fetch/bar/unstable + fetching bpkg:build2.org/rep-fetch/foo/testing (prerequisite of bpkg:build2.org/rep-fetch/bar/unstable) + fetching bpkg:build2.org/rep-fetch/foo/stable (complements bpkg:build2.org/rep-fetch/foo/testing) + fetching bpkg:build2.org/rep-fetch/bar/testing (complements bpkg:build2.org/rep-fetch/bar/unstable) + fetching bpkg:build2.org/rep-fetch/bar/stable (complements bpkg:build2.org/rep-fetch/bar/testing) + 5 package(s) in 5 repository(s) + EOE + + $* 2>>EOE + fetching bpkg:build2.org/rep-fetch/bar/unstable + fetching bpkg:build2.org/rep-fetch/foo/testing (prerequisite of bpkg:build2.org/rep-fetch/bar/unstable) + fetching bpkg:build2.org/rep-fetch/foo/stable (complements bpkg:build2.org/rep-fetch/foo/testing) + fetching bpkg:build2.org/rep-fetch/bar/testing (complements bpkg:build2.org/rep-fetch/bar/unstable) + fetching bpkg:build2.org/rep-fetch/bar/stable (complements bpkg:build2.org/rep-fetch/bar/testing) + 5 package(s) in 5 repository(s) + EOE + } + + : both + : + { + $clone_root_cfg && $rep_add $rep/hello && $rep_add $rep/bar/unstable; + + $* --trust-yes 2>>EOE &cfg/.bpkg/certificates/**; + fetching bpkg:build2.org/rep-fetch/bar/unstable + fetching bpkg:build2.org/rep-fetch/foo/testing (prerequisite of bpkg:build2.org/rep-fetch/bar/unstable) + fetching bpkg:build2.org/rep-fetch/foo/stable (complements bpkg:build2.org/rep-fetch/foo/testing) + fetching bpkg:build2.org/rep-fetch/bar/testing (complements bpkg:build2.org/rep-fetch/bar/unstable) + fetching bpkg:build2.org/rep-fetch/bar/stable (complements bpkg:build2.org/rep-fetch/bar/testing) + fetching bpkg:build2.org/rep-fetch/hello + 6 package(s) in 6 repository(s) + EOE + + $* 2>>EOE + fetching bpkg:build2.org/rep-fetch/bar/unstable + fetching bpkg:build2.org/rep-fetch/foo/testing (prerequisite of bpkg:build2.org/rep-fetch/bar/unstable) + fetching bpkg:build2.org/rep-fetch/foo/stable (complements bpkg:build2.org/rep-fetch/foo/testing) + fetching bpkg:build2.org/rep-fetch/bar/testing (complements bpkg:build2.org/rep-fetch/bar/unstable) + fetching bpkg:build2.org/rep-fetch/bar/stable (complements bpkg:build2.org/rep-fetch/bar/testing) + fetching bpkg:build2.org/rep-fetch/hello + 6 package(s) in 6 repository(s) + EOE + } } -: bar-unstable +: git-repositories : +if ($remote != true) { - $clone_cfg && $rep_add $rep/bar/unstable; - - $* --trust-yes 2>>EOE; - fetching bpkg:build2.org/rep-fetch/bar/unstable - fetching bpkg:build2.org/rep-fetch/foo/testing (prerequisite of bpkg:build2.org/rep-fetch/bar/unstable) - fetching bpkg:build2.org/rep-fetch/foo/stable (complements bpkg:build2.org/rep-fetch/foo/testing) - fetching bpkg:build2.org/rep-fetch/bar/testing (complements bpkg:build2.org/rep-fetch/bar/unstable) - fetching bpkg:build2.org/rep-fetch/bar/stable (complements bpkg:build2.org/rep-fetch/bar/testing) - 5 package(s) in 5 repository(s) - EOE - - $* 2>>EOE - fetching bpkg:build2.org/rep-fetch/bar/unstable - fetching bpkg:build2.org/rep-fetch/foo/testing (prerequisite of bpkg:build2.org/rep-fetch/bar/unstable) - fetching bpkg:build2.org/rep-fetch/foo/stable (complements bpkg:build2.org/rep-fetch/foo/testing) - fetching bpkg:build2.org/rep-fetch/bar/testing (complements bpkg:build2.org/rep-fetch/bar/unstable) - fetching bpkg:build2.org/rep-fetch/bar/stable (complements bpkg:build2.org/rep-fetch/bar/testing) - 5 package(s) in 5 repository(s) - EOE + git_protocol = 'local' + .include rep-fetch-git.test } - -: both -: +else { - $clone_cfg && $rep_add $rep/hello && $rep_add $rep/bar/unstable; - - $* --trust-yes 2>>EOE &cfg/.bpkg/certs/***; - fetching bpkg:build2.org/rep-fetch/bar/unstable - fetching bpkg:build2.org/rep-fetch/foo/testing (prerequisite of bpkg:build2.org/rep-fetch/bar/unstable) - fetching bpkg:build2.org/rep-fetch/foo/stable (complements bpkg:build2.org/rep-fetch/foo/testing) - fetching bpkg:build2.org/rep-fetch/bar/testing (complements bpkg:build2.org/rep-fetch/bar/unstable) - fetching bpkg:build2.org/rep-fetch/bar/stable (complements bpkg:build2.org/rep-fetch/bar/testing) - fetching bpkg:build2.org/rep-fetch/hello - 6 package(s) in 6 repository(s) - EOE - - $* 2>>EOE - fetching bpkg:build2.org/rep-fetch/bar/unstable - fetching bpkg:build2.org/rep-fetch/foo/testing (prerequisite of bpkg:build2.org/rep-fetch/bar/unstable) - fetching bpkg:build2.org/rep-fetch/foo/stable (complements bpkg:build2.org/rep-fetch/foo/testing) - fetching bpkg:build2.org/rep-fetch/bar/testing (complements bpkg:build2.org/rep-fetch/bar/unstable) - fetching bpkg:build2.org/rep-fetch/bar/stable (complements bpkg:build2.org/rep-fetch/bar/testing) - fetching bpkg:build2.org/rep-fetch/hello - 6 package(s) in 6 repository(s) - EOE + : https-dumb + : + { + git_protocol = 'https-dumb' + .include rep-fetch-git.test + } + + : https-smart + : + { + git_protocol = 'https-smart' + .include rep-fetch-git.test + } + + : https-smart-unadv + : + { + git_protocol = 'https-smart-unadv' + .include rep-fetch-git.test + } + + : git + : + { + git_protocol = 'git' + .include rep-fetch-git.test + } } diff --git a/tests/rep-fetch/git/state0 b/tests/rep-fetch/git/state0 new file mode 120000 index 0000000..cfd06e4 --- /dev/null +++ b/tests/rep-fetch/git/state0 @@ -0,0 +1 @@ +../../common/git/state0
\ No newline at end of file diff --git a/tests/rep-fetch/git/state1 b/tests/rep-fetch/git/state1 new file mode 120000 index 0000000..7543de7 --- /dev/null +++ b/tests/rep-fetch/git/state1 @@ -0,0 +1 @@ +../../common/git/state1
\ No newline at end of file |