Skip to content

Commit 477cc3b

Browse files
committed
Merge branch 'jc/name-rev-stdin'
Using "git name-rev --stdin" as an example, improve the framework to prepare tests to pretend to be in the future where the breaking changes have already happened. * jc/name-rev-stdin: name-rev: remove "--stdin" support t6120: further modernize t6120: avoid hiding "git" exit status t: introduce WITH_BREAKING_CHANGES prerequisite t: extend test_lazy_prereq t: document test_lazy_prereq
2 parents e63c3e4 + de3dec1 commit 477cc3b

File tree

10 files changed

+72
-17
lines changed

10 files changed

+72
-17
lines changed

Documentation/BreakingChanges.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ references.
178178
+
179179
These features will be removed.
180180

181+
* Support for "--stdin" option in the "name-rev" command was
182+
deprecated (and hidden from the documentation) in the Git 2.40
183+
timeframe, in preference to its synonym "--annotate-stdin". Git 3.0
184+
removes the support for "--stdin" altogether.
185+
186+
181187
== Superseded features that will not be deprecated
182188

183189
Some features have gained newer replacements that aim to improve the design in

builtin/name-rev.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,11 @@ int cmd_name_rev(int argc,
567567
{
568568
struct mem_pool string_pool;
569569
struct object_array revs = OBJECT_ARRAY_INIT;
570-
int all = 0, annotate_stdin = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
570+
571+
#ifndef WITH_BREAKING_CHANGES
572+
int transform_stdin = 0;
573+
#endif
574+
int all = 0, annotate_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
571575
struct name_ref_data data = { 0, 0, STRING_LIST_INIT_NODUP, STRING_LIST_INIT_NODUP };
572576
struct option opts[] = {
573577
OPT_BOOL(0, "name-only", &data.name_only, N_("print only ref-based names (no object names)")),
@@ -578,11 +582,13 @@ int cmd_name_rev(int argc,
578582
N_("ignore refs matching <pattern>")),
579583
OPT_GROUP(""),
580584
OPT_BOOL(0, "all", &all, N_("list all commits reachable from all refs")),
585+
#ifndef WITH_BREAKING_CHANGES
581586
OPT_BOOL_F(0,
582587
"stdin",
583588
&transform_stdin,
584589
N_("deprecated: use --annotate-stdin instead"),
585590
PARSE_OPT_HIDDEN),
591+
#endif /* WITH_BREAKING_CHANGES */
586592
OPT_BOOL(0, "annotate-stdin", &annotate_stdin, N_("annotate text from stdin")),
587593
OPT_BOOL(0, "undefined", &allow_undefined, N_("allow to print `undefined` names (default)")),
588594
OPT_BOOL(0, "always", &always,
@@ -597,12 +603,14 @@ int cmd_name_rev(int argc,
597603
git_config(git_default_config, NULL);
598604
argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
599605

606+
#ifndef WITH_BREAKING_CHANGES
600607
if (transform_stdin) {
601608
warning("--stdin is deprecated. Please use --annotate-stdin instead, "
602609
"which is functionally equivalent.\n"
603610
"This option will be removed in a future release.");
604611
annotate_stdin = 1;
605612
}
613+
#endif
606614

607615
if (all + annotate_stdin + !!argc > 1) {
608616
error("Specify either a list, or --all, not both!");

t/README

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ Skipping tests
818818
--------------
819819

820820
If you need to skip tests you should do so by using the three-arg form
821-
of the test_* functions (see the "Test harness library" section
821+
of the test_expect_* functions (see the "Test harness library" section
822822
below), e.g.:
823823

824824
test_expect_success PERL 'I need Perl' '
@@ -965,6 +965,29 @@ see test-lib-functions.sh for the full list and their options.
965965
test_done
966966
fi
967967

968+
- test_lazy_prereq <prereq> <script>
969+
970+
Declare the way to determine if a test prerequisite <prereq> is
971+
satisified or not, but delay the actual determination until the
972+
prerequisite is actually used by "test_have_prereq" or the
973+
three-arg form of the test_expect_* functions. For example, this
974+
is how the SYMLINKS prerequisite is declared to see if the platform
975+
supports symbolic links:
976+
977+
test_lazy_prereq SYMLINKS '
978+
ln -s x y && test -h y
979+
'
980+
981+
The script is lazily invoked when SYMLINKS prerequisite is first
982+
queried by either "test_have_prereq SYMLINKS" or "test_expect_*
983+
SYMLINKS ...". The script is run in a temporary directory inside
984+
a subshell, so you do not have to worry about removing temporary
985+
files you create there. When the script exits with status 0, the
986+
prerequisite is set. Exiting with non-zero status other than 125
987+
makes the prerequisite unsatisified. Exiting the script with 125
988+
signals a programming error and is used to mark a prerequisite that
989+
should not be used by test scripts.
990+
968991
- test_expect_code <exit-code> <command>
969992

970993
Run a command and ensure that it exits with the given exit code.

t/t5323-pack-redundant.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ relationship between packs and objects is as follows:
3636

3737
. ./test-lib.sh
3838

39-
if ! test_have_prereq WITHOUT_BREAKING_CHANGES
39+
if test_have_prereq WITH_BREAKING_CHANGES
4040
then
4141
skip_all='skipping git-pack-redundant tests; built with breaking changes'
4242
test_done

t/t5505-remote.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ Pull: refs/heads/main:refs/heads/origin
11231123
Pull: refs/heads/next:refs/heads/origin2
11241124
EOF
11251125

1126-
test_expect_success WITHOUT_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/remotes' '
1126+
test_expect_success !WITH_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/remotes' '
11271127
git clone one five &&
11281128
origin_url=$(pwd)/one &&
11291129
(
@@ -1149,7 +1149,7 @@ test_expect_success WITHOUT_BREAKING_CHANGES 'migrate a remote from named file i
11491149
)
11501150
'
11511151

1152-
test_expect_success WITHOUT_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/branches' '
1152+
test_expect_success !WITH_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/branches' '
11531153
git clone --template= one six &&
11541154
origin_url=$(pwd)/one &&
11551155
(
@@ -1165,7 +1165,7 @@ test_expect_success WITHOUT_BREAKING_CHANGES 'migrate a remote from named file i
11651165
)
11661166
'
11671167

1168-
test_expect_success WITHOUT_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/branches (2)' '
1168+
test_expect_success !WITH_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/branches (2)' '
11691169
git clone --template= one seven &&
11701170
(
11711171
cd seven &&

t/t5515-fetch-merge-logic.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test_expect_success setup '
104104
git config remote.config-glob.fetch refs/heads/*:refs/remotes/rem/* &&
105105
remotes="$remotes config-glob" &&
106106
107-
if test_have_prereq WITHOUT_BREAKING_CHANGES
107+
if ! test_have_prereq WITH_BREAKING_CHANGES
108108
then
109109
mkdir -p .git/remotes &&
110110
cat >.git/remotes/remote-explicit <<-\EOF &&

t/t5516-fetch-push.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ test_expect_success 'allow push to HEAD of non-bare repository (config)' '
975975
! grep "warning: updating the current branch" stderr
976976
'
977977

978-
test_expect_success WITHOUT_BREAKING_CHANGES 'fetch with branches' '
978+
test_expect_success !WITH_BREAKING_CHANGES 'fetch with branches' '
979979
mk_empty testrepo &&
980980
git branch second $the_first_commit &&
981981
git checkout second &&
@@ -991,7 +991,7 @@ test_expect_success WITHOUT_BREAKING_CHANGES 'fetch with branches' '
991991
git checkout main
992992
'
993993

994-
test_expect_success WITHOUT_BREAKING_CHANGES 'fetch with branches containing #' '
994+
test_expect_success !WITH_BREAKING_CHANGES 'fetch with branches containing #' '
995995
mk_empty testrepo &&
996996
mkdir testrepo/.git/branches &&
997997
echo "..#second" > testrepo/.git/branches/branch2 &&
@@ -1005,7 +1005,7 @@ test_expect_success WITHOUT_BREAKING_CHANGES 'fetch with branches containing #'
10051005
git checkout main
10061006
'
10071007

1008-
test_expect_success WITHOUT_BREAKING_CHANGES 'push with branches' '
1008+
test_expect_success !WITH_BREAKING_CHANGES 'push with branches' '
10091009
mk_empty testrepo &&
10101010
git checkout second &&
10111011
@@ -1022,7 +1022,7 @@ test_expect_success WITHOUT_BREAKING_CHANGES 'push with branches' '
10221022
)
10231023
'
10241024

1025-
test_expect_success WITHOUT_BREAKING_CHANGES 'push with branches containing #' '
1025+
test_expect_success !WITH_BREAKING_CHANGES 'push with branches containing #' '
10261026
mk_empty testrepo &&
10271027
10281028
test_when_finished "rm -rf .git/branches" &&

t/t6120-describe.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,23 @@ test_expect_success 'name-rev --annotate-stdin' '
292292
echo "$rev ($name)" >>expect.unsorted || return 1
293293
done &&
294294
sort <expect.unsorted >expect &&
295-
git rev-list --all | git name-rev --annotate-stdin >actual.unsorted &&
295+
git rev-list --all >list &&
296+
git name-rev --annotate-stdin <list >actual.unsorted &&
296297
sort <actual.unsorted >actual &&
297298
test_cmp expect actual
298299
'
299300

300-
test_expect_success 'name-rev --stdin deprecated' "
301-
git rev-list --all | git name-rev --stdin 2>actual &&
302-
grep -E 'warning: --stdin is deprecated' actual
303-
"
301+
test_expect_success 'name-rev --stdin deprecated' '
302+
git rev-list --all >list &&
303+
if ! test_have_prereq WITH_BREAKING_CHANGES
304+
then
305+
git name-rev --stdin <list 2>actual &&
306+
test_grep "warning: --stdin is deprecated" actual
307+
else
308+
test_must_fail git name-rev --stdin <list 2>actual &&
309+
test_grep "unknown option .stdin." actual
310+
fi
311+
'
304312

305313
test_expect_success 'describe --contains with the exact tags' '
306314
echo "A^0" >expect &&

t/test-lib-functions.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,8 @@ mkdir -p "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&
773773
rm -rf "$TRASH_DIRECTORY/prereq-test-dir-$1"
774774
if test "$eval_ret" = 0; then
775775
say >&3 "prerequisite $1 ok"
776+
elif test "$eval_ret" = 125; then
777+
:;
776778
else
777779
say >&3 "prerequisite $1 not satisfied"
778780
fi
@@ -811,6 +813,9 @@ test_have_prereq () {
811813
if test_run_lazy_prereq_ "$prerequisite" "$script"
812814
then
813815
test_set_prereq $prerequisite
816+
elif test $? = 125
817+
then
818+
BUG "Do not use $prerequisite"
814819
fi
815820
lazily_tested_prereq="$lazily_tested_prereq$prerequisite "
816821
esac

t/test-lib.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1862,8 +1862,13 @@ test_lazy_prereq CURL '
18621862
curl --version
18631863
'
18641864

1865+
test_lazy_prereq WITH_BREAKING_CHANGES '
1866+
test -n "$WITH_BREAKING_CHANGES"
1867+
'
1868+
18651869
test_lazy_prereq WITHOUT_BREAKING_CHANGES '
1866-
test -z "$WITH_BREAKING_CHANGES"
1870+
# Signal that this prereq should not be used.
1871+
exit 125
18671872
'
18681873

18691874
# SHA1 is a test if the hash algorithm in use is SHA-1. This is both for tests

0 commit comments

Comments
 (0)