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

[PATCH 4/8] archive: add tests for directory selection

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Apr 8, 2009, 10:05 UTC
Message-ID
<1239185133-4181-5-git-send-email-pclouds@gmail.com>
In-Reply-To
<1239185133-4181-4-git-send-email-pclouds@gmail.com>

While in archive.c, it says "pathspec". It's not really pathspec. Make a few tests to catch this point.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 archive.c               |   17 +++++++++++++++++
 t/t0024-crlf-archive.sh |   30 +++++++++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 1 deletions(-)
diff --git a/archive.c b/archive.c
index e87fed7..5b54d95 100644
--- a/archive.c
+++ b/archive.c
@@ -15,6 +15,8 @@ static char const * const archive_usage[] = {
 
 #define USES_ZLIB_COMPRESSION 1
 
+static int list_archive(struct archiver_args *args);
+
 static const struct archiver {
 	const char *name;
 	write_archive_fn_t write_archive;
@@ -22,8 +24,23 @@ static const struct archiver {
 } archivers[] = {
 	{ "tar", write_tar_archive },
 	{ "zip", write_zip_archive, USES_ZLIB_COMPRESSION },
+	{ "dump-file-list", list_archive },
 };
 
+static int list_archive_entry(struct archiver_args *args,
+		const unsigned char *sha1, const char *path, size_t pathlen,
+		unsigned int mode, void *buffer, unsigned long size)
+{
+	printf("%s\n", path);
+	return 0;
+}
+
+static int list_archive(struct archiver_args *args)
+{
+	write_archive_entries(args, list_archive_entry);
+	return 0;
+}
+
 static void format_subst(const struct commit *commit,
                          const char *src, size_t len,
                          struct strbuf *buf)
diff --git a/t/t0024-crlf-archive.sh b/t/t0024-crlf-archive.sh
index 9c56e0e..695ad5a 100755
--- a/t/t0024-crlf-archive.sh
+++ b/t/t0024-crlf-archive.sh
@@ -9,14 +9,42 @@ test_expect_success setup '
 
 	git config core.autocrlf true
 
+	mkdir sub &&
 	printf "CRLF line ending\r\nAnd another\r\n" > sample &&
-	git add sample &&
+	cp sample sub/sample &&
+	git add sample sub/sample &&
 
 	test_tick &&
 	git commit -m Initial
 
 '
 
+cat <<\EOF > expected
+sample
+sub/
+sub/sample
+EOF
+
+test_expect_success 'archive without subdir' '
+	git archive --format=dump-file-list HEAD > output &&
+	test_cmp output expected
+'
+
+cat <<\EOF > expected
+sub/
+sub/sample
+EOF
+
+test_expect_success 'archive with subdir' '
+	git archive --format=dump-file-list HEAD sub > output &&
+	test_cmp output expected
+'
+
+test_expect_success 'subdir is not pathspec' '
+	test "$(git archive --format=dump-file-list HEAD sub/)" = ""
+	test "$(git archive --format=dump-file-list HEAD s\*)" = ""
+'
+
 test_expect_success 'tar archive' '
 
 	git archive --format=tar HEAD |
-- 
1.6.2.2.602.g83ee9f
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 5 of 24 in “support "in-tree attributes" for git-archive”
  1. 0/8 support "in-tree attributes" for git-archiveNguyễn Thái Ngọc Duy, Apr 8, 2009
  2. 1/8 archive: add shortcuts for --format and --prefixNguyễn Thái Ngọc Duy, Apr 8, 2009
  3. 2/8 move prune_cache() to git libNguyễn Thái Ngọc Duy, Apr 8, 2009
  4. 3/8 archive: add a failure test wrt .gitattributes misreadingNguyễn Thái Ngọc Duy, Apr 8, 2009
  5. 4/8 archive: add tests for directory selectionNguyễn Thái Ngọc Duy, Apr 8, 2009
  6. 5/8 attr: add GIT_ATTR_INDEX "direction"Nguyễn Thái Ngọc Duy, Apr 8, 2009
  7. 6/8 archive: use index instead of parsing tree directlyNguyễn Thái Ngọc Duy, Apr 8, 2009
  8. 7/8 archive: disregard .gitattributes on working directoryNguyễn Thái Ngọc Duy, Apr 8, 2009
  9. 8/8 archive: support creating archives from indexNguyễn Thái Ngọc Duy, Apr 8, 2009
  10. René ScharfeApr 8, 2009
  11. Junio C HamanoApr 8, 2009
  12. Junio C HamanoApr 8, 2009
  13. René ScharfeApr 8, 2009
  14. René ScharfeApr 8, 2009
  15. René ScharfeApr 8, 2009
  16. Junio C HamanoApr 8, 2009
  17. René ScharfeApr 13, 2009
  18. Nguyen Thai Ngoc DuyApr 14, 2009
  19. René ScharfeApr 14, 2009
  20. Junio C HamanoApr 16, 2009
  21. René ScharfeApr 17, 2009
  22. Junio C HamanoApr 18, 2009
  23. Junio C HamanoApr 8, 2009
  24. René ScharfeApr 8, 2009

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.