Commit Diff


commit - 0b41df0a1d24e9d24c582a7f2906c835b7050f074a3f7028cf74c616534e81e3
commit + f7321f76f782d54a93e0e4c48db2cf7c83bbfd92405a544d12aa110eb48caf83
blob - 726727e433080131b3ce0415d4673bddeafbfe1f5f4dc2eb20efc14c8eb25efa
blob + d11e5cc622139290c79cc1cb2cc59a39cfebf0733c8a157429e1402bb7fc636e
--- gotwebd/gotweb.c	
+++ gotwebd/gotweb.c	
@@ -474,8 +474,7 @@ gotweb_serve_website(struct request *c, struct website
 	if (site->branch_name[0] != 0) {
 		const char *branch = site->branch_name;
 
-		if (strncmp("refs/", branch, 5) != 0) {
-			branch += 5;
+		if (strncmp("refs/heads/", branch, 11) != 0) {
 			if (asprintf(&refname, "refs/heads/%s", branch) == -1) {
 				error = got_error_from_errno("asprintf");
 				goto done;
blob - 12797213e1fda98dcad71d5d8d467a802bddd70c795750d624d7087b8fe48ae8
blob + 63adf8d558081735aa12a9459864c179f6bd40b90bff1d872033f9f0251ee21a
--- regress/gotsysd/test_gotwebd_www.sh	
+++ regress/gotsysd/test_gotwebd_www.sh	
@@ -185,5 +185,142 @@ EOF
 	test_done "$testroot" "$ret"
 }
 
+test_website_on_branch() {
+	local testroot=`test_init website_on_branch 1`
+
+	got checkout -q $testroot/${GOTSYS_REPO} $testroot/wt >/dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got checkout failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	crypted_vm_pw=`echo ${GOTSYSD_VM_PASSWORD} | encrypt | tr -d '\n'`
+	crypted_pw=`echo ${GOTSYSD_DEV_PASSWORD} | encrypt | tr -d '\n'`
+	sshkey=`cat ${GOTSYSD_SSH_PUBKEY}`
+	cat > ${testroot}/wt/gotsys.conf <<EOF
+user ${GOTSYSD_TEST_USER} {
+	password "${crypted_vm_pw}" 
+	authorized key ${sshkey}
+}
+user ${GOTSYSD_DEV_USER} {
+	password "${crypted_pw}" 
+	authorized key ${sshkey}
+}
+repository gotsys {
+	permit rw ${GOTSYSD_TEST_USER}
+	permit rw ${GOTSYSD_DEV_USER}
+}
+repository www {
+	permit rw ${GOTSYSD_TEST_USER}
+	permit rw ${GOTSYSD_DEV_USER}
+}
+
+web server "${VMIP}" {
+	website "/" {
+		repository "www"
+		branch "website"
+		disable authentication
+	}
+}
+EOF
+	(cd ${testroot}/wt && gotsys check -q)
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "bad gotsys.conf written by test" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	(cd ${testroot}/wt && got commit  -m "set web site branch" >/dev/null)
+	local commit_id=`git_show_head $testroot/${GOTSYS_REPO}`
+
+	got send -q -i ${GOTSYSD_SSH_KEY} -r ${testroot}/${GOTSYS_REPO}
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got send failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	# Wait for gotsysd to apply the new configuration.
+	echo "$commit_id" > $testroot/stdout.expected
+	for i in 1 2 3 4 5; do
+		sleep 1
+		ssh -i ${GOTSYSD_SSH_KEY} root@${VMIP} \
+			cat /var/db/gotsysd/commit > $testroot/stdout
+		if cmp -s $testroot/stdout.expected $testroot/stdout; then
+			break;
+		fi
+	done
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "gotsysd failed to apply configuration" >&2
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	got init -b website $testroot/www.git > /dev/null
+	mkdir -p $testroot/www
+
+	cat > $testroot/www/index.html <<EOF
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>testing gotwebd</title>
+</head>
+<body>
+<h1>testing gotwebd</h1>
+<p>Testing the web site feature of gotwebd.</p>
+</body>
+</html>
+EOF
+	got import -m init -r $testroot/www.git -b website $testroot/www \
+		> /dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got import failed unexpectedly" >&2
+		return 1
+	fi
+
+	cat > $testroot/www.git/got.conf <<EOF
+remote "origin" {
+	server "${GOTSYSD_DEV_USER}@$VMIP"
+	protocol ssh
+	repository "www"
+	branch "website"
+}
+EOF
+	got send -q -i ${GOTSYSD_SSH_KEY} -r $testroot/www.git
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got send failed unexpectedly" >&2
+		return 1
+	fi
+
+	# Attempt website access.
+	w3m "http://${VMIP}/" -dump > $testroot/stdout
+	cat > $testroot/stdout.expected <<EOF
+testing gotwebd
+
+Testing the web site feature of gotwebd.
+
+EOF
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
 test_parseargs "$@"
 run_test test_website_at_root_path
+run_test test_website_on_branch