{"thread":{"id":"55952","subject":"[PATCH 1/2] test-lib-functions: test_create_repo learns --bare","startedAt":"2021-06-17T12:43:44Z","lastAt":"2021-06-23T00:54:00Z","messageCount":4,"participants":["Jiang Xin","Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"427746","messageId":"20210617124331.17888-1-zhiyou.jx@alibaba-inc.com","threadId":"55952","inReplyTo":null,"subject":"[PATCH 1/2] test-lib-functions: test_create_repo learns --bare","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2021-06-17T12:43:30Z","receivedAt":"2021-06-17T12:43:44Z","isPatch":true,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"\"test_create_repo\" learns --bare option to create bare repository.\n\nSigned-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>\n---\n t/test-lib-functions.sh | 22 +++++++++++++++++++---\n 1 file changed, 19 insertions(+), 3 deletions(-)\n\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex b823c14027..f6d1afe295 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -1216,8 +1216,21 @@ test_atexit () {\n }\n \n # Most tests can use the created repository, but some may need to create more.\n-# Usage: test_create_repo <directory>\n+# Usage: test_create_repo [--bare] <directory>\n test_create_repo () {\n+\tbare= &&\n+\twhile test $# -gt 0\n+\tdo\n+\t\tcase \"$1\" in\n+\t\t--bare)\n+\t\t\tbare=yes\n+\t\t\t;;\n+\t\t*)\n+\t\t\tbreak\n+\t\t\t;;\n+\t\tesac\n+\t\tshift\n+\tdone &&\n \ttest \"$#\" = 1 ||\n \tBUG \"not 1 parameter to test-create-repo\"\n \trepo=\"$1\"\n@@ -1226,10 +1239,13 @@ test_create_repo () {\n \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n \t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" -c \\\n \t\t\tinit.defaultBranch=\"${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\" \\\n-\t\t\tinit \\\n+\t\t\tinit ${bare:+--bare} \\\n \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n \t\terror \"cannot run git init -- have you built things yet?\"\n-\t\tmv .git/hooks .git/hooks-disabled\n+\t\tif test -z \"$bare\"\n+\t\tthen\n+\t\t\tmv .git/hooks .git/hooks-disabled\n+\t\tfi\n \t) || exit\n }\n \n-- \n2.32.0.rc0.27.g7b1e85181b\n\n"},{"id":"427747","messageId":"20210617124331.17888-2-zhiyou.jx@alibaba-inc.com","threadId":"55952","inReplyTo":"20210617124331.17888-1-zhiyou.jx@alibaba-inc.com","subject":"[PATCH 2/2] test: create repo using test_create_repo","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2021-06-17T12:43:31Z","receivedAt":"2021-06-17T12:43:47Z","isPatch":true,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"When creating new repository, function \"test_create_repo\" uses env\nGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME as default branch.  Replace\n\"git-init\" with \"test_create_repo\" in t5411, t5548 and t6020 to create\nrepository with specific default branch.\n\nSigned-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>\n---\n t/t5411-proc-receive-hook.sh | 4 ++--\n t/t5548-push-porcelain.sh    | 7 +++++--\n t/t6020-bundle-misc.sh       | 2 +-\n 3 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t5411-proc-receive-hook.sh b/t/t5411-proc-receive-hook.sh\nindex 98b0e81208..7148e5ab7e 100755\n--- a/t/t5411-proc-receive-hook.sh\n+++ b/t/t5411-proc-receive-hook.sh\n@@ -18,8 +18,8 @@ setup_upstream_and_workbench () {\n \ttest_expect_success \"setup upstream and workbench\" '\n \t\trm -rf upstream.git &&\n \t\trm -rf workbench &&\n-\t\tgit init --bare upstream.git &&\n-\t\tgit init workbench &&\n+\t\ttest_create_repo --bare upstream.git &&\n+\t\ttest_create_repo workbench &&\n \t\tcreate_commits_in workbench A B &&\n \t\t(\n \t\t\tcd workbench &&\ndiff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh\nindex 5a761f3642..8725b00a68 100755\n--- a/t/t5548-push-porcelain.sh\n+++ b/t/t5548-push-porcelain.sh\n@@ -4,6 +4,9 @@\n #\n test_description='Test git push porcelain output'\n \n+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n+\n . ./test-lib.sh\n \n # Create commits in <repo> and assign each commit's oid to shell variables\n@@ -61,8 +64,8 @@ setup_upstream_and_workbench () {\n \t# Workbench after setup : main(A)\n \ttest_expect_success \"setup upstream repository and workbench\" '\n \t\trm -rf upstream.git workbench &&\n-\t\tgit init --bare upstream.git &&\n-\t\tgit init workbench &&\n+\t\ttest_create_repo --bare upstream.git &&\n+\t\ttest_create_repo workbench &&\n \t\tcreate_commits_in workbench A B &&\n \t\t(\n \t\t\tcd workbench &&\ndiff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh\nindex 881f72fd44..4ad98a3385 100755\n--- a/t/t6020-bundle-misc.sh\n+++ b/t/t6020-bundle-misc.sh\n@@ -315,7 +315,7 @@ test_expect_success 'create bundle 2 - has prerequisites' '\n '\n \n test_expect_success 'fail to verify bundle without prerequisites' '\n-\tgit init --bare test1.git &&\n+\ttest_create_repo --bare test1.git &&\n \n \tcat >expect <<-\\EOF &&\n \terror: Repository lacks these prerequisite commits:\n-- \n2.32.0.rc0.27.g7b1e85181b\n\n"},{"id":"428215","messageId":"878s313krl.fsf@evledraar.gmail.com","threadId":"55952","inReplyTo":"20210617124331.17888-1-zhiyou.jx@alibaba-inc.com","subject":"Re: [PATCH 1/2] test-lib-functions: test_create_repo learns --bare","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-06-22T16:48:22Z","receivedAt":"2021-06-22T16:51:49Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Thu, Jun 17 2021, Jiang Xin wrote:\n\n> \"test_create_repo\" learns --bare option to create bare repository.\n>\n> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>\n> ---\n>  t/test-lib-functions.sh | 22 +++++++++++++++++++---\n>  1 file changed, 19 insertions(+), 3 deletions(-)\n>\n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> index b823c14027..f6d1afe295 100644\n> --- a/t/test-lib-functions.sh\n> +++ b/t/test-lib-functions.sh\n> @@ -1216,8 +1216,21 @@ test_atexit () {\n>  }\n>  \n>  # Most tests can use the created repository, but some may need to create more.\n> -# Usage: test_create_repo <directory>\n> +# Usage: test_create_repo [--bare] <directory>\n>  test_create_repo () {\n> +\tbare= &&\n> +\twhile test $# -gt 0\n> +\tdo\n> +\t\tcase \"$1\" in\n> +\t\t--bare)\n> +\t\t\tbare=yes\n> +\t\t\t;;\n> +\t\t*)\n> +\t\t\tbreak\n> +\t\t\t;;\n> +\t\tesac\n> +\t\tshift\n> +\tdone &&\n>  \ttest \"$#\" = 1 ||\n>  \tBUG \"not 1 parameter to test-create-repo\"\n>  \trepo=\"$1\"\n> @@ -1226,10 +1239,13 @@ test_create_repo () {\n>  \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n>  \t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" -c \\\n>  \t\t\tinit.defaultBranch=\"${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\" \\\n> -\t\t\tinit \\\n> +\t\t\tinit ${bare:+--bare} \\\n>  \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n>  \t\terror \"cannot run git init -- have you built things yet?\"\n> -\t\tmv .git/hooks .git/hooks-disabled\n> +\t\tif test -z \"$bare\"\n> +\t\tthen\n> +\t\t\tmv .git/hooks .git/hooks-disabled\n> +\t\tfi\n>  \t) || exit\n>  }\n\nIt looks like you authored this before, but sent this after f0d4d398e28\n(test-lib: split up and deprecate test_create_repo(), 2021-05-10) was\nmerged down.\n\nYour 2/2 here looks like it's not needed after my 97c8aac9c5f (test-lib:\ndo not show advice about init.defaultBranch under --verbose, 2021-05-10)\neither.\n"},{"id":"428239","messageId":"CANYiYbGCOJvVqVhWkSfAStwCF8D-U7_H=kVa6hK-oRqtmPg_dg@mail.gmail.com","threadId":"55952","inReplyTo":"878s313krl.fsf@evledraar.gmail.com","subject":"Re: [PATCH 1/2] test-lib-functions: test_create_repo learns --bare","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2021-06-23T00:53:46Z","receivedAt":"2021-06-23T00:54:00Z","isPatch":true,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> 于2021年6月23日周三 上午12:51写道：\n>\n>\n> On Thu, Jun 17 2021, Jiang Xin wrote:\n>\n> > \"test_create_repo\" learns --bare option to create bare repository.\n> >\n> > Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>\n> > ---\n> >  t/test-lib-functions.sh | 22 +++++++++++++++++++---\n> >  1 file changed, 19 insertions(+), 3 deletions(-)\n> >\n> > diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> > index b823c14027..f6d1afe295 100644\n> > --- a/t/test-lib-functions.sh\n> > +++ b/t/test-lib-functions.sh\n> > @@ -1216,8 +1216,21 @@ test_atexit () {\n> >  }\n> >\n> >  # Most tests can use the created repository, but some may need to create more.\n> > -# Usage: test_create_repo <directory>\n> > +# Usage: test_create_repo [--bare] <directory>\n> >  test_create_repo () {\n> > +     bare= &&\n> > +     while test $# -gt 0\n> > +     do\n> > +             case \"$1\" in\n> > +             --bare)\n> > +                     bare=yes\n> > +                     ;;\n> > +             *)\n> > +                     break\n> > +                     ;;\n> > +             esac\n> > +             shift\n> > +     done &&\n> >       test \"$#\" = 1 ||\n> >       BUG \"not 1 parameter to test-create-repo\"\n> >       repo=\"$1\"\n> > @@ -1226,10 +1239,13 @@ test_create_repo () {\n> >               cd \"$repo\" || error \"Cannot setup test environment\"\n> >               \"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" -c \\\n> >                       init.defaultBranch=\"${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\" \\\n> > -                     init \\\n> > +                     init ${bare:+--bare} \\\n> >                       \"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n> >               error \"cannot run git init -- have you built things yet?\"\n> > -             mv .git/hooks .git/hooks-disabled\n> > +             if test -z \"$bare\"\n> > +             then\n> > +                     mv .git/hooks .git/hooks-disabled\n> > +             fi\n> >       ) || exit\n> >  }\n>\n> It looks like you authored this before, but sent this after f0d4d398e28\n> (test-lib: split up and deprecate test_create_repo(), 2021-05-10) was\n> merged down.\n>\n> Your 2/2 here looks like it's not needed after my 97c8aac9c5f (test-lib:\n> do not show advice about init.defaultBranch under --verbose, 2021-05-10)\n> either.\n\nThanks Ævar for reminding this.\n"}]}