summaryrefslogtreecommitdiff
path: root/eclass/tests/git-r3.sh
blob: 3de6f059752fe424c86b142031cab503f2d5b6ae (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

source tests-common.sh

inherit git-r3

testdir=${pkg_root}/git
mkdir "${testdir}" || die "unable to mkdir testdir"
cd "${testdir}" || die "unable to cd to testdir"

EGIT3_STORE_DIR=store
mkdir "${EGIT3_STORE_DIR}" || die "unable to mkdir store"

test_file() {
	local fn=${1}
	local expect=${2}

	if [[ ! -f ${fn} ]]; then
		eerror "${fn} does not exist (not checked out?)"
	else
		local got=$(<"${fn}")

		if [[ ${got} != ${expect} ]]; then
			eerror "${fn}, expected: ${expect}, got: ${got}"
		else
			return 0
		fi
	fi
	return 1
}

test_no_file() {
	local fn=${1}

	if [[ -f ${fn} ]]; then
		eerror "${fn} exists (wtf?!)"
	else
		return 0
	fi
	return 1
}

test_repo_clean() {
	local P=${P}_${FUNCNAME#test_}

	(
		mkdir repo
		cd repo
		git init -q
		echo test > file
		git add file
		git commit -m 1 -q
		echo other-text > file2
		git add file2
		git commit -m 2 -q
	) || die "unable to prepare repo"

	# we need to use an array to preserve whitespace
	local EGIT_REPO_URI=(
		"ext::git daemon --export-all --base-path=. --inetd %G/repo"
	)

	tbegin "fetching from a simple repo"
	(
		git-r3_src_unpack
		test_file "${WORKDIR}/${P}/file" test && \
		test_file "${WORKDIR}/${P}/file2" other-text
	) &>fetch.log

	eend ${?} || cat fetch.log
}

test_repo_revert() {
	local P=${P}_${FUNCNAME#test_}

	(
		cd repo
		git revert -n HEAD^
		git commit -m r1 -q
	) || die "unable to prepare repo"

	# we need to use an array to preserve whitespace
	local EGIT_REPO_URI=(
		"ext::git daemon --export-all --base-path=. --inetd %G/repo"
	)

	tbegin "fetching revert"
	(
		git-r3_src_unpack
		test_no_file "${WORKDIR}/${P}/file" && \
		test_file "${WORKDIR}/${P}/file2" other-text
	) &>fetch.log

	eend ${?} || cat fetch.log
}

test_repo_branch() {
	local P=${P}_${FUNCNAME#test_}

	(
		cd repo
		git branch -q other-branch HEAD^
		git checkout -q other-branch
		echo one-more > file3
		git add file3
		git commit -m 3 -q
		git checkout -q master
	) || die "unable to prepare repo"

	# we need to use an array to preserve whitespace
	local EGIT_REPO_URI=(
		"ext::git daemon --export-all --base-path=. --inetd %G/repo"
	)
	local EGIT_BRANCH=other-branch

	tbegin "switching branches"
	(
		git-r3_src_unpack
		test_file "${WORKDIR}/${P}/file" test && \
		test_file "${WORKDIR}/${P}/file2" other-text && \
		test_file "${WORKDIR}/${P}/file3" one-more
	) &>fetch.log

	eend ${?} || cat fetch.log
}

test_repo_merge() {
	local P=${P}_${FUNCNAME#test_}

	(
		cd repo
		git branch -q one-more-branch HEAD^
		git checkout -q one-more-branch
		echo foobarbaz > file3
		git add file3
		git commit -m 3b -q
		git checkout -q master
		git merge -m 4 -q one-more-branch
	) || die "unable to prepare repo"

	# we need to use an array to preserve whitespace
	local EGIT_REPO_URI=(
		"ext::git daemon --export-all --base-path=. --inetd %G/repo"
	)

	tbegin "fetching a merge commit"
	(
		git-r3_src_unpack
		test_no_file "${WORKDIR}/${P}/file" && \
		test_file "${WORKDIR}/${P}/file2" other-text && \
		test_file "${WORKDIR}/${P}/file3" foobarbaz
	) &>fetch.log

	eend ${?} || cat fetch.log
}

test_repo_revert_merge() {
	local P=${P}_${FUNCNAME#test_}

	(
		cd repo
		git branch -q to-be-reverted
		git checkout -q to-be-reverted
		echo trrm > file3
		git add file3
		git commit -m 5b -q
		git checkout -q master
		echo trrm > file2
		git add file2
		git commit -m 5 -q
		git merge -m 6 -q to-be-reverted
		echo trrm > file
		git add file
		git commit -m 7 -q
		git revert -m 1 -n HEAD^
		git commit -m 7r -q
	) || die "unable to prepare repo"

	# we need to use an array to preserve whitespace
	local EGIT_REPO_URI=(
		"ext::git daemon --export-all --base-path=. --inetd %G/repo"
	)

	tbegin "fetching a revert of a merge commit"
	(
		git-r3_src_unpack
		test_file "${WORKDIR}/${P}/file" trrm && \
		test_file "${WORKDIR}/${P}/file2" trrm && \
		test_file "${WORKDIR}/${P}/file3" foobarbaz
	) &>fetch.log

	eend ${?} || cat fetch.log
}

test_repo_clean
test_repo_revert
test_repo_branch
test_repo_merge
test_repo_revert_merge

texit