Debian Codegraph @

tools/testing/make_test_repo

raw
1 #!/bin/bash
2 #emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
3 #ex: set sts=4 ts=4 sw=4 noet:
4 # ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
5 #
6 # See COPYING file distributed along with the datalad package for the
7 # copyright and license terms.
8 #
9 # ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
10 #
11 # DEPRECATED!!!!! Kept for references
12 #
13 set -e
14 #set -x
15 set -u
16
17 GH_ORG=datalad
18 GH_PREFIX=testrepo--
19
20 topdir=$(dirname `which $0 | xargs readlink -f `)/../..
21 topdir=$(readlink -f $topdir)
22 reposdir=$topdir/datalad/tests/testrepos
23
24 # So we could use special custom remotes
25 export PATH=$topdir/bin:$PATH PYTHONPATH=$topdir
26
27 flavor="$1"
28 name="$2"
29
30 # Repo specific variables
31 descr="datalad test repo $flavor/$name"
32 repodir=$reposdir/$flavor/$name
33 ghrepo=${GH_ORG}/${GH_PREFIX}$flavor--$name
34
35 # Information about the system
36 git_version=$(git --version | sed -e 's,.* \([0-9]\),\1,g')
37 annex_version=$(dpkg -l git-annex | awk '/^ii/{print $3;}')
38
39 _info() {
40 echo "I: $@"
41 }
42
43 create_info_file() {
44 cat >| $repodir/INFO.txt <<EOF
45 git: $git_version
46 annex: $annex_version
47 EOF
48 git add $repodir/INFO.txt
49 }
50
51 rm_repo() {
52 _info "removing $repodir"
53 chmod +w -R $repodir/.git # inefficient but for us sufficient
54 rm -rf $repodir
55 }
56
57 create_repo() {
58 _info "creating $repodir"
59 mkdir -p $repodir
60 cd $repodir
61 git init
62 git annex init $descr
63 }
64
65 create_github_repo() {
66 _info "creating github repo"
67 cd $repodir
68 # it wouldn't delete or complain in exit code if exists already
69 hub create -d "$descr (otherwise userless)" $ghrepo
70 git remote | grep -q '^origin' || git remote add origin https://github.com/$ghrepo
71 git push --set-upstream --all -f origin
72 }
73
74 flavor_basic() {
75 create_repo
76 create_info_file
77 echo "123" > test.dat
78 git add test.dat
79 git commit -m "Adding a basic INFO file and rudimentary load file for annex testing"
80 create_github_repo
81 # cp test.dat test-annex.dat
82 # git annex add test-annex.dat
83 git annex addurl --file=test-annex.dat https://raw.githubusercontent.com/$ghrepo/master/test.dat
84 git commit -m "Adding a rudimentary git-annex load file"
85 git annex drop test-annex.dat # since available from github
86 git push --all origin # and push again
87 }
88
89 initremote_archive() {
90 git annex initremote annexed-archives \
91 encryption=none type=external externaltype=dl+archive
92 }
93
94 flavor_archive() {
95 create_repo
96 initremote_archive
97 create_info_file
98 mkdir -p d; echo "123" > d/test.dat; tar -czf d.tar.gz d;
99 mv d/test.dat test2.dat; rm -rf d;
100 git annex add d.tar.gz
101 git commit -m "Added tarball"
102 key=$(git annex lookupkey d.tar.gz)
103 git annex add test2.dat
104 git commit -m "Added the load file"
105 git annex addurl --file test2.dat dl+archive:$key/d/test.dat
106 _info "Added the dl+archive URL, committing"
107 #git commit -m "Added a url for the file"
108 git annex drop --force test2.dat # TODO -- should work without force
109 git annex get test2.dat
110 }
111
112 if [ -e $repodir ]; then
113 # TODO -- ask
114 rm_repo
115 fi
116
117 register_repo_submodule() {
118 cd $reposdir
119 _info "registering git submodule"
120 # TODO: verify if not registered already
121 #git submodule ...
122 git submodule add --force https://github.com/$ghrepo ./$flavor/$name && \
123 git commit -m "Added test $flavor/$name" -a && \
124 git push origin
125 }
126
127 # cd datalad/tests/testrepos
128 # hub create -d "Super-submodule collating test repositories for datalad" datalad/testrepos
129
130 eval flavor_$flavor
131
132 #register_repo_submodule