]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: docker tests only need a workdir, not a clone
authorLoic Dachary <ldachary@redhat.com>
Sun, 7 Dec 2014 12:27:16 +0000 (13:27 +0100)
committerLoic Dachary <ldachary@redhat.com>
Sat, 13 Dec 2014 11:17:34 +0000 (12:17 +0100)
Instead of cloning the repository, create a work directory that has
symbolic links to the original .git, using

https://github.com/git/git/blob/master/contrib/workdir/git-new-workdir

It resolves the problem of fetching a commit that is not attached to any
ref, which is apparently not implemented in the git protocol (discussed
on irc.freenode.net#git).

http://tracker.ceph.com/issues/10264 Fixes: #10264

Signed-off-by: Loic Dachary <ldachary@redhat.com>
src/test/docker-test-helper.sh

index 6daab47200e41653bf6eeebbefed1368a1817f3d..ff5289d9d5c9448bd68ef0464446f2b47580129f 100755 (executable)
@@ -21,10 +21,6 @@ function get_image_name() {
     echo ceph-$os_type-$os_version
 }
 
-function get_branch() {
-    git rev-parse --abbrev-ref HEAD
-}
-
 function compile_ubuntu() {
     cat <<EOF
 set -ex
@@ -65,14 +61,17 @@ function setup_container() {
     fi
 }
 
+function get_upstream() {
+    git rev-parse --show-toplevel
+}
+
 function get_downstream() {
     local os_type=$1
     local os_version=$2
 
     local image=$(get_image_name $os_type $os_version)
-    local root=$(git rev-parse --show-toplevel)
-    local dir=$(dirname $root)
-    local upstream=$(basename $root)
+    local upstream=$(get_upstream)
+    local dir=$(dirname $upstream)
     echo "$dir/$image"
 }
 
@@ -81,24 +80,31 @@ function setup_downstream() {
     local os_version=$2
 
     local image=$(get_image_name $os_type $os_version)
-    local root=$(git rev-parse --show-toplevel)
-    local branch=$(get_branch)
-    local dir=$(dirname $root)
-    local upstream=$(basename $root)
+    local upstream=$(get_upstream)
+    local dir=$(dirname $upstream)
     local downstream=$(get_downstream $os_type $os_version)
+    local commit=$(git rev-parse HEAD)
     
     (
         cd $dir
         if ! test -d $downstream ; then
-            git clone $upstream $downstream || return 1
-            cd $downstream
-            git checkout -b docker-build origin/$branch || return 1
-            git submodule update --init || return 1
-        else
-            cd $downstream
+            # Inspired by https://github.com/git/git/blob/master/contrib/workdir/git-new-workdir
+            mkdir -p $downstream/.git || return 1
+            for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache
+            do
+               case $x in
+                   */*)
+                       mkdir -p "$downstream/.git/$x"
+                       ;;
+               esac
+               ln -s "$upstream/.git/$x" "$downstream/.git/$x"
+                cp "$upstream/.git/HEAD" "$downstream/.git/HEAD"
+            done
         fi
-        git fetch origin
-        git reset --hard origin/$branch || return 1
+        cd $downstream
+        git reset --hard $commit || return 1
+        git submodule sync || return 1
+        git submodule update --init || return 1
     )
 }
 
@@ -119,6 +125,7 @@ function run_in_docker() {
     setup_container $os_type $os_version "$opts" || return 1
     local downstream=$(get_downstream $os_type $os_version)
     local image=$(get_image_name $os_type $os_version)
+    local upstream=$(get_upstream)
     local ccache
     if test -d $HOME/.ccache ; then
         ccache="--volume $HOME/.ccache:$HOME/.ccache"
@@ -133,7 +140,9 @@ function run_in_docker() {
     else
         user=
     fi
-    local cmd="docker run $opts --rm --name $image --privileged $ccache --volume $downstream:$downstream"
+    local cmd="docker run $opts --rm --name $image --privileged $ccache"
+    cmd+=" --volume $downstream:$downstream"
+    cmd+=" --volume $upstream:$upstream"
     local status=0
     if test "$script" = "bash" ; then
         $cmd --tty --interactive --workdir $downstream $user $dev $image bash