2021-01-12 05:27:01 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2021 Jiang Xin
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test git-bundle'
|
|
|
|
|
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
2021-02-10 00:41:52 +03:00
|
|
|
. "$TEST_DIRECTORY"/lib-bundle.sh
|
bundle: turn on --all-progress-implied by default
In 79862b6b77c (bundle-create: progress output control, 2019-11-10),
"bundle create" learned about the --all-progress and
--all-progress-implied options, which were copied from pack-objects.
I think these were a mistake.
In pack-objects, "all-progress-implied" is about switching the behavior
between a regular on-disk "git repack" and the use of pack-objects for
push/fetch (where a fetch does not want progress from the server during
the write stage; the client will print progress as it receives the
data). But there's no such distinction for bundles. Prior to
79862b6b77c, we always printed the write stage. Afterwards, a vanilla:
git bundle create foo.bundle
omits the write progress, appearing to hang (especially if your
repository is large or your disk is slow). That seems like a regression.
It's possible that the flexibility to disable the write-phase progress
_could_ be useful for bundle. E.g., if you did something like:
ssh some-host git bundle create foo.bundle |
git bundle unbundle
But if you are running both in real-time, why are you using bundles in
the first place? You're better off doing a real fetch.
But even if we did want to support that, it should be the exception, and
vanilla "bundle create" should display the full progress. So we'd want
to name the option "--no-write-progress" or something.
The "--all-progress" option itself is even worse. It exists in
pack-objects only for historical reasons. It's a mistake because it
implies "--progress", and we added "--all-progress-implied" to fix that.
There is no reason to propagate that mistake to new commands.
Likewise, the documentation for these options was pulled from
pack-objects. But it doesn't make any sense in this context. It talks
about "--stdout", but that is not even an option that git-bundle
supports.
This patch flips the default for "--all-progress-implied" back to
"true", fixing the regression in 79862b6b77c. This turns that option
into a noop, and means that "--all-progress" is really the same as
"--progress". We _could_ drop them completely, but since they've been
shipped with Git since v2.25.0, it's polite to continue accepting them.
I didn't implement any sort of "--no-write-progress" here. I'm not at
all convinced it's necessary, and the discussion from the original
thread:
https://lore.kernel.org/git/20191110204126.30553-2-robbat2@gentoo.org/
shows that that the main focus was on getting --progress and --quiet
support, and not any kind of clever "real-time bundle over the network"
feature. But technically this patch is making it impossible to do
something that you _could_ do post-79862b6b77c.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-03-04 13:55:13 +03:00
|
|
|
. "$TEST_DIRECTORY"/lib-terminal.sh
|
2021-01-12 05:27:01 +03:00
|
|
|
|
bundle: don't segfault on "git bundle <subcmd>"
Since aef7d75e580 (builtin/bundle.c: let parse-options parse
subcommands, 2022-08-19) we've been segfaulting if no argument was
provided.
The fix is easy, as all of the "git bundle" subcommands require a
non-option argument we can check that we have arguments left after
calling parse-options().
This makes use of code added in 73c3253d75e (bundle: framework for
options before bundle file, 2019-11-10), before this change that code
has always been unreachable. In 73c3253d75e we'd never reach it as we
already checked "argc < 2" in cmd_bundle() itself.
Then when aef7d75e580 (whose segfault we're fixing here) migrated this
code to the subcommand API it removed that "argc < 2" check, but we
were still checking the wrong "argc" in parse_options_cmd_bundle(), we
need to check the "newargc". The "argc" will always be >= 1, as it
will necessarily contain at least the subcommand name
itself (e.g. "create").
As an aside, this could be safely squashed into this, but let's not do
that for this minimal segfault fix, as it's an unrelated refactoring:
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -55,13 +55,12 @@ static int parse_options_cmd_bundle(int argc,
const char * const usagestr[],
const struct option options[],
char **bundle_file) {
- int newargc;
- newargc = parse_options(argc, argv, NULL, options, usagestr,
+ argc = parse_options(argc, argv, NULL, options, usagestr,
PARSE_OPT_STOP_AT_NON_OPTION);
- if (!newargc)
+ if (!argc)
usage_with_options(usagestr, options);
*bundle_file = prefix_filename(prefix, argv[0]);
- return newargc;
+ return argc;
}
static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
Reported-by: Hubert Jasudowicz <hubertj@stmcyber.pl>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Tested-by: Hubert Jasudowicz <hubertj@stmcyber.pl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-12-20 16:40:18 +03:00
|
|
|
for cmd in create verify list-heads unbundle
|
|
|
|
do
|
|
|
|
test_expect_success "usage: git bundle $cmd needs an argument" '
|
|
|
|
test_expect_code 129 git bundle $cmd
|
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2021-01-12 05:27:01 +03:00
|
|
|
# Create a commit or tag and set the variable with the object ID.
|
|
|
|
test_commit_setvar () {
|
|
|
|
notick=
|
|
|
|
signoff=
|
|
|
|
indir=
|
|
|
|
merge=
|
|
|
|
tag=
|
|
|
|
var=
|
|
|
|
|
|
|
|
while test $# != 0
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
--merge)
|
|
|
|
merge=t
|
|
|
|
;;
|
|
|
|
--tag)
|
|
|
|
tag=t
|
|
|
|
;;
|
|
|
|
--notick)
|
|
|
|
notick=t
|
|
|
|
;;
|
|
|
|
--signoff)
|
|
|
|
signoff="$1"
|
|
|
|
;;
|
|
|
|
-C)
|
|
|
|
shift
|
|
|
|
indir="$1"
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
echo >&2 "error: unknown option $1"
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
if test $# -lt 2
|
|
|
|
then
|
|
|
|
echo >&2 "error: test_commit_setvar must have at least 2 arguments"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
var=$1
|
|
|
|
shift
|
|
|
|
indir=${indir:+"$indir"/}
|
|
|
|
if test -z "$notick"
|
|
|
|
then
|
|
|
|
test_tick
|
|
|
|
fi &&
|
|
|
|
if test -n "$merge"
|
|
|
|
then
|
|
|
|
git ${indir:+ -C "$indir"} merge --no-edit --no-ff \
|
|
|
|
${2:+-m "$2"} "$1" &&
|
|
|
|
oid=$(git ${indir:+ -C "$indir"} rev-parse HEAD)
|
|
|
|
elif test -n "$tag"
|
|
|
|
then
|
|
|
|
git ${indir:+ -C "$indir"} tag -m "$1" "$1" "${2:-HEAD}" &&
|
|
|
|
oid=$(git ${indir:+ -C "$indir"} rev-parse "$1")
|
|
|
|
else
|
|
|
|
file=${2:-"$1.t"} &&
|
|
|
|
echo "${3-$1}" >"$indir$file" &&
|
|
|
|
git ${indir:+ -C "$indir"} add "$file" &&
|
|
|
|
git ${indir:+ -C "$indir"} commit $signoff -m "$1" &&
|
|
|
|
oid=$(git ${indir:+ -C "$indir"} rev-parse HEAD)
|
|
|
|
fi &&
|
|
|
|
eval $var=$oid
|
|
|
|
}
|
|
|
|
|
2021-06-17 06:14:11 +03:00
|
|
|
get_abbrev_oid () {
|
|
|
|
oid=$1 &&
|
|
|
|
suffix=${oid#???????} &&
|
|
|
|
oid=${oid%$suffix} &&
|
|
|
|
if test -n "$oid"
|
|
|
|
then
|
|
|
|
echo "$oid"
|
|
|
|
else
|
|
|
|
echo "undefined-oid"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-12 05:27:01 +03:00
|
|
|
# Format the output of git commands to make a user-friendly and stable
|
|
|
|
# text. We can easily prepare the expect text without having to worry
|
2021-06-17 06:17:25 +03:00
|
|
|
# about future changes of the commit ID.
|
2021-01-12 05:27:01 +03:00
|
|
|
make_user_friendly_and_stable_output () {
|
|
|
|
sed \
|
2021-06-17 06:14:11 +03:00
|
|
|
-e "s/$(get_abbrev_oid $A)[0-9a-f]*/<COMMIT-A>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $B)[0-9a-f]*/<COMMIT-B>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $C)[0-9a-f]*/<COMMIT-C>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $D)[0-9a-f]*/<COMMIT-D>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $E)[0-9a-f]*/<COMMIT-E>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $F)[0-9a-f]*/<COMMIT-F>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $G)[0-9a-f]*/<COMMIT-G>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $H)[0-9a-f]*/<COMMIT-H>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $I)[0-9a-f]*/<COMMIT-I>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $J)[0-9a-f]*/<COMMIT-J>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $K)[0-9a-f]*/<COMMIT-K>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $L)[0-9a-f]*/<COMMIT-L>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $M)[0-9a-f]*/<COMMIT-M>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $N)[0-9a-f]*/<COMMIT-N>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $O)[0-9a-f]*/<COMMIT-O>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $P)[0-9a-f]*/<COMMIT-P>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $TAG1)[0-9a-f]*/<TAG-1>/g" \
|
|
|
|
-e "s/$(get_abbrev_oid $TAG2)[0-9a-f]*/<TAG-2>/g" \
|
2021-07-08 23:15:01 +03:00
|
|
|
-e "s/$(get_abbrev_oid $TAG3)[0-9a-f]*/<TAG-3>/g"
|
2021-06-17 06:17:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
format_and_save_expect () {
|
|
|
|
sed -e 's/Z$//' >expect
|
2021-01-12 05:27:01 +03:00
|
|
|
}
|
|
|
|
|
2022-03-22 20:28:39 +03:00
|
|
|
HASH_MESSAGE="The bundle uses this hash algorithm: $GIT_DEFAULT_HASH"
|
|
|
|
|
2021-01-12 05:27:01 +03:00
|
|
|
# (C) (D, pull/1/head, topic/1)
|
|
|
|
# o --- o
|
|
|
|
# / \ (L)
|
|
|
|
# / \ o (H, topic/2) (M, tag:v2)
|
|
|
|
# / (F) \ / (N, tag:v3)
|
|
|
|
# / o --------- o (G, pull/2/head) o --- o --- o (release)
|
|
|
|
# / / \ \ / \
|
|
|
|
# o --- o --- o -------- o -- o ------------------ o ------- o --- o (main)
|
|
|
|
# (A) (B) (E, tag:v1) (I) (J) (K) (O) (P)
|
|
|
|
#
|
|
|
|
test_expect_success 'setup' '
|
|
|
|
# Try to make a stable fixed width for abbreviated commit ID,
|
|
|
|
# this fixed-width oid will be replaced with "<OID>".
|
|
|
|
git config core.abbrev 7 &&
|
|
|
|
|
|
|
|
# branch main: commit A & B
|
|
|
|
test_commit_setvar A "Commit A" main.txt &&
|
|
|
|
test_commit_setvar B "Commit B" main.txt &&
|
|
|
|
|
|
|
|
# branch topic/1: commit C & D, refs/pull/1/head
|
|
|
|
git checkout -b topic/1 &&
|
|
|
|
test_commit_setvar C "Commit C" topic-1.txt &&
|
|
|
|
test_commit_setvar D "Commit D" topic-1.txt &&
|
|
|
|
git update-ref refs/pull/1/head HEAD &&
|
|
|
|
|
|
|
|
# branch topic/1: commit E, tag v1
|
|
|
|
git checkout main &&
|
|
|
|
test_commit_setvar E "Commit E" main.txt &&
|
|
|
|
test_commit_setvar --tag TAG1 v1 &&
|
|
|
|
|
|
|
|
# branch topic/2: commit F & G, refs/pull/2/head
|
|
|
|
git checkout -b topic/2 &&
|
|
|
|
test_commit_setvar F "Commit F" topic-2.txt &&
|
|
|
|
test_commit_setvar G "Commit G" topic-2.txt &&
|
|
|
|
git update-ref refs/pull/2/head HEAD &&
|
|
|
|
test_commit_setvar H "Commit H" topic-2.txt &&
|
|
|
|
|
|
|
|
# branch main: merge commit I & J
|
|
|
|
git checkout main &&
|
|
|
|
test_commit_setvar --merge I topic/1 "Merge commit I" &&
|
|
|
|
test_commit_setvar --merge J refs/pull/2/head "Merge commit J" &&
|
|
|
|
|
|
|
|
# branch main: commit K
|
|
|
|
git checkout main &&
|
|
|
|
test_commit_setvar K "Commit K" main.txt &&
|
|
|
|
|
|
|
|
# branch release:
|
|
|
|
git checkout -b release &&
|
|
|
|
test_commit_setvar L "Commit L" release.txt &&
|
|
|
|
test_commit_setvar M "Commit M" release.txt &&
|
|
|
|
test_commit_setvar --tag TAG2 v2 &&
|
|
|
|
test_commit_setvar N "Commit N" release.txt &&
|
|
|
|
test_commit_setvar --tag TAG3 v3 &&
|
|
|
|
|
|
|
|
# branch main: merge commit O, commit P
|
|
|
|
git checkout main &&
|
|
|
|
test_commit_setvar --merge O tags/v2 "Merge commit O" &&
|
|
|
|
test_commit_setvar P "Commit P" main.txt
|
|
|
|
'
|
|
|
|
|
bundle: lost objects when removing duplicate pendings
`git rev-list` will list one commit for the following command:
$ git rev-list 'main^!'
<tip-commit-of-main-branch>
But providing the same rev-list args to `git bundle`, fail to create
a bundle file.
$ git bundle create - 'main^!'
# v2 git bundle
-<OID> <one-line-message>
fatal: Refusing to create empty bundle.
This is because when removing duplicate objects in function
`object_array_remove_duplicates()`, one unique pending object which has
the same name is deleted by mistake. The revision arg 'main^!' in the
above example is parsed by `handle_revision_arg()`, and at lease two
different objects will be appended to `revs.pending`, one points to the
parent commit of the "main" branch, and the other points to the tip
commit of the "main" branch. These two objects have the same name
"main". Only one object is left with the name "main" after calling the
function `object_array_remove_duplicates()`.
And what's worse, when adding boundary commits into pending list, we use
one-line commit message as names, and the arbitory names may surprise
git-bundle.
Only comparing objects themselves (".item") is also not good enough,
because user may want to create a bundle with two identical objects but
with different reference names, such as: "HEAD" and "refs/heads/main".
Add new function `contains_object()` which compare both the address and
the name of the object.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:02 +03:00
|
|
|
test_expect_success 'create bundle from special rev: main^!' '
|
2021-01-12 05:27:01 +03:00
|
|
|
git bundle create special-rev.bdl "main^!" &&
|
|
|
|
|
|
|
|
git bundle list-heads special-rev.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
<COMMIT-P> refs/heads/main
|
|
|
|
EOF
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 05:27:01 +03:00
|
|
|
|
|
|
|
git bundle verify special-rev.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2022-03-22 20:28:39 +03:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 05:27:01 +03:00
|
|
|
The bundle contains this ref:
|
|
|
|
<COMMIT-P> refs/heads/main
|
|
|
|
The bundle requires this ref:
|
2021-06-17 06:17:25 +03:00
|
|
|
<COMMIT-O> Z
|
2022-03-22 20:28:39 +03:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 05:27:01 +03:00
|
|
|
EOF
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 05:27:01 +03:00
|
|
|
|
|
|
|
test_bundle_object_count special-rev.bdl 3
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'create bundle with --max-count option' '
|
|
|
|
git bundle create max-count.bdl --max-count 1 \
|
|
|
|
main \
|
|
|
|
"^release" \
|
|
|
|
refs/tags/v1 \
|
|
|
|
refs/pull/1/head \
|
|
|
|
refs/pull/2/head &&
|
|
|
|
|
|
|
|
git bundle verify max-count.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2022-03-22 20:28:39 +03:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 05:27:01 +03:00
|
|
|
The bundle contains these 2 refs:
|
|
|
|
<COMMIT-P> refs/heads/main
|
|
|
|
<TAG-1> refs/tags/v1
|
|
|
|
The bundle requires this ref:
|
2021-06-17 06:17:25 +03:00
|
|
|
<COMMIT-O> Z
|
2022-03-22 20:28:39 +03:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 05:27:01 +03:00
|
|
|
EOF
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 05:27:01 +03:00
|
|
|
|
|
|
|
test_bundle_object_count max-count.bdl 4
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'create bundle with --since option' '
|
|
|
|
git log -1 --pretty="%ad" $M >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
Thu Apr 7 15:26:13 2005 -0700
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual &&
|
|
|
|
|
|
|
|
git bundle create since.bdl \
|
|
|
|
--since "Thu Apr 7 15:27:00 2005 -0700" \
|
|
|
|
--all &&
|
|
|
|
|
|
|
|
git bundle verify since.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2022-03-22 20:28:39 +03:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 05:27:01 +03:00
|
|
|
The bundle contains these 5 refs:
|
|
|
|
<COMMIT-P> refs/heads/main
|
|
|
|
<COMMIT-N> refs/heads/release
|
|
|
|
<TAG-2> refs/tags/v2
|
|
|
|
<TAG-3> refs/tags/v3
|
|
|
|
<COMMIT-P> HEAD
|
|
|
|
The bundle requires these 2 refs:
|
2021-06-17 06:17:25 +03:00
|
|
|
<COMMIT-M> Z
|
|
|
|
<COMMIT-K> Z
|
2022-03-22 20:28:39 +03:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 05:27:01 +03:00
|
|
|
EOF
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 05:27:01 +03:00
|
|
|
|
|
|
|
test_bundle_object_count --thin since.bdl 13
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'create bundle 1 - no prerequisites' '
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
# create bundle from args
|
2021-01-12 05:27:01 +03:00
|
|
|
git bundle create 1.bdl topic/1 topic/2 &&
|
|
|
|
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
# create bundle from stdin
|
|
|
|
cat >input <<-\EOF &&
|
|
|
|
topic/1
|
|
|
|
topic/2
|
|
|
|
EOF
|
|
|
|
git bundle create stdin-1.bdl --stdin <input &&
|
|
|
|
|
2022-03-22 20:28:39 +03:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 05:27:01 +03:00
|
|
|
The bundle contains these 2 refs:
|
|
|
|
<COMMIT-D> refs/heads/topic/1
|
|
|
|
<COMMIT-H> refs/heads/topic/2
|
|
|
|
The bundle records a complete history.
|
2022-03-22 20:28:39 +03:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 05:27:01 +03:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# verify bundle, which has no prerequisites
|
|
|
|
git bundle verify 1.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 05:27:01 +03:00
|
|
|
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
git bundle verify stdin-1.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
|
|
|
|
test_bundle_object_count 1.bdl 24 &&
|
|
|
|
test_bundle_object_count stdin-1.bdl 24
|
2021-01-12 05:27:01 +03:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'create bundle 2 - has prerequisites' '
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
# create bundle from args
|
2021-01-12 05:27:01 +03:00
|
|
|
git bundle create 2.bdl \
|
|
|
|
--ignore-missing \
|
|
|
|
^topic/deleted \
|
|
|
|
^$D \
|
|
|
|
^topic/2 \
|
|
|
|
release &&
|
|
|
|
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
# create bundle from stdin
|
|
|
|
# input has a non-exist reference: "topic/deleted"
|
|
|
|
cat >input <<-EOF &&
|
|
|
|
^topic/deleted
|
|
|
|
^$D
|
|
|
|
^topic/2
|
|
|
|
EOF
|
|
|
|
git bundle create stdin-2.bdl \
|
|
|
|
--ignore-missing \
|
|
|
|
--stdin \
|
|
|
|
release <input &&
|
|
|
|
|
2022-03-22 20:28:39 +03:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 05:27:01 +03:00
|
|
|
The bundle contains this ref:
|
|
|
|
<COMMIT-N> refs/heads/release
|
|
|
|
The bundle requires these 3 refs:
|
2021-06-17 06:17:25 +03:00
|
|
|
<COMMIT-D> Z
|
|
|
|
<COMMIT-E> Z
|
|
|
|
<COMMIT-G> Z
|
2022-03-22 20:28:39 +03:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 05:27:01 +03:00
|
|
|
EOF
|
|
|
|
|
|
|
|
git bundle verify 2.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 05:27:01 +03:00
|
|
|
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
git bundle verify stdin-2.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
|
|
|
|
test_bundle_object_count 2.bdl 16 &&
|
|
|
|
test_bundle_object_count stdin-2.bdl 16
|
2021-01-12 05:27:01 +03:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fail to verify bundle without prerequisites' '
|
|
|
|
git init --bare test1.git &&
|
|
|
|
|
2021-06-17 06:17:25 +03:00
|
|
|
format_and_save_expect <<-\EOF &&
|
2021-01-12 05:27:01 +03:00
|
|
|
error: Repository lacks these prerequisite commits:
|
2021-06-17 06:17:25 +03:00
|
|
|
error: <COMMIT-D> Z
|
|
|
|
error: <COMMIT-E> Z
|
|
|
|
error: <COMMIT-G> Z
|
2021-01-12 05:27:01 +03:00
|
|
|
EOF
|
|
|
|
|
|
|
|
test_must_fail git -C test1.git bundle verify ../2.bdl 2>&1 |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
|
|
|
|
test_must_fail git -C test1.git bundle verify ../stdin-2.bdl 2>&1 |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual
|
2021-01-12 05:27:01 +03:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'create bundle 3 - two refs, same object' '
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
# create bundle from args
|
2021-01-12 05:27:01 +03:00
|
|
|
git bundle create --version=3 3.bdl \
|
|
|
|
^release \
|
|
|
|
^topic/1 \
|
|
|
|
^topic/2 \
|
|
|
|
main \
|
|
|
|
HEAD &&
|
|
|
|
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
# create bundle from stdin
|
|
|
|
cat >input <<-\EOF &&
|
|
|
|
^release
|
|
|
|
^topic/1
|
|
|
|
^topic/2
|
|
|
|
EOF
|
|
|
|
git bundle create --version=3 stdin-3.bdl \
|
|
|
|
--stdin \
|
|
|
|
main HEAD <input &&
|
|
|
|
|
2022-03-22 20:28:39 +03:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 05:27:01 +03:00
|
|
|
The bundle contains these 2 refs:
|
|
|
|
<COMMIT-P> refs/heads/main
|
|
|
|
<COMMIT-P> HEAD
|
|
|
|
The bundle requires these 2 refs:
|
2021-06-17 06:17:25 +03:00
|
|
|
<COMMIT-M> Z
|
|
|
|
<COMMIT-K> Z
|
2022-03-22 20:28:39 +03:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 05:27:01 +03:00
|
|
|
EOF
|
|
|
|
|
|
|
|
git bundle verify 3.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 05:27:01 +03:00
|
|
|
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
git bundle verify stdin-3.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
|
|
|
|
test_bundle_object_count 3.bdl 4 &&
|
|
|
|
test_bundle_object_count stdin-3.bdl 4
|
2021-01-12 05:27:01 +03:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'create bundle 4 - with tags' '
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
# create bundle from args
|
2021-01-12 05:27:01 +03:00
|
|
|
git bundle create 4.bdl \
|
|
|
|
^main \
|
|
|
|
^release \
|
|
|
|
^topic/1 \
|
|
|
|
^topic/2 \
|
|
|
|
--all &&
|
|
|
|
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
# create bundle from stdin
|
|
|
|
cat >input <<-\EOF &&
|
|
|
|
^main
|
|
|
|
^release
|
|
|
|
^topic/1
|
|
|
|
^topic/2
|
|
|
|
EOF
|
|
|
|
git bundle create stdin-4.bdl \
|
|
|
|
--ignore-missing \
|
|
|
|
--stdin \
|
|
|
|
--all <input &&
|
|
|
|
|
2022-03-22 20:28:39 +03:00
|
|
|
cat >expect <<-EOF &&
|
2021-01-12 05:27:01 +03:00
|
|
|
The bundle contains these 3 refs:
|
|
|
|
<TAG-1> refs/tags/v1
|
|
|
|
<TAG-2> refs/tags/v2
|
|
|
|
<TAG-3> refs/tags/v3
|
|
|
|
The bundle records a complete history.
|
2022-03-22 20:28:39 +03:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 05:27:01 +03:00
|
|
|
EOF
|
|
|
|
|
|
|
|
git bundle verify 4.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 05:27:01 +03:00
|
|
|
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
git bundle verify stdin-4.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 04:53:53 +03:00
|
|
|
test_cmp expect actual &&
|
bundle: arguments can be read from stdin
In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits. It will be more
convenient to pass args via stdin. But the current implementation does
not allow us to do this.
This is because args are parsed twice when creating bundle. The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`. Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.
The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`. In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`. But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`). Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.
The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept. Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.
Also add testcases for git bundle in t6020, which read args from stdin.
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-12 05:27:03 +03:00
|
|
|
|
|
|
|
test_bundle_object_count 4.bdl 3 &&
|
|
|
|
test_bundle_object_count stdin-4.bdl 3
|
2021-01-12 05:27:01 +03:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'clone from bundle' '
|
|
|
|
git clone --mirror 1.bdl mirror.git &&
|
|
|
|
git -C mirror.git show-ref |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
<COMMIT-D> refs/heads/topic/1
|
|
|
|
<COMMIT-H> refs/heads/topic/2
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual &&
|
|
|
|
|
|
|
|
git -C mirror.git fetch ../2.bdl "+refs/*:refs/*" &&
|
|
|
|
git -C mirror.git show-ref |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
<COMMIT-N> refs/heads/release
|
|
|
|
<COMMIT-D> refs/heads/topic/1
|
|
|
|
<COMMIT-H> refs/heads/topic/2
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual &&
|
|
|
|
|
|
|
|
git -C mirror.git fetch ../3.bdl "+refs/*:refs/*" &&
|
|
|
|
git -C mirror.git show-ref |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
<COMMIT-P> refs/heads/main
|
|
|
|
<COMMIT-N> refs/heads/release
|
|
|
|
<COMMIT-D> refs/heads/topic/1
|
|
|
|
<COMMIT-H> refs/heads/topic/2
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual &&
|
|
|
|
|
|
|
|
git -C mirror.git fetch ../4.bdl "+refs/*:refs/*" &&
|
|
|
|
git -C mirror.git show-ref |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
<COMMIT-P> refs/heads/main
|
|
|
|
<COMMIT-N> refs/heads/release
|
|
|
|
<COMMIT-D> refs/heads/topic/1
|
|
|
|
<COMMIT-H> refs/heads/topic/2
|
|
|
|
<TAG-1> refs/tags/v1
|
|
|
|
<TAG-2> refs/tags/v2
|
|
|
|
<TAG-3> refs/tags/v3
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2022-03-09 19:01:38 +03:00
|
|
|
test_expect_success 'unfiltered bundle with --objects' '
|
|
|
|
git bundle create all-objects.bdl \
|
|
|
|
--all --objects &&
|
|
|
|
git bundle create all.bdl \
|
|
|
|
--all &&
|
|
|
|
|
|
|
|
# Compare the headers of these files.
|
|
|
|
sed -n -e "/^$/q" -e "p" all.bdl >expect &&
|
|
|
|
sed -n -e "/^$/q" -e "p" all-objects.bdl >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2022-03-09 19:01:41 +03:00
|
|
|
for filter in "blob:none" "tree:0" "tree:1" "blob:limit=100"
|
|
|
|
do
|
|
|
|
test_expect_success "filtered bundle: $filter" '
|
|
|
|
test_when_finished rm -rf .git/objects/pack cloned unbundled &&
|
|
|
|
git bundle create partial.bdl \
|
|
|
|
--all \
|
|
|
|
--filter=$filter &&
|
|
|
|
|
|
|
|
git bundle verify partial.bdl >unfiltered &&
|
|
|
|
make_user_friendly_and_stable_output <unfiltered >actual &&
|
|
|
|
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
The bundle contains these 10 refs:
|
|
|
|
<COMMIT-P> refs/heads/main
|
|
|
|
<COMMIT-N> refs/heads/release
|
|
|
|
<COMMIT-D> refs/heads/topic/1
|
|
|
|
<COMMIT-H> refs/heads/topic/2
|
|
|
|
<COMMIT-D> refs/pull/1/head
|
|
|
|
<COMMIT-G> refs/pull/2/head
|
|
|
|
<TAG-1> refs/tags/v1
|
|
|
|
<TAG-2> refs/tags/v2
|
|
|
|
<TAG-3> refs/tags/v3
|
|
|
|
<COMMIT-P> HEAD
|
|
|
|
The bundle records a complete history.
|
2022-03-22 20:28:39 +03:00
|
|
|
$HASH_MESSAGE
|
2022-03-22 20:28:38 +03:00
|
|
|
The bundle uses this filter: $filter
|
2022-03-09 19:01:41 +03:00
|
|
|
EOF
|
|
|
|
test_cmp expect actual &&
|
|
|
|
|
|
|
|
test_config uploadpack.allowfilter 1 &&
|
|
|
|
test_config uploadpack.allowanysha1inwant 1 &&
|
|
|
|
git clone --no-local --filter=$filter --bare "file://$(pwd)" cloned &&
|
|
|
|
|
|
|
|
git init unbundled &&
|
|
|
|
git -C unbundled bundle unbundle ../partial.bdl >ref-list.txt &&
|
2022-03-09 19:01:42 +03:00
|
|
|
ls unbundled/.git/objects/pack/pack-*.promisor >promisor &&
|
|
|
|
test_line_count = 1 promisor &&
|
2022-03-09 19:01:41 +03:00
|
|
|
|
|
|
|
# Count the same number of reachable objects.
|
|
|
|
reflist=$(git for-each-ref --format="%(objectname)") &&
|
|
|
|
git rev-list --objects --filter=$filter --missing=allow-any \
|
|
|
|
$reflist >expect &&
|
|
|
|
for repo in cloned unbundled
|
|
|
|
do
|
|
|
|
git -C $repo rev-list --objects --missing=allow-any \
|
|
|
|
$reflist >actual &&
|
|
|
|
test_cmp expect actual || return 1
|
|
|
|
done
|
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2022-03-09 19:01:43 +03:00
|
|
|
# NEEDSWORK: 'git clone --bare' should be able to clone from a filtered
|
|
|
|
# bundle, but that requires a change to promisor/filter config options.
|
|
|
|
# For now, we fail gracefully with a helpful error. This behavior can be
|
|
|
|
# changed in the future to succeed as much as possible.
|
|
|
|
test_expect_success 'cloning from filtered bundle has useful error' '
|
|
|
|
git bundle create partial.bdl \
|
|
|
|
--all \
|
|
|
|
--filter=blob:none &&
|
|
|
|
test_must_fail git clone --bare partial.bdl partial 2>err &&
|
|
|
|
grep "cannot clone from filtered bundle" err
|
|
|
|
'
|
|
|
|
|
2023-01-31 16:29:09 +03:00
|
|
|
test_expect_success 'verify catches unreachable, broken prerequisites' '
|
|
|
|
test_when_finished rm -rf clone-from clone-to &&
|
|
|
|
git init clone-from &&
|
|
|
|
(
|
|
|
|
cd clone-from &&
|
|
|
|
git checkout -b base &&
|
|
|
|
test_commit A &&
|
|
|
|
git checkout -b tip &&
|
|
|
|
git commit --allow-empty -m "will drop by shallow" &&
|
|
|
|
git commit --allow-empty -m "will keep by shallow" &&
|
|
|
|
git commit --allow-empty -m "for bundle, not clone" &&
|
|
|
|
git bundle create tip.bundle tip~1..tip &&
|
|
|
|
git reset --hard HEAD~1 &&
|
|
|
|
git checkout base
|
|
|
|
) &&
|
|
|
|
BAD_OID=$(git -C clone-from rev-parse tip~1) &&
|
|
|
|
TIP_OID=$(git -C clone-from rev-parse tip) &&
|
|
|
|
git clone --depth=1 --no-single-branch \
|
|
|
|
"file://$(pwd)/clone-from" clone-to &&
|
|
|
|
(
|
|
|
|
cd clone-to &&
|
|
|
|
|
|
|
|
# Set up broken history by removing shallow markers
|
|
|
|
git update-ref -d refs/remotes/origin/tip &&
|
|
|
|
rm .git/shallow &&
|
|
|
|
|
|
|
|
# Verify should fail
|
|
|
|
test_must_fail git bundle verify \
|
|
|
|
../clone-from/tip.bundle 2>err &&
|
bundle: verify using check_connected()
When Git verifies a bundle to see if it is safe for unbundling, it first
looks to see if the prerequisite commits are in the object store. This
is an easy way to "fail fast" but it is not a sufficient check for
updating refs that guarantee closure under reachability. There could
still be issues if those commits are not reachable from the repository's
references. The repository only has guarantees that its object store is
closed under reachability for the objects that are reachable from
references.
Thus, the code in verify_bundle() has previously had the additional
check that all prerequisite commits are reachable from repository
references. This is done via a revision walk from all references,
stopping only if all prerequisite commits are discovered or all commits
are walked. This uses a custom walk to verify_bundle().
This check is more strict than what Git applies to fetched pack-files.
In the fetch case, Git guarantees that the new references are closed
under reachability by walking from the new references until walking
commits that are reachable from repository refs. This is done through
the well-used check_connected() method.
To better align with the restrictions required by 'git fetch',
reimplement this check in verify_bundle() to use check_connected(). This
also simplifies the code significantly.
The previous change added a test that verified the behavior of 'git
bundle verify' and 'git bundle unbundle' in this case, and the error
messages looked like this:
error: Could not read <missing-commit>
fatal: Failed to traverse parents of commit <extant-commit>
However, by changing the revision walk slightly within check_connected()
and using its quiet mode, we can omit those messages. Instead, we get
only this message, tailored to describing the current state of the
repository:
error: some prerequisite commits exist in the object store,
but are not connected to the repository's history
(Line break added here for the commit message formatting, only.)
While this message does not include any object IDs, there is no
guarantee that those object IDs would help the user diagnose what is
going on, as they could be separated from the prerequisite commits by
some distance. At minimum, this situation describes the situation in a
more informative way than the previous error messages.
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-01-31 16:29:10 +03:00
|
|
|
grep "some prerequisite commits .* are not connected" err &&
|
|
|
|
test_line_count = 1 err &&
|
2023-01-31 16:29:09 +03:00
|
|
|
|
|
|
|
# Unbundling should fail
|
|
|
|
test_must_fail git bundle unbundle \
|
|
|
|
../clone-from/tip.bundle 2>err &&
|
bundle: verify using check_connected()
When Git verifies a bundle to see if it is safe for unbundling, it first
looks to see if the prerequisite commits are in the object store. This
is an easy way to "fail fast" but it is not a sufficient check for
updating refs that guarantee closure under reachability. There could
still be issues if those commits are not reachable from the repository's
references. The repository only has guarantees that its object store is
closed under reachability for the objects that are reachable from
references.
Thus, the code in verify_bundle() has previously had the additional
check that all prerequisite commits are reachable from repository
references. This is done via a revision walk from all references,
stopping only if all prerequisite commits are discovered or all commits
are walked. This uses a custom walk to verify_bundle().
This check is more strict than what Git applies to fetched pack-files.
In the fetch case, Git guarantees that the new references are closed
under reachability by walking from the new references until walking
commits that are reachable from repository refs. This is done through
the well-used check_connected() method.
To better align with the restrictions required by 'git fetch',
reimplement this check in verify_bundle() to use check_connected(). This
also simplifies the code significantly.
The previous change added a test that verified the behavior of 'git
bundle verify' and 'git bundle unbundle' in this case, and the error
messages looked like this:
error: Could not read <missing-commit>
fatal: Failed to traverse parents of commit <extant-commit>
However, by changing the revision walk slightly within check_connected()
and using its quiet mode, we can omit those messages. Instead, we get
only this message, tailored to describing the current state of the
repository:
error: some prerequisite commits exist in the object store,
but are not connected to the repository's history
(Line break added here for the commit message formatting, only.)
While this message does not include any object IDs, there is no
guarantee that those object IDs would help the user diagnose what is
going on, as they could be separated from the prerequisite commits by
some distance. At minimum, this situation describes the situation in a
more informative way than the previous error messages.
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-01-31 16:29:10 +03:00
|
|
|
grep "some prerequisite commits .* are not connected" err &&
|
|
|
|
test_line_count = 1 err
|
2023-01-31 16:29:09 +03:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
bundle: turn on --all-progress-implied by default
In 79862b6b77c (bundle-create: progress output control, 2019-11-10),
"bundle create" learned about the --all-progress and
--all-progress-implied options, which were copied from pack-objects.
I think these were a mistake.
In pack-objects, "all-progress-implied" is about switching the behavior
between a regular on-disk "git repack" and the use of pack-objects for
push/fetch (where a fetch does not want progress from the server during
the write stage; the client will print progress as it receives the
data). But there's no such distinction for bundles. Prior to
79862b6b77c, we always printed the write stage. Afterwards, a vanilla:
git bundle create foo.bundle
omits the write progress, appearing to hang (especially if your
repository is large or your disk is slow). That seems like a regression.
It's possible that the flexibility to disable the write-phase progress
_could_ be useful for bundle. E.g., if you did something like:
ssh some-host git bundle create foo.bundle |
git bundle unbundle
But if you are running both in real-time, why are you using bundles in
the first place? You're better off doing a real fetch.
But even if we did want to support that, it should be the exception, and
vanilla "bundle create" should display the full progress. So we'd want
to name the option "--no-write-progress" or something.
The "--all-progress" option itself is even worse. It exists in
pack-objects only for historical reasons. It's a mistake because it
implies "--progress", and we added "--all-progress-implied" to fix that.
There is no reason to propagate that mistake to new commands.
Likewise, the documentation for these options was pulled from
pack-objects. But it doesn't make any sense in this context. It talks
about "--stdout", but that is not even an option that git-bundle
supports.
This patch flips the default for "--all-progress-implied" back to
"true", fixing the regression in 79862b6b77c. This turns that option
into a noop, and means that "--all-progress" is really the same as
"--progress". We _could_ drop them completely, but since they've been
shipped with Git since v2.25.0, it's polite to continue accepting them.
I didn't implement any sort of "--no-write-progress" here. I'm not at
all convinced it's necessary, and the discussion from the original
thread:
https://lore.kernel.org/git/20191110204126.30553-2-robbat2@gentoo.org/
shows that that the main focus was on getting --progress and --quiet
support, and not any kind of clever "real-time bundle over the network"
feature. But technically this patch is making it impossible to do
something that you _could_ do post-79862b6b77c.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-03-04 13:55:13 +03:00
|
|
|
test_expect_success 'bundle progress includes write phase' '
|
|
|
|
GIT_PROGRESS_DELAY=0 \
|
|
|
|
git bundle create --progress out.bundle --all 2>err &&
|
|
|
|
grep 'Writing' err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success TTY 'create --quiet disables all bundle progress' '
|
|
|
|
test_terminal env GIT_PROGRESS_DELAY=0 \
|
|
|
|
git bundle create --quiet out.bundle --all 2>err &&
|
|
|
|
test_must_be_empty err
|
|
|
|
'
|
|
|
|
|
2023-07-29 23:40:27 +03:00
|
|
|
test_expect_success 'bundle progress with --no-quiet' '
|
|
|
|
GIT_PROGRESS_DELAY=0 \
|
|
|
|
git bundle create --no-quiet out.bundle --all 2>err &&
|
|
|
|
grep "%" err
|
|
|
|
'
|
|
|
|
|
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>
2023-03-04 13:26:14 +03:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
bundle: don't blindly apply prefix_filename() to "-"
A user can specify a filename to a command from the command line,
either as the value given to a command line option, or a command
line argument. When it is given as a relative filename, in the
user's mind, it is relative to the directory "git" was started from,
but by the time the filename is used, "git" would almost always have
chdir()'ed up to the root level of the working tree.
The given filename, if it is relative, needs to be prefixed with the
path to the current directory, and it typically is done by calling
prefix_filename() helper function. For commands that can also take
"-" to use the standard input or the standard output, however, this
needs to be done with care.
"git bundle create" uses the next word on the command line as the
output filename, and can take "-" to mean "write to the standard
output". It blindly called prefix_filename(), so running it in a
subdirectory did not quite work as expected.
Introduce a new helper, prefix_filename_except_for_dash(), and use
it to help "git bundle create" codepath.
Reported-by: Michael Henry
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-03-04 13:27:56 +03:00
|
|
|
test_expect_success 'send a bundle to standard output' '
|
|
|
|
git bundle create - --all HEAD >bundle-one &&
|
|
|
|
mkdir -p down &&
|
|
|
|
git -C down bundle create - --all HEAD >bundle-two &&
|
|
|
|
git bundle verify bundle-one &&
|
|
|
|
git bundle verify bundle-two &&
|
|
|
|
git ls-remote bundle-one >expect &&
|
|
|
|
git ls-remote bundle-two >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2021-01-12 05:27:01 +03:00
|
|
|
test_done
|