git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/6] gitweb.perl support for snapshots with lists of specified files is now tested

From
JKJim Klimov <jim@jimklimov.com>
Date
Mar 11, 2016, 13:24 UTC
Message-ID
<1457702689-9084-4-git-send-email-jim@jimklimov.com>
In-Reply-To
<1457702689-9084-1-git-send-email-jim@jimklimov.com>
---
 t/t9502-gitweb-standalone-parse-output.sh | 156 ++++++++++++++++++++++++++++--
 1 file changed, 148 insertions(+), 8 deletions(-)
diff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh
index 0796a43..11a116f 100755
--- a/t/t9502-gitweb-standalone-parse-output.sh
+++ b/t/t9502-gitweb-standalone-parse-output.sh
@@ -27,25 +27,46 @@ $known_snapshot_formats{'tar'} = {
 $feature{'snapshot'}{'default'} = ['tar'];
 EOF
 
-# Call check_snapshot with the arguments "<basename> [<prefix>]"
+# Call list_snapshot with the argument "<basename>"
 #
 # This will check that gitweb HTTP header contains proposed filename
-# as <basename> with '.tar' suffix added, and that generated tarfile
-# (gitweb message body) has <prefix> as prefix for al files in tarfile
+# as <basename> with '.tar' suffix added, and lists its content to
+# stdout of this routine (in "tar test" default listing format)
 #
-# <prefix> default to <basename>
-check_snapshot () {
-	basename=$1
-	prefix=${2:-"$1"}
+# <prefix> defaults to <basename>
+#
+list_snapshot () {
+	basename="`echo "$1" | sed 's,\/,\.,g'`"
 	echo "basename=$basename"
 	grep "filename=.*$basename.tar" gitweb.headers >/dev/null 2>&1 &&
-	"$TAR" tf gitweb.body >file_list &&
+	"$TAR" tf gitweb.body >file_list
+}
+
+#
+# Call check_snapshot with the arguments "<basename> [<prefix>]"
+#
+# This uses list_snapshot() above to list the tarfile <basename>.tar received
+# from gitweb, and that this generated tarfile (gitweb message body) has
+# <prefix> prepended as prefix for all objects in the tarfile
+# The tarfile listing is exchanged via the "file_list" temporary file
+#
+# <prefix> defaults to <basename>
+#
+check_snapshot () {
+	basename="$1"
+	prefix=${2:-"$1"}
+	list_snapshot "$basename" &&
 	! grep -v -e "^$prefix$" -e "^$prefix/" -e "^pax_global_header$" file_list
 }
 
+# Note: the "xx/test" branch only contains file "foo"; others land in "master"
+# Call test_commit with the arguments "<message> [<file> [<contents> [<tag>]]]"
 test_expect_success setup '
 	test_commit first foo &&
+	mkdir -p dir1 && test_commit bar dir1/second bar second &&
 	git branch xx/test &&
+	mkdir -p dir2 && test_commit pif dir2/third pif third &&
+	test_commit wow dir2/"fourth file" wow wow &&
 	FULL_ID=$(git rev-parse --verify HEAD) &&
 	SHORT_ID=$(git rev-parse --verify --short=7 HEAD)
 '
@@ -112,6 +133,125 @@ test_expect_success 'snapshot: hierarchical branch name (xx/test)' '
 '
 test_debug 'cat gitweb.headers'
 
+test_expect_success 'snapshot sanity: have expected content in xx/test branch - do not have /first file in full snapshot' '
+	rm -f gitweb.body file_list &&
+	BRANCH=xx/test &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	! grep "first" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - only those under subdir dir2/ and not others' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	! grep "foo" file_list &&
+	! grep "dir1/second" file_list &&
+	grep "dir2/third" file_list &&
+	grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - subdir name is required in requested nested path (bad path - empty output)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=third" &&
+	[ ! -s gitweb.body ]
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - correct subdir name is required in requested nested path (bad path - empty output)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir1/third" &&
+	[ ! -s gitweb.body ]
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - can request filenames with spaces (backslash + HTML-escape)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2/fourth\%20file" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	! grep "foo" file_list &&
+	! grep "dir1/second" file_list &&
+	! grep "dir2/third" file_list &&
+	grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - can request list of filenames separated by HTML-escaped spaces' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir1/second%20dir2/third" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	! grep "foo" file_list &&
+	grep "dir1/second" file_list &&
+	grep "dir2/third" file_list &&
+	! grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - can request list of filenames separated by HTML-escaped spaces including a filename with spaces (backslash + HTML-escape)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=foo%20dir2/fourth\%20file%20dir1/second" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	grep "foo" file_list &&
+	grep "dir1/second" file_list &&
+	! grep "dir2/third" file_list &&
+	grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have only expected content in refs/tags/second full tag' '
+	rm -f gitweb.body file_list &&
+	BRANCH=second &&
+	gitweb_run "p=.git;a=snapshot;h=refs/tags/$BRANCH;sf=tar;f=dir1/second" &&
+	list_snapshot ".git-$BRANCH" &&
+	! grep "foo" file_list &&
+	grep "dir1/second" file_list &&
+	! grep "dir2/third" file_list &&
+	! grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for only absent subdir dir2/ fails (empty output)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=xx/test &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2" &&
+        [ ! -s "gitweb.body" ]
+'
+test_debug 'cat gitweb.headers'
+
+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for file /foo and absent subdir dir2/ also fails (empty output)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=xx/test &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2%20foo" &&
+        [ ! -s "gitweb.body" ]
+'
+test_debug 'cat gitweb.headers'
+
+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - have /foo file (and only it)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=xx/test &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=foo" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	grep "foo" file_list &&
+	! grep "dir1/second" file_list &&
+	! grep "dir2/third" file_list &&
+	! grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
 # ----------------------------------------------------------------------
 # forks of projects
 
-- 
2.1.4
Previous: Jim KlimovNext: Jim Klimov
Message 4 of 6 in “gitweb.perl : added ability to "git archive" just certain paths (files or subdirs, not whole repo) via gitweb interface”
  1. 1/6 gitweb.perl : added ability to "git archive" just certain paths (files or subdirs, not whole repo) via gitweb interfaceJim Klimov, Mar 11, 2016
  2. 2/6 gitweb.perl : added ability to debug requests coming through gitweb interface by adding an option to request URL (also requires server-side envvar "GITWEB_MAY_DEBUG=yes")Jim Klimov, Mar 11, 2016
  3. 3/6 gitweb.perl : added ability to DEBUG progression through "git archive"Jim Klimov, Mar 11, 2016
  4. 4/6 gitweb.perl support for snapshots with lists of specified files is now testedJim Klimov, Mar 11, 2016
  5. 5/6 gitweb.perl changed (and tested) to return HTTP-404 when missing objects are requested via snapshotJim Klimov, Mar 11, 2016
  6. 6/6 gitweb.perl : the optional DEBUG functionality is now unit-testedJim Klimov, Mar 11, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.