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
This commit is contained in:
Junio C Hamano
2025-04-07 14:23:17 -07:00
10 changed files with 72 additions and 17 deletions

View File

@@ -178,6 +178,12 @@ references.
+
These features will be removed.
* Support for "--stdin" option in the "name-rev" command was
deprecated (and hidden from the documentation) in the Git 2.40
timeframe, in preference to its synonym "--annotate-stdin". Git 3.0
removes the support for "--stdin" altogether.
== Superseded features that will not be deprecated
Some features have gained newer replacements that aim to improve the design in

View File

@@ -567,7 +567,11 @@ int cmd_name_rev(int argc,
{
struct mem_pool string_pool;
struct object_array revs = OBJECT_ARRAY_INIT;
int all = 0, annotate_stdin = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
#ifndef WITH_BREAKING_CHANGES
int transform_stdin = 0;
#endif
int all = 0, annotate_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
struct name_ref_data data = { 0, 0, STRING_LIST_INIT_NODUP, STRING_LIST_INIT_NODUP };
struct option opts[] = {
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,
N_("ignore refs matching <pattern>")),
OPT_GROUP(""),
OPT_BOOL(0, "all", &all, N_("list all commits reachable from all refs")),
#ifndef WITH_BREAKING_CHANGES
OPT_BOOL_F(0,
"stdin",
&transform_stdin,
N_("deprecated: use --annotate-stdin instead"),
PARSE_OPT_HIDDEN),
#endif /* WITH_BREAKING_CHANGES */
OPT_BOOL(0, "annotate-stdin", &annotate_stdin, N_("annotate text from stdin")),
OPT_BOOL(0, "undefined", &allow_undefined, N_("allow to print `undefined` names (default)")),
OPT_BOOL(0, "always", &always,
@@ -597,12 +603,14 @@ int cmd_name_rev(int argc,
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
#ifndef WITH_BREAKING_CHANGES
if (transform_stdin) {
warning("--stdin is deprecated. Please use --annotate-stdin instead, "
"which is functionally equivalent.\n"
"This option will be removed in a future release.");
annotate_stdin = 1;
}
#endif
if (all + annotate_stdin + !!argc > 1) {
error("Specify either a list, or --all, not both!");

View File

@@ -818,7 +818,7 @@ Skipping tests
--------------
If you need to skip tests you should do so by using the three-arg form
of the test_* functions (see the "Test harness library" section
of the test_expect_* functions (see the "Test harness library" section
below), e.g.:
test_expect_success PERL 'I need Perl' '
@@ -965,6 +965,29 @@ see test-lib-functions.sh for the full list and their options.
test_done
fi
- test_lazy_prereq <prereq> <script>
Declare the way to determine if a test prerequisite <prereq> is
satisified or not, but delay the actual determination until the
prerequisite is actually used by "test_have_prereq" or the
three-arg form of the test_expect_* functions. For example, this
is how the SYMLINKS prerequisite is declared to see if the platform
supports symbolic links:
test_lazy_prereq SYMLINKS '
ln -s x y && test -h y
'
The script is lazily invoked when SYMLINKS prerequisite is first
queried by either "test_have_prereq SYMLINKS" or "test_expect_*
SYMLINKS ...". The script is run in a temporary directory inside
a subshell, so you do not have to worry about removing temporary
files you create there. When the script exits with status 0, the
prerequisite is set. Exiting with non-zero status other than 125
makes the prerequisite unsatisified. Exiting the script with 125
signals a programming error and is used to mark a prerequisite that
should not be used by test scripts.
- test_expect_code <exit-code> <command>
Run a command and ensure that it exits with the given exit code.

View File

@@ -36,7 +36,7 @@ relationship between packs and objects is as follows:
. ./test-lib.sh
if ! test_have_prereq WITHOUT_BREAKING_CHANGES
if test_have_prereq WITH_BREAKING_CHANGES
then
skip_all='skipping git-pack-redundant tests; built with breaking changes'
test_done

View File

@@ -1123,7 +1123,7 @@ Pull: refs/heads/main:refs/heads/origin
Pull: refs/heads/next:refs/heads/origin2
EOF
test_expect_success WITHOUT_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/remotes' '
test_expect_success !WITH_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/remotes' '
git clone one five &&
origin_url=$(pwd)/one &&
(
@@ -1149,7 +1149,7 @@ test_expect_success WITHOUT_BREAKING_CHANGES 'migrate a remote from named file i
)
'
test_expect_success WITHOUT_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/branches' '
test_expect_success !WITH_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/branches' '
git clone --template= one six &&
origin_url=$(pwd)/one &&
(
@@ -1165,7 +1165,7 @@ test_expect_success WITHOUT_BREAKING_CHANGES 'migrate a remote from named file i
)
'
test_expect_success WITHOUT_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/branches (2)' '
test_expect_success !WITH_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/branches (2)' '
git clone --template= one seven &&
(
cd seven &&

View File

@@ -104,7 +104,7 @@ test_expect_success setup '
git config remote.config-glob.fetch refs/heads/*:refs/remotes/rem/* &&
remotes="$remotes config-glob" &&
if test_have_prereq WITHOUT_BREAKING_CHANGES
if ! test_have_prereq WITH_BREAKING_CHANGES
then
mkdir -p .git/remotes &&
cat >.git/remotes/remote-explicit <<-\EOF &&

View File

@@ -975,7 +975,7 @@ test_expect_success 'allow push to HEAD of non-bare repository (config)' '
! grep "warning: updating the current branch" stderr
'
test_expect_success WITHOUT_BREAKING_CHANGES 'fetch with branches' '
test_expect_success !WITH_BREAKING_CHANGES 'fetch with branches' '
mk_empty testrepo &&
git branch second $the_first_commit &&
git checkout second &&
@@ -991,7 +991,7 @@ test_expect_success WITHOUT_BREAKING_CHANGES 'fetch with branches' '
git checkout main
'
test_expect_success WITHOUT_BREAKING_CHANGES 'fetch with branches containing #' '
test_expect_success !WITH_BREAKING_CHANGES 'fetch with branches containing #' '
mk_empty testrepo &&
mkdir testrepo/.git/branches &&
echo "..#second" > testrepo/.git/branches/branch2 &&
@@ -1005,7 +1005,7 @@ test_expect_success WITHOUT_BREAKING_CHANGES 'fetch with branches containing #'
git checkout main
'
test_expect_success WITHOUT_BREAKING_CHANGES 'push with branches' '
test_expect_success !WITH_BREAKING_CHANGES 'push with branches' '
mk_empty testrepo &&
git checkout second &&
@@ -1022,7 +1022,7 @@ test_expect_success WITHOUT_BREAKING_CHANGES 'push with branches' '
)
'
test_expect_success WITHOUT_BREAKING_CHANGES 'push with branches containing #' '
test_expect_success !WITH_BREAKING_CHANGES 'push with branches containing #' '
mk_empty testrepo &&
test_when_finished "rm -rf .git/branches" &&

View File

@@ -292,15 +292,23 @@ test_expect_success 'name-rev --annotate-stdin' '
echo "$rev ($name)" >>expect.unsorted || return 1
done &&
sort <expect.unsorted >expect &&
git rev-list --all | git name-rev --annotate-stdin >actual.unsorted &&
git rev-list --all >list &&
git name-rev --annotate-stdin <list >actual.unsorted &&
sort <actual.unsorted >actual &&
test_cmp expect actual
'
test_expect_success 'name-rev --stdin deprecated' "
git rev-list --all | git name-rev --stdin 2>actual &&
grep -E 'warning: --stdin is deprecated' actual
"
test_expect_success 'name-rev --stdin deprecated' '
git rev-list --all >list &&
if ! test_have_prereq WITH_BREAKING_CHANGES
then
git name-rev --stdin <list 2>actual &&
test_grep "warning: --stdin is deprecated" actual
else
test_must_fail git name-rev --stdin <list 2>actual &&
test_grep "unknown option .stdin." actual
fi
'
test_expect_success 'describe --contains with the exact tags' '
echo "A^0" >expect &&

View File

@@ -773,6 +773,8 @@ mkdir -p "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&
rm -rf "$TRASH_DIRECTORY/prereq-test-dir-$1"
if test "$eval_ret" = 0; then
say >&3 "prerequisite $1 ok"
elif test "$eval_ret" = 125; then
:;
else
say >&3 "prerequisite $1 not satisfied"
fi
@@ -811,6 +813,9 @@ test_have_prereq () {
if test_run_lazy_prereq_ "$prerequisite" "$script"
then
test_set_prereq $prerequisite
elif test $? = 125
then
BUG "Do not use $prerequisite"
fi
lazily_tested_prereq="$lazily_tested_prereq$prerequisite "
esac

View File

@@ -1862,8 +1862,13 @@ test_lazy_prereq CURL '
curl --version
'
test_lazy_prereq WITH_BREAKING_CHANGES '
test -n "$WITH_BREAKING_CHANGES"
'
test_lazy_prereq WITHOUT_BREAKING_CHANGES '
test -z "$WITH_BREAKING_CHANGES"
# Signal that this prereq should not be used.
exit 125
'
# SHA1 is a test if the hash algorithm in use is SHA-1. This is both for tests