about summary refs log tree commit diff
path: root/pkgs/build-support/fetchmtn/builder.sh
blob: c1b0db895bc1016968293aad66f4b54a48229761 (plain) (blame)
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
source $stdenv/setup

set -x

if ! [ -f "$cacheDB" ]; then 
	echo "Creating cache DB $cacheDB"
	mtn --db "$cacheDB" db init
fi

header "getting revision $selector";

done=;
for source in $dbs; do
	if mtn pull --db "$cacheDB" "$source" "${branch}"; then
		revision="$(mtn --db "$cacheDB" au toposort $(mtn --db "$cacheDB" au select "$selector") | tail -1)";
		if [ -n "$revision" ]; then
			if mtn --db "$cacheDB" au get_revision "$revision"; then
				echo "found revision $revision"
				done=1;
			else
				echo "revision $revision does not exist";
			fi
		else
			echo "selector $selector does not match any revision";
		fi
	else
		echo "pulling branch $branch wasn't successful";
	fi;
	if test -n "$done"; then
		break;
	fi;
done;

stopNest;

header "checking out the revision $revision";

if test -n "$done"; then
	mtn checkout --db "$cacheDB" -r "$revision" "$out" -b "${branch}"
else
	echo "Needed revision still not found. Exiting";
	exit 1;
fi;

stopNest

header "clearing _MTN in the output"

rm -rf "$out/_MTN"

stopNest