diff options
author | Jeff King <peff@peff.net> | 2023-03-04 10:26:14 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-03-06 21:12:55 (GMT) |
commit | bf8b1e04ffa3bb6c64bb8ae50ec825b128ef957d (patch) | |
tree | c667d9a0256aad3093971e5ffcb3b65a67d28d6f /t/t6020-bundle-misc.sh | |
parent | 768bb238c4843bf52847773a621de4dffa6b9ab5 (diff) | |
download | git-bf8b1e04ffa3bb6c64bb8ae50ec825b128ef957d.zip git-bf8b1e04ffa3bb6c64bb8ae50ec825b128ef957d.tar.gz git-bf8b1e04ffa3bb6c64bb8ae50ec825b128ef957d.tar.bz2 |
bundle: let "-" mean stdin for reading operations
For writing, "bundle create -" indicates that the bundle should be
written to stdout. But there's no matching handling of "-" for reading
operations. This is inconsistent, and a little inflexible (though one
can always use "/dev/stdin" on systems that support it).
However, it's easy to change. Once upon a time, the bundle-reading code
required a seekable descriptor, but that was fixed long ago in
e9ee84cf28b (bundle: allowing to read from an unseekable fd,
2011-10-13). So we just need to handle "-" explicitly when opening the
file.
We _could_ do this by handling "-" in read_bundle_header(), which the
reading functions all call already. But that is probably a bad idea.
It's also used by low-level code like the transport functions, and we
may want to be more careful there. We do not know that stdin is even
available to us, and certainly we would not want to get confused by a
configured URL that happens to point to "-".
So instead, let's add a helper to builtin/bundle.c. Since both the
bundle code and some of the callers refer to the bundle by name for
error messages, let's use the string "<stdin>" to make the output a bit
nicer to read.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t6020-bundle-misc.sh')
-rwxr-xr-x | t/t6020-bundle-misc.sh | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh index 3a1cf30..063e8ce 100755 --- a/t/t6020-bundle-misc.sh +++ b/t/t6020-bundle-misc.sh @@ -566,4 +566,19 @@ test_expect_success 'cloning from filtered bundle has useful error' ' grep "cannot clone from filtered bundle" err ' +test_expect_success 'read bundle over stdin' ' + git bundle create some.bundle HEAD && + + git bundle verify - <some.bundle 2>err && + grep "<stdin> is okay" err && + + git bundle list-heads some.bundle >expect && + git bundle list-heads - <some.bundle >actual && + test_cmp expect actual && + + git bundle unbundle some.bundle >expect && + git bundle unbundle - <some.bundle >actual && + test_cmp expect actual +' + test_done |