2021-01-12 03:27:01 +01: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-09 22:41:52 +01:00
|
|
|
. "$TEST_DIRECTORY"/lib-bundle.sh
|
2021-01-12 03:27:01 +01: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 14:40:18 +01: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 03:27:01 +01: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 05:14:11 +02: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 03:27:01 +01: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 05:17:25 +02:00
|
|
|
# about future changes of the commit ID.
|
2021-01-12 03:27:01 +01:00
|
|
|
make_user_friendly_and_stable_output () {
|
|
|
|
sed \
|
2021-06-17 05:14:11 +02: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 22:15:01 +02:00
|
|
|
-e "s/$(get_abbrev_oid $TAG3)[0-9a-f]*/<TAG-3>/g"
|
2021-06-17 05:17:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
format_and_save_expect () {
|
|
|
|
sed -e 's/Z$//' >expect
|
2021-01-12 03:27:01 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 18:28:39 +01:00
|
|
|
HASH_MESSAGE="The bundle uses this hash algorithm: $GIT_DEFAULT_HASH"
|
|
|
|
|
2021-01-12 03:27:01 +01: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 03:27:02 +01:00
|
|
|
test_expect_success 'create bundle from special rev: main^!' '
|
2021-01-12 03:27:01 +01: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 02:53:53 +01:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 03:27:01 +01:00
|
|
|
|
|
|
|
git bundle verify special-rev.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2022-03-22 18:28:39 +01:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 03:27:01 +01:00
|
|
|
The bundle contains this ref:
|
|
|
|
<COMMIT-P> refs/heads/main
|
|
|
|
The bundle requires this ref:
|
2021-06-17 05:17:25 +02:00
|
|
|
<COMMIT-O> Z
|
2022-03-22 18:28:39 +01:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 03:27:01 +01:00
|
|
|
EOF
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 03:27:01 +01: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 18:28:39 +01:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 03:27:01 +01: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 05:17:25 +02:00
|
|
|
<COMMIT-O> Z
|
2022-03-22 18:28:39 +01:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 03:27:01 +01:00
|
|
|
EOF
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 03:27:01 +01: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 18:28:39 +01:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 03:27:01 +01: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 05:17:25 +02:00
|
|
|
<COMMIT-M> Z
|
|
|
|
<COMMIT-K> Z
|
2022-03-22 18:28:39 +01:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 03:27:01 +01:00
|
|
|
EOF
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 03:27:01 +01: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 03:27:03 +01:00
|
|
|
# create bundle from args
|
2021-01-12 03:27:01 +01: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 03:27:03 +01:00
|
|
|
# create bundle from stdin
|
|
|
|
cat >input <<-\EOF &&
|
|
|
|
topic/1
|
|
|
|
topic/2
|
|
|
|
EOF
|
|
|
|
git bundle create stdin-1.bdl --stdin <input &&
|
|
|
|
|
2022-03-22 18:28:39 +01:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 03:27:01 +01: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 18:28:39 +01:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 03:27:01 +01:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# verify bundle, which has no prerequisites
|
|
|
|
git bundle verify 1.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 03:27:01 +01: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 03:27:03 +01:00
|
|
|
git bundle verify stdin-1.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 02:53:53 +01: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 03:27:03 +01:00
|
|
|
|
|
|
|
test_bundle_object_count 1.bdl 24 &&
|
|
|
|
test_bundle_object_count stdin-1.bdl 24
|
2021-01-12 03:27:01 +01: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 03:27:03 +01:00
|
|
|
# create bundle from args
|
2021-01-12 03:27:01 +01: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 03:27:03 +01: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 18:28:39 +01:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 03:27:01 +01:00
|
|
|
The bundle contains this ref:
|
|
|
|
<COMMIT-N> refs/heads/release
|
|
|
|
The bundle requires these 3 refs:
|
2021-06-17 05:17:25 +02:00
|
|
|
<COMMIT-D> Z
|
|
|
|
<COMMIT-E> Z
|
|
|
|
<COMMIT-G> Z
|
2022-03-22 18:28:39 +01:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 03:27:01 +01:00
|
|
|
EOF
|
|
|
|
|
|
|
|
git bundle verify 2.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 03:27:01 +01: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 03:27:03 +01:00
|
|
|
git bundle verify stdin-2.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 02:53:53 +01: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 03:27:03 +01:00
|
|
|
|
|
|
|
test_bundle_object_count 2.bdl 16 &&
|
|
|
|
test_bundle_object_count stdin-2.bdl 16
|
2021-01-12 03:27:01 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fail to verify bundle without prerequisites' '
|
|
|
|
git init --bare test1.git &&
|
|
|
|
|
2021-06-17 05:17:25 +02:00
|
|
|
format_and_save_expect <<-\EOF &&
|
2021-01-12 03:27:01 +01:00
|
|
|
error: Repository lacks these prerequisite commits:
|
2021-06-17 05:17:25 +02:00
|
|
|
error: <COMMIT-D> Z
|
|
|
|
error: <COMMIT-E> Z
|
|
|
|
error: <COMMIT-G> Z
|
2021-01-12 03:27:01 +01: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 02:53:53 +01: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 03:27:03 +01: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 02:53:53 +01:00
|
|
|
test_cmp expect actual
|
2021-01-12 03:27:01 +01: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 03:27:03 +01:00
|
|
|
# create bundle from args
|
2021-01-12 03:27:01 +01: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 03:27:03 +01: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 18:28:39 +01:00
|
|
|
format_and_save_expect <<-EOF &&
|
2021-01-12 03:27:01 +01:00
|
|
|
The bundle contains these 2 refs:
|
|
|
|
<COMMIT-P> refs/heads/main
|
|
|
|
<COMMIT-P> HEAD
|
|
|
|
The bundle requires these 2 refs:
|
2021-06-17 05:17:25 +02:00
|
|
|
<COMMIT-M> Z
|
|
|
|
<COMMIT-K> Z
|
2022-03-22 18:28:39 +01:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 03:27:01 +01:00
|
|
|
EOF
|
|
|
|
|
|
|
|
git bundle verify 3.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 03:27:01 +01: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 03:27:03 +01:00
|
|
|
git bundle verify stdin-3.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 02:53:53 +01: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 03:27:03 +01:00
|
|
|
|
|
|
|
test_bundle_object_count 3.bdl 4 &&
|
|
|
|
test_bundle_object_count stdin-3.bdl 4
|
2021-01-12 03:27:01 +01: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 03:27:03 +01:00
|
|
|
# create bundle from args
|
2021-01-12 03:27:01 +01: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 03:27:03 +01: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 18:28:39 +01:00
|
|
|
cat >expect <<-EOF &&
|
2021-01-12 03:27:01 +01: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 18:28:39 +01:00
|
|
|
$HASH_MESSAGE
|
2021-01-12 03:27:01 +01:00
|
|
|
EOF
|
|
|
|
|
|
|
|
git bundle verify 4.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expect actual &&
|
2021-01-12 03:27:01 +01: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 03:27:03 +01:00
|
|
|
git bundle verify stdin-4.bdl |
|
|
|
|
make_user_friendly_and_stable_output >actual &&
|
2021-02-11 02:53:53 +01: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 03:27:03 +01:00
|
|
|
|
|
|
|
test_bundle_object_count 4.bdl 3 &&
|
|
|
|
test_bundle_object_count stdin-4.bdl 3
|
2021-01-12 03:27:01 +01: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 17:01:38 +01: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 17:01:41 +01: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 18:28:39 +01:00
|
|
|
$HASH_MESSAGE
|
2022-03-22 18:28:38 +01:00
|
|
|
The bundle uses this filter: $filter
|
2022-03-09 17:01:41 +01: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 17:01:42 +01:00
|
|
|
ls unbundled/.git/objects/pack/pack-*.promisor >promisor &&
|
|
|
|
test_line_count = 1 promisor &&
|
2022-03-09 17:01:41 +01: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 17:01:43 +01: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 14:29:09 +01: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 14:29:10 +01:00
|
|
|
grep "some prerequisite commits .* are not connected" err &&
|
|
|
|
test_line_count = 1 err &&
|
2023-01-31 14:29:09 +01: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 14:29:10 +01:00
|
|
|
grep "some prerequisite commits .* are not connected" err &&
|
|
|
|
test_line_count = 1 err
|
2023-01-31 14:29:09 +01:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2021-01-12 03:27:01 +01:00
|
|
|
test_done
|