summaryrefslogtreecommitdiff
path: root/t/t6020-bundle-misc.sh
diff options
context:
space:
mode:
authorJiang Xin <zhiyou.jx@alibaba-inc.com>2021-01-12 02:27:03 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-01-12 05:50:41 (GMT)
commit5bb0fd2cab5a18bc188c8154097857f51a0e9feb (patch)
treeac6801a1892609e2da0ab5d767d4af6225ba0210 /t/t6020-bundle-misc.sh
parentce1d6d9f1641d87a66c3933255531ee2c15d3143 (diff)
downloadgit-5bb0fd2cab5a18bc188c8154097857f51a0e9feb.zip
git-5bb0fd2cab5a18bc188c8154097857f51a0e9feb.tar.gz
git-5bb0fd2cab5a18bc188c8154097857f51a0e9feb.tar.bz2
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>
Diffstat (limited to 't/t6020-bundle-misc.sh')
-rwxr-xr-xt/t6020-bundle-misc.sh77
1 files changed, 73 insertions, 4 deletions
diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh
index b554538..6249420 100755
--- a/t/t6020-bundle-misc.sh
+++ b/t/t6020-bundle-misc.sh
@@ -242,8 +242,16 @@ test_expect_success 'create bundle with --since option' '
'
test_expect_success 'create bundle 1 - no prerequisites' '
+ # create bundle from args
git bundle create 1.bdl topic/1 topic/2 &&
+ # create bundle from stdin
+ cat >input <<-\EOF &&
+ topic/1
+ topic/2
+ EOF
+ git bundle create stdin-1.bdl --stdin <input &&
+
cat >expect <<-\EOF &&
The bundle contains these 2 refs:
<COMMIT-D> refs/heads/topic/1
@@ -256,10 +264,16 @@ test_expect_success 'create bundle 1 - no prerequisites' '
make_user_friendly_and_stable_output >actual &&
test_i18ncmp expect actual &&
- test_bundle_object_count 1.bdl 24
+ git bundle verify stdin-1.bdl |
+ make_user_friendly_and_stable_output >actual &&
+ test_i18ncmp expect actual &&
+
+ test_bundle_object_count 1.bdl 24 &&
+ test_bundle_object_count stdin-1.bdl 24
'
test_expect_success 'create bundle 2 - has prerequisites' '
+ # create bundle from args
git bundle create 2.bdl \
--ignore-missing \
^topic/deleted \
@@ -267,6 +281,18 @@ test_expect_success 'create bundle 2 - has prerequisites' '
^topic/2 \
release &&
+ # 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 &&
+
cat >expect <<-\EOF &&
The bundle contains this ref:
<COMMIT-N> refs/heads/release
@@ -280,7 +306,12 @@ test_expect_success 'create bundle 2 - has prerequisites' '
make_user_friendly_and_stable_output >actual &&
test_i18ncmp expect actual &&
- test_bundle_object_count 2.bdl 16
+ git bundle verify stdin-2.bdl |
+ make_user_friendly_and_stable_output >actual &&
+ test_i18ncmp expect actual &&
+
+ test_bundle_object_count 2.bdl 16 &&
+ test_bundle_object_count stdin-2.bdl 16
'
test_expect_success 'fail to verify bundle without prerequisites' '
@@ -295,10 +326,15 @@ test_expect_success 'fail to verify bundle without prerequisites' '
test_must_fail git -C test1.git bundle verify ../2.bdl 2>&1 |
make_user_friendly_and_stable_output >actual &&
+ test_i18ncmp expect actual &&
+
+ test_must_fail git -C test1.git bundle verify ../stdin-2.bdl 2>&1 |
+ make_user_friendly_and_stable_output >actual &&
test_i18ncmp expect actual
'
test_expect_success 'create bundle 3 - two refs, same object' '
+ # create bundle from args
git bundle create --version=3 3.bdl \
^release \
^topic/1 \
@@ -306,6 +342,16 @@ test_expect_success 'create bundle 3 - two refs, same object' '
main \
HEAD &&
+ # 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 &&
+
cat >expect <<-\EOF &&
The bundle contains these 2 refs:
<COMMIT-P> refs/heads/main
@@ -319,10 +365,16 @@ test_expect_success 'create bundle 3 - two refs, same object' '
make_user_friendly_and_stable_output >actual &&
test_i18ncmp expect actual &&
- test_bundle_object_count 3.bdl 4
+ git bundle verify stdin-3.bdl |
+ make_user_friendly_and_stable_output >actual &&
+ test_i18ncmp expect actual &&
+
+ test_bundle_object_count 3.bdl 4 &&
+ test_bundle_object_count stdin-3.bdl 4
'
test_expect_success 'create bundle 4 - with tags' '
+ # create bundle from args
git bundle create 4.bdl \
^main \
^release \
@@ -330,6 +382,18 @@ test_expect_success 'create bundle 4 - with tags' '
^topic/2 \
--all &&
+ # 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 &&
+
cat >expect <<-\EOF &&
The bundle contains these 3 refs:
<TAG-1> refs/tags/v1
@@ -342,7 +406,12 @@ test_expect_success 'create bundle 4 - with tags' '
make_user_friendly_and_stable_output >actual &&
test_i18ncmp expect actual &&
- test_bundle_object_count 4.bdl 3
+ git bundle verify stdin-4.bdl |
+ make_user_friendly_and_stable_output >actual &&
+ test_i18ncmp expect actual &&
+
+ test_bundle_object_count 4.bdl 3 &&
+ test_bundle_object_count stdin-4.bdl 3
'
test_expect_success 'clone from bundle' '