File: make_test_repo

package info (click to toggle)
datalad 1.1.5-2.1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 7,140 kB
  • sloc: python: 69,392; sh: 1,521; makefile: 220
file content (132 lines) | stat: -rwxr-xr-x 3,460 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
#emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
#ex: set sts=4 ts=4 sw=4 noet:
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
#   See COPYING file distributed along with the datalad package for the
#   copyright and license terms.
#
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
# DEPRECATED!!!!!  Kept for references
#
set -e
#set -x
set -u

GH_ORG=datalad
GH_PREFIX=testrepo--

topdir=$(dirname `which $0 | xargs readlink -f `)/../..
topdir=$(readlink -f $topdir)
reposdir=$topdir/datalad/tests/testrepos

# So we could use special custom remotes
export PATH=$topdir/bin:$PATH PYTHONPATH=$topdir

flavor="$1"
name="$2"

# Repo specific variables
descr="datalad test repo $flavor/$name"
repodir=$reposdir/$flavor/$name
ghrepo=${GH_ORG}/${GH_PREFIX}$flavor--$name

# Information about the system
git_version=$(git --version | sed -e 's,.* \([0-9]\),\1,g')
annex_version=$(dpkg -l git-annex | awk '/^ii/{print $3;}')

_info() {
	echo "I: $@"
}

create_info_file() {
	cat >| $repodir/INFO.txt <<EOF
git: $git_version
annex: $annex_version
EOF
	git add $repodir/INFO.txt
}

rm_repo() {
	_info "removing $repodir"
	chmod +w -R $repodir/.git  # inefficient but for us sufficient
	rm -rf $repodir
}

create_repo() {
	_info "creating $repodir"
	mkdir -p $repodir
	cd $repodir
	git init
	git annex init $descr
}

create_github_repo() {
	_info "creating github repo"
	cd $repodir
	# it wouldn't delete or complain in exit code if exists already
	hub create -d "$descr (otherwise userless)" $ghrepo
	git remote | grep -q '^origin' || git remote add origin https://github.com/$ghrepo
	git push --set-upstream --all -f origin
}

flavor_basic() {
	create_repo
	create_info_file
	echo "123" > test.dat
	git add test.dat
	git commit -m "Adding a basic INFO file and rudimentary load file for annex testing"
	create_github_repo
#	cp test.dat test-annex.dat
#	git annex add test-annex.dat
	git annex addurl --file=test-annex.dat https://raw.githubusercontent.com/$ghrepo/master/test.dat
	git commit -m "Adding a rudimentary git-annex load file"
	git annex drop test-annex.dat # since available from github
	git push --all origin # and push again
}

initremote_archive() {
	git annex initremote annexed-archives \
	    encryption=none type=external externaltype=dl+archive
}

flavor_archive() {
	create_repo
	initremote_archive
	create_info_file
	mkdir -p d; echo "123" > d/test.dat; tar -czf d.tar.gz d;
    mv d/test.dat test2.dat; rm -rf d;
	git annex add d.tar.gz
	git commit -m "Added tarball"
	key=$(git annex lookupkey d.tar.gz)
	git annex add test2.dat
	git commit -m "Added the load file"
	git annex addurl --file test2.dat dl+archive:$key/d/test.dat
	_info "Added the dl+archive URL, committing"
	#git commit -m "Added a url for the file"
	git annex drop --force test2.dat # TODO -- should work without force
	git annex get test2.dat
}

if [ -e $repodir ]; then
	# TODO -- ask
	rm_repo
fi

register_repo_submodule() {
	cd $reposdir
	_info "registering git submodule"
	# TODO: verify if not registered already
	#git submodule ...
	git submodule add --force https://github.com/$ghrepo ./$flavor/$name && \
		git commit -m "Added test $flavor/$name" -a && \
		git push origin
}

# cd datalad/tests/testrepos
# hub create -d "Super-submodule collating test repositories for datalad" datalad/testrepos

eval flavor_$flavor

#register_repo_submodule