git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
f84fe950ec28715e5bbcd5be4547af04602f3cf5 blob 3579 bytes (raw)

  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
 
#!/bin/sh

test_description='tests for transfering external objects to an HTTPD server'

. ./test-lib.sh

# If we don't specify a port, the current test number will be used
# which will not work as it is less than 1024, so it can only be used by root.
LIB_HTTPD_PORT=$(expr ${this_test#t} + 12000)

. "$TEST_DIRECTORY"/lib-httpd.sh

start_httpd apache-e-odb.conf

# odb helper script must see this
export HTTPD_URL

write_script odb-http-helper <<\EOF
die() {
	printf >&2 "%s\n" "$@"
	exit 1
}
echo >&2 "odb-http-helper args:" "$@"
case "$1" in
init)
	echo "capability=get_raw_obj"
	echo "capability=put_raw_obj"
	echo "capability=have"
	;;
have)
	list_url="$HTTPD_URL/list/"
	curl "$list_url" ||
	die "curl '$list_url' failed"
	;;
get_raw_obj)
	get_url="$HTTPD_URL/list/?sha1=$2"
	curl "$get_url" ||
	die "curl '$get_url' failed"
	;;
put_raw_obj)
	sha1="$2"
	size="$3"
	kind="$4"
	upload_url="$HTTPD_URL/upload/?sha1=$sha1&size=$size&type=$kind"
	curl --data-binary @- --include "$upload_url" >out ||
	die "curl '$upload_url' failed"
	ref_hash=$(echo "$sha1 $size $kind" | GIT_NO_EXTERNAL_ODB=1 git hash-object -w -t blob --stdin) || exit
	git update-ref refs/odbs/magic/"$sha1" "$ref_hash"
	;;
*)
	die "unknown command '$1'"
	;;
esac
EOF
HELPER="\"$PWD\"/odb-http-helper"

test_expect_success 'setup repo with a root commit and the helper' '
	test_commit zero &&
	git config odb.magic.scriptCommand "$HELPER"
'

test_expect_success 'setup another repo from the first one' '
	git init other-repo &&
	(cd other-repo &&
	 git remote add origin .. &&
	 git pull origin master &&
	 git checkout master &&
	 git log)
'

UPLOADFILENAME="hello_apache_upload.txt"

UPLOAD_URL="$HTTPD_URL/upload/?sha1=$UPLOADFILENAME&size=123&type=blob"

test_expect_success 'can upload a file' '
	echo "Hello Apache World!" >hello_to_send.txt &&
	echo "How are you?" >>hello_to_send.txt &&
	curl --data-binary @hello_to_send.txt --include "$UPLOAD_URL" >out_upload
'

LIST_URL="$HTTPD_URL/list/"

test_expect_success 'can list uploaded files' '
	curl --include "$LIST_URL" >out_list &&
	grep "$UPLOADFILENAME" out_list
'

test_expect_success 'can delete uploaded files' '
	curl --data "delete" --include "$UPLOAD_URL&delete=1" >out_delete &&
	curl --include "$LIST_URL" >out_list2 &&
	! grep "$UPLOADFILENAME" out_list2
'

FILES_DIR="httpd/www/files"

test_expect_success 'new blobs are transfered to the http server' '
	test_commit one &&
	hash1=$(git ls-tree HEAD | grep one.t | cut -f1 | cut -d\  -f3) &&
	echo "$hash1-4-blob" >expected &&
	ls "$FILES_DIR" >actual &&
	test_cmp expected actual
'

test_expect_success 'blobs can be retrieved from the http server' '
	git cat-file blob "$hash1" &&
	git log -p >expected
'

test_expect_success 'update other repo from the first one' '
	(cd other-repo &&
	 git fetch origin "refs/odbs/magic/*:refs/odbs/magic/*" &&
	 test_must_fail git cat-file blob "$hash1" &&
	 git config odb.magic.scriptCommand "$HELPER" &&
	 git cat-file blob "$hash1" &&
	 git pull origin master)
'

test_expect_success 'local clone from the first repo' '
	mkdir my-clone &&
	(cd my-clone &&
	 git clone .. . &&
	 git cat-file blob "$hash1")
'

test_expect_success 'no-local clone from the first repo fails' '
	mkdir my-other-clone &&
	(cd my-other-clone &&
	 test_must_fail git clone --no-local .. .) &&
	rm -rf my-other-clone
'

test_expect_success 'no-local clone from the first repo with helper succeeds' '
	mkdir my-other-clone &&
	(cd my-other-clone &&
	 git clone -c odb.magic.scriptCommand="$HELPER" \
		--no-local .. .) &&
	rm -rf my-other-clone
'

stop_httpd

test_done
debug log:

solving f84fe950ec ...
found f84fe950ec in https://public-inbox.org/git/20180319133147.15413-28-chriscool@tuxfamily.org/

applying [1/1] https://public-inbox.org/git/20180319133147.15413-28-chriscool@tuxfamily.org/
diff --git a/t/t0520-transfer-http-e-odb.sh b/t/t0520-transfer-http-e-odb.sh
new file mode 100755
index 0000000000..f84fe950ec

Checking patch t/t0520-transfer-http-e-odb.sh...
Applied patch t/t0520-transfer-http-e-odb.sh cleanly.

index at:
100755 f84fe950ec28715e5bbcd5be4547af04602f3cf5	t/t0520-transfer-http-e-odb.sh

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).