2007-11-19 07:22:00 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
ref-filter: add --no-contains option to tag/branch/for-each-ref
Change the tag, branch & for-each-ref commands to have a --no-contains
option in addition to their longstanding --contains options.
This allows for finding the last-good rollout tag given a known-bad
<commit>. Given a hypothetically bad commit cf5c7253e0, the git
version to revert to can be found with this hacky two-liner:
(git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253e0 'v[0-9]*') |
sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10
With this new --no-contains option the same can be achieved with:
git tag -l --no-contains cf5c7253e0 'v[0-9]*' | sort | tail -n 10
As the filtering machinery is shared between the tag, branch &
for-each-ref commands, implement this for those commands too. A
practical use for this with "branch" is e.g. finding branches which
were branched off between v2.8.0 and v2.10.0:
git branch --contains v2.8.0 --no-contains v2.10.0
The "describe" command also has a --contains option, but its semantics
are unrelated to what tag/branch/for-each-ref use --contains for. A
--no-contains option for "describe" wouldn't make any sense, other
than being exactly equivalent to not supplying --contains at all,
which would be confusing at best.
Add a --without option to "tag" as an alias for --no-contains, for
consistency with --with and --contains. The --with option is
undocumented, and possibly the only user of it is
Junio (<xmqqefy71iej.fsf@gitster.mtv.corp.google.com>). But it's
trivial to support, so let's do that.
The additions to the the test suite are inverse copies of the
corresponding --contains tests. With this change --no-contains for
tag, branch & for-each-ref is just as well tested as the existing
--contains option.
In addition to those tests, add a test for "tag" which asserts that
--no-contains won't find tree/blob tags, which is slightly
unintuitive, but consistent with how --contains works & is documented.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-24 19:40:57 +01:00
|
|
|
test_description='branch --contains <commit>, --no-contains <commit> --merged, and --no-merged'
|
2007-11-19 07:22:00 +01:00
|
|
|
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-19 00:44:19 +01:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
|
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2007-11-19 07:22:00 +01:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
|
|
|
>file &&
|
|
|
|
git add file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m initial &&
|
|
|
|
git branch side &&
|
|
|
|
|
|
|
|
echo 1 >file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -a -m "second on master" &&
|
|
|
|
|
|
|
|
git checkout side &&
|
|
|
|
echo 1 >file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -a -m "second on side" &&
|
|
|
|
|
|
|
|
git merge master
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'branch --contains=master' '
|
|
|
|
|
|
|
|
git branch --contains=master >actual &&
|
|
|
|
{
|
|
|
|
echo " master" && echo "* side"
|
|
|
|
} >expect &&
|
2008-03-12 22:36:36 +01:00
|
|
|
test_cmp expect actual
|
2007-11-19 07:22:00 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'branch --contains master' '
|
|
|
|
|
|
|
|
git branch --contains master >actual &&
|
|
|
|
{
|
|
|
|
echo " master" && echo "* side"
|
|
|
|
} >expect &&
|
2008-03-12 22:36:36 +01:00
|
|
|
test_cmp expect actual
|
2007-11-19 07:22:00 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
ref-filter: add --no-contains option to tag/branch/for-each-ref
Change the tag, branch & for-each-ref commands to have a --no-contains
option in addition to their longstanding --contains options.
This allows for finding the last-good rollout tag given a known-bad
<commit>. Given a hypothetically bad commit cf5c7253e0, the git
version to revert to can be found with this hacky two-liner:
(git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253e0 'v[0-9]*') |
sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10
With this new --no-contains option the same can be achieved with:
git tag -l --no-contains cf5c7253e0 'v[0-9]*' | sort | tail -n 10
As the filtering machinery is shared between the tag, branch &
for-each-ref commands, implement this for those commands too. A
practical use for this with "branch" is e.g. finding branches which
were branched off between v2.8.0 and v2.10.0:
git branch --contains v2.8.0 --no-contains v2.10.0
The "describe" command also has a --contains option, but its semantics
are unrelated to what tag/branch/for-each-ref use --contains for. A
--no-contains option for "describe" wouldn't make any sense, other
than being exactly equivalent to not supplying --contains at all,
which would be confusing at best.
Add a --without option to "tag" as an alias for --no-contains, for
consistency with --with and --contains. The --with option is
undocumented, and possibly the only user of it is
Junio (<xmqqefy71iej.fsf@gitster.mtv.corp.google.com>). But it's
trivial to support, so let's do that.
The additions to the the test suite are inverse copies of the
corresponding --contains tests. With this change --no-contains for
tag, branch & for-each-ref is just as well tested as the existing
--contains option.
In addition to those tests, add a test for "tag" which asserts that
--no-contains won't find tree/blob tags, which is slightly
unintuitive, but consistent with how --contains works & is documented.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-24 19:40:57 +01:00
|
|
|
test_expect_success 'branch --no-contains=master' '
|
|
|
|
|
|
|
|
git branch --no-contains=master >actual &&
|
2018-07-27 19:48:11 +02:00
|
|
|
test_must_be_empty actual
|
ref-filter: add --no-contains option to tag/branch/for-each-ref
Change the tag, branch & for-each-ref commands to have a --no-contains
option in addition to their longstanding --contains options.
This allows for finding the last-good rollout tag given a known-bad
<commit>. Given a hypothetically bad commit cf5c7253e0, the git
version to revert to can be found with this hacky two-liner:
(git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253e0 'v[0-9]*') |
sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10
With this new --no-contains option the same can be achieved with:
git tag -l --no-contains cf5c7253e0 'v[0-9]*' | sort | tail -n 10
As the filtering machinery is shared between the tag, branch &
for-each-ref commands, implement this for those commands too. A
practical use for this with "branch" is e.g. finding branches which
were branched off between v2.8.0 and v2.10.0:
git branch --contains v2.8.0 --no-contains v2.10.0
The "describe" command also has a --contains option, but its semantics
are unrelated to what tag/branch/for-each-ref use --contains for. A
--no-contains option for "describe" wouldn't make any sense, other
than being exactly equivalent to not supplying --contains at all,
which would be confusing at best.
Add a --without option to "tag" as an alias for --no-contains, for
consistency with --with and --contains. The --with option is
undocumented, and possibly the only user of it is
Junio (<xmqqefy71iej.fsf@gitster.mtv.corp.google.com>). But it's
trivial to support, so let's do that.
The additions to the the test suite are inverse copies of the
corresponding --contains tests. With this change --no-contains for
tag, branch & for-each-ref is just as well tested as the existing
--contains option.
In addition to those tests, add a test for "tag" which asserts that
--no-contains won't find tree/blob tags, which is slightly
unintuitive, but consistent with how --contains works & is documented.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-24 19:40:57 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'branch --no-contains master' '
|
|
|
|
|
|
|
|
git branch --no-contains master >actual &&
|
2018-07-27 19:48:11 +02:00
|
|
|
test_must_be_empty actual
|
ref-filter: add --no-contains option to tag/branch/for-each-ref
Change the tag, branch & for-each-ref commands to have a --no-contains
option in addition to their longstanding --contains options.
This allows for finding the last-good rollout tag given a known-bad
<commit>. Given a hypothetically bad commit cf5c7253e0, the git
version to revert to can be found with this hacky two-liner:
(git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253e0 'v[0-9]*') |
sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10
With this new --no-contains option the same can be achieved with:
git tag -l --no-contains cf5c7253e0 'v[0-9]*' | sort | tail -n 10
As the filtering machinery is shared between the tag, branch &
for-each-ref commands, implement this for those commands too. A
practical use for this with "branch" is e.g. finding branches which
were branched off between v2.8.0 and v2.10.0:
git branch --contains v2.8.0 --no-contains v2.10.0
The "describe" command also has a --contains option, but its semantics
are unrelated to what tag/branch/for-each-ref use --contains for. A
--no-contains option for "describe" wouldn't make any sense, other
than being exactly equivalent to not supplying --contains at all,
which would be confusing at best.
Add a --without option to "tag" as an alias for --no-contains, for
consistency with --with and --contains. The --with option is
undocumented, and possibly the only user of it is
Junio (<xmqqefy71iej.fsf@gitster.mtv.corp.google.com>). But it's
trivial to support, so let's do that.
The additions to the the test suite are inverse copies of the
corresponding --contains tests. With this change --no-contains for
tag, branch & for-each-ref is just as well tested as the existing
--contains option.
In addition to those tests, add a test for "tag" which asserts that
--no-contains won't find tree/blob tags, which is slightly
unintuitive, but consistent with how --contains works & is documented.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-24 19:40:57 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-11-19 07:22:00 +01:00
|
|
|
test_expect_success 'branch --contains=side' '
|
|
|
|
|
|
|
|
git branch --contains=side >actual &&
|
|
|
|
{
|
|
|
|
echo "* side"
|
|
|
|
} >expect &&
|
2008-03-12 22:36:36 +01:00
|
|
|
test_cmp expect actual
|
2007-11-19 07:22:00 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
ref-filter: add --no-contains option to tag/branch/for-each-ref
Change the tag, branch & for-each-ref commands to have a --no-contains
option in addition to their longstanding --contains options.
This allows for finding the last-good rollout tag given a known-bad
<commit>. Given a hypothetically bad commit cf5c7253e0, the git
version to revert to can be found with this hacky two-liner:
(git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253e0 'v[0-9]*') |
sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10
With this new --no-contains option the same can be achieved with:
git tag -l --no-contains cf5c7253e0 'v[0-9]*' | sort | tail -n 10
As the filtering machinery is shared between the tag, branch &
for-each-ref commands, implement this for those commands too. A
practical use for this with "branch" is e.g. finding branches which
were branched off between v2.8.0 and v2.10.0:
git branch --contains v2.8.0 --no-contains v2.10.0
The "describe" command also has a --contains option, but its semantics
are unrelated to what tag/branch/for-each-ref use --contains for. A
--no-contains option for "describe" wouldn't make any sense, other
than being exactly equivalent to not supplying --contains at all,
which would be confusing at best.
Add a --without option to "tag" as an alias for --no-contains, for
consistency with --with and --contains. The --with option is
undocumented, and possibly the only user of it is
Junio (<xmqqefy71iej.fsf@gitster.mtv.corp.google.com>). But it's
trivial to support, so let's do that.
The additions to the the test suite are inverse copies of the
corresponding --contains tests. With this change --no-contains for
tag, branch & for-each-ref is just as well tested as the existing
--contains option.
In addition to those tests, add a test for "tag" which asserts that
--no-contains won't find tree/blob tags, which is slightly
unintuitive, but consistent with how --contains works & is documented.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-24 19:40:57 +01:00
|
|
|
test_expect_success 'branch --no-contains=side' '
|
|
|
|
|
|
|
|
git branch --no-contains=side >actual &&
|
|
|
|
{
|
|
|
|
echo " master"
|
|
|
|
} >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-01-31 07:46:11 +01:00
|
|
|
test_expect_success 'branch --contains with pattern implies --list' '
|
|
|
|
|
|
|
|
git branch --contains=master master >actual &&
|
|
|
|
{
|
|
|
|
echo " master"
|
|
|
|
} >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
ref-filter: add --no-contains option to tag/branch/for-each-ref
Change the tag, branch & for-each-ref commands to have a --no-contains
option in addition to their longstanding --contains options.
This allows for finding the last-good rollout tag given a known-bad
<commit>. Given a hypothetically bad commit cf5c7253e0, the git
version to revert to can be found with this hacky two-liner:
(git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253e0 'v[0-9]*') |
sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10
With this new --no-contains option the same can be achieved with:
git tag -l --no-contains cf5c7253e0 'v[0-9]*' | sort | tail -n 10
As the filtering machinery is shared between the tag, branch &
for-each-ref commands, implement this for those commands too. A
practical use for this with "branch" is e.g. finding branches which
were branched off between v2.8.0 and v2.10.0:
git branch --contains v2.8.0 --no-contains v2.10.0
The "describe" command also has a --contains option, but its semantics
are unrelated to what tag/branch/for-each-ref use --contains for. A
--no-contains option for "describe" wouldn't make any sense, other
than being exactly equivalent to not supplying --contains at all,
which would be confusing at best.
Add a --without option to "tag" as an alias for --no-contains, for
consistency with --with and --contains. The --with option is
undocumented, and possibly the only user of it is
Junio (<xmqqefy71iej.fsf@gitster.mtv.corp.google.com>). But it's
trivial to support, so let's do that.
The additions to the the test suite are inverse copies of the
corresponding --contains tests. With this change --no-contains for
tag, branch & for-each-ref is just as well tested as the existing
--contains option.
In addition to those tests, add a test for "tag" which asserts that
--no-contains won't find tree/blob tags, which is slightly
unintuitive, but consistent with how --contains works & is documented.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-24 19:40:57 +01:00
|
|
|
test_expect_success 'branch --no-contains with pattern implies --list' '
|
|
|
|
|
|
|
|
git branch --no-contains=master master >actual &&
|
2018-07-27 19:48:11 +02:00
|
|
|
test_must_be_empty actual
|
ref-filter: add --no-contains option to tag/branch/for-each-ref
Change the tag, branch & for-each-ref commands to have a --no-contains
option in addition to their longstanding --contains options.
This allows for finding the last-good rollout tag given a known-bad
<commit>. Given a hypothetically bad commit cf5c7253e0, the git
version to revert to can be found with this hacky two-liner:
(git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253e0 'v[0-9]*') |
sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10
With this new --no-contains option the same can be achieved with:
git tag -l --no-contains cf5c7253e0 'v[0-9]*' | sort | tail -n 10
As the filtering machinery is shared between the tag, branch &
for-each-ref commands, implement this for those commands too. A
practical use for this with "branch" is e.g. finding branches which
were branched off between v2.8.0 and v2.10.0:
git branch --contains v2.8.0 --no-contains v2.10.0
The "describe" command also has a --contains option, but its semantics
are unrelated to what tag/branch/for-each-ref use --contains for. A
--no-contains option for "describe" wouldn't make any sense, other
than being exactly equivalent to not supplying --contains at all,
which would be confusing at best.
Add a --without option to "tag" as an alias for --no-contains, for
consistency with --with and --contains. The --with option is
undocumented, and possibly the only user of it is
Junio (<xmqqefy71iej.fsf@gitster.mtv.corp.google.com>). But it's
trivial to support, so let's do that.
The additions to the the test suite are inverse copies of the
corresponding --contains tests. With this change --no-contains for
tag, branch & for-each-ref is just as well tested as the existing
--contains option.
In addition to those tests, add a test for "tag" which asserts that
--no-contains won't find tree/blob tags, which is slightly
unintuitive, but consistent with how --contains works & is documented.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-24 19:40:57 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2008-04-18 18:30:15 +02:00
|
|
|
test_expect_success 'side: branch --merged' '
|
|
|
|
|
|
|
|
git branch --merged >actual &&
|
|
|
|
{
|
|
|
|
echo " master" &&
|
|
|
|
echo "* side"
|
|
|
|
} >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-01-31 07:46:11 +01:00
|
|
|
test_expect_success 'branch --merged with pattern implies --list' '
|
|
|
|
|
|
|
|
git branch --merged=side master >actual &&
|
|
|
|
{
|
|
|
|
echo " master"
|
|
|
|
} >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2008-04-18 18:30:15 +02:00
|
|
|
test_expect_success 'side: branch --no-merged' '
|
|
|
|
|
|
|
|
git branch --no-merged >actual &&
|
2018-07-27 19:48:11 +02:00
|
|
|
test_must_be_empty actual
|
2008-04-18 18:30:15 +02:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'master: branch --merged' '
|
|
|
|
|
|
|
|
git checkout master &&
|
|
|
|
git branch --merged >actual &&
|
|
|
|
{
|
|
|
|
echo "* master"
|
|
|
|
} >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'master: branch --no-merged' '
|
|
|
|
|
|
|
|
git branch --no-merged >actual &&
|
|
|
|
{
|
|
|
|
echo " side"
|
|
|
|
} >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-01-31 07:46:11 +01:00
|
|
|
test_expect_success 'branch --no-merged with pattern implies --list' '
|
|
|
|
|
|
|
|
git branch --no-merged=master master >actual &&
|
2018-07-27 19:48:11 +02:00
|
|
|
test_must_be_empty actual
|
2013-01-31 07:46:11 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'implicit --list conflicts with modification options' '
|
|
|
|
|
|
|
|
test_must_fail git branch --contains=master -d &&
|
ref-filter: add --no-contains option to tag/branch/for-each-ref
Change the tag, branch & for-each-ref commands to have a --no-contains
option in addition to their longstanding --contains options.
This allows for finding the last-good rollout tag given a known-bad
<commit>. Given a hypothetically bad commit cf5c7253e0, the git
version to revert to can be found with this hacky two-liner:
(git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253e0 'v[0-9]*') |
sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10
With this new --no-contains option the same can be achieved with:
git tag -l --no-contains cf5c7253e0 'v[0-9]*' | sort | tail -n 10
As the filtering machinery is shared between the tag, branch &
for-each-ref commands, implement this for those commands too. A
practical use for this with "branch" is e.g. finding branches which
were branched off between v2.8.0 and v2.10.0:
git branch --contains v2.8.0 --no-contains v2.10.0
The "describe" command also has a --contains option, but its semantics
are unrelated to what tag/branch/for-each-ref use --contains for. A
--no-contains option for "describe" wouldn't make any sense, other
than being exactly equivalent to not supplying --contains at all,
which would be confusing at best.
Add a --without option to "tag" as an alias for --no-contains, for
consistency with --with and --contains. The --with option is
undocumented, and possibly the only user of it is
Junio (<xmqqefy71iej.fsf@gitster.mtv.corp.google.com>). But it's
trivial to support, so let's do that.
The additions to the the test suite are inverse copies of the
corresponding --contains tests. With this change --no-contains for
tag, branch & for-each-ref is just as well tested as the existing
--contains option.
In addition to those tests, add a test for "tag" which asserts that
--no-contains won't find tree/blob tags, which is slightly
unintuitive, but consistent with how --contains works & is documented.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-24 19:40:57 +01:00
|
|
|
test_must_fail git branch --contains=master -m foo &&
|
|
|
|
test_must_fail git branch --no-contains=master -d &&
|
|
|
|
test_must_fail git branch --no-contains=master -m foo
|
2013-01-31 07:46:11 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2017-03-23 14:05:18 +01:00
|
|
|
test_expect_success 'Assert that --contains only works on commits, not trees & blobs' '
|
|
|
|
test_must_fail git branch --contains master^{tree} &&
|
|
|
|
blob=$(git hash-object -w --stdin <<-\EOF
|
|
|
|
Some blob
|
|
|
|
EOF
|
|
|
|
) &&
|
ref-filter: add --no-contains option to tag/branch/for-each-ref
Change the tag, branch & for-each-ref commands to have a --no-contains
option in addition to their longstanding --contains options.
This allows for finding the last-good rollout tag given a known-bad
<commit>. Given a hypothetically bad commit cf5c7253e0, the git
version to revert to can be found with this hacky two-liner:
(git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253e0 'v[0-9]*') |
sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10
With this new --no-contains option the same can be achieved with:
git tag -l --no-contains cf5c7253e0 'v[0-9]*' | sort | tail -n 10
As the filtering machinery is shared between the tag, branch &
for-each-ref commands, implement this for those commands too. A
practical use for this with "branch" is e.g. finding branches which
were branched off between v2.8.0 and v2.10.0:
git branch --contains v2.8.0 --no-contains v2.10.0
The "describe" command also has a --contains option, but its semantics
are unrelated to what tag/branch/for-each-ref use --contains for. A
--no-contains option for "describe" wouldn't make any sense, other
than being exactly equivalent to not supplying --contains at all,
which would be confusing at best.
Add a --without option to "tag" as an alias for --no-contains, for
consistency with --with and --contains. The --with option is
undocumented, and possibly the only user of it is
Junio (<xmqqefy71iej.fsf@gitster.mtv.corp.google.com>). But it's
trivial to support, so let's do that.
The additions to the the test suite are inverse copies of the
corresponding --contains tests. With this change --no-contains for
tag, branch & for-each-ref is just as well tested as the existing
--contains option.
In addition to those tests, add a test for "tag" which asserts that
--no-contains won't find tree/blob tags, which is slightly
unintuitive, but consistent with how --contains works & is documented.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-24 19:40:57 +01:00
|
|
|
test_must_fail git branch --contains $blob &&
|
|
|
|
test_must_fail git branch --no-contains $blob
|
2017-03-23 14:05:18 +01:00
|
|
|
'
|
|
|
|
|
2020-09-16 04:08:38 +02:00
|
|
|
test_expect_success 'multiple branch --contains' '
|
|
|
|
git checkout -b side2 master &&
|
|
|
|
>feature &&
|
|
|
|
git add feature &&
|
|
|
|
git commit -m "add feature" &&
|
|
|
|
git checkout -b next master &&
|
|
|
|
git merge side &&
|
|
|
|
git branch --contains side --contains side2 >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
* next
|
|
|
|
side
|
|
|
|
side2
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2020-09-16 04:08:40 +02:00
|
|
|
test_expect_success 'multiple branch --merged' '
|
|
|
|
git branch --merged next --merged master >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
master
|
|
|
|
* next
|
|
|
|
side
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2020-09-16 04:08:38 +02:00
|
|
|
test_expect_success 'multiple branch --no-contains' '
|
|
|
|
git branch --no-contains side --no-contains side2 >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
master
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2020-09-16 04:08:40 +02:00
|
|
|
test_expect_success 'multiple branch --no-merged' '
|
|
|
|
git branch --no-merged next --no-merged master >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
side2
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2020-09-16 04:08:38 +02:00
|
|
|
test_expect_success 'branch --contains combined with --no-contains' '
|
|
|
|
git checkout -b seen master &&
|
|
|
|
git merge side &&
|
|
|
|
git merge side2 &&
|
|
|
|
git branch --contains side --no-contains side2 >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
next
|
|
|
|
side
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2020-09-16 04:08:40 +02:00
|
|
|
test_expect_success 'branch --merged combined with --no-merged' '
|
|
|
|
git branch --merged seen --no-merged next >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
* seen
|
|
|
|
side2
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2014-09-18 12:49:43 +02:00
|
|
|
# We want to set up a case where the walk for the tracking info
|
|
|
|
# of one branch crosses the tip of another branch (and make sure
|
|
|
|
# that the latter walk does not mess up our flag to see if it was
|
|
|
|
# merged).
|
|
|
|
#
|
|
|
|
# Here "topic" tracks "master" with one extra commit, and "zzz" points to the
|
|
|
|
# same tip as master The name "zzz" must come alphabetically after "topic"
|
|
|
|
# as we process them in that order.
|
2020-10-23 16:00:05 +02:00
|
|
|
test_expect_success PREPARE_FOR_MAIN_BRANCH 'branch --merged with --verbose' '
|
2014-09-18 12:49:43 +02:00
|
|
|
git branch --track topic master &&
|
|
|
|
git branch zzz topic &&
|
|
|
|
git checkout topic &&
|
|
|
|
test_commit foo &&
|
|
|
|
git branch --merged topic >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
master
|
|
|
|
* topic
|
|
|
|
zzz
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git branch --verbose --merged topic >actual &&
|
2019-08-18 21:16:33 +02:00
|
|
|
cat >expect <<-EOF &&
|
2020-10-23 16:00:05 +02:00
|
|
|
main $(git rev-parse --short main) second on main
|
|
|
|
* topic $(git rev-parse --short topic ) [ahead 1] foo
|
|
|
|
zzz $(git rev-parse --short zzz ) second on main
|
2014-09-18 12:49:43 +02:00
|
|
|
EOF
|
2016-06-17 22:21:07 +02:00
|
|
|
test_i18ncmp expect actual
|
2014-09-18 12:49:43 +02:00
|
|
|
'
|
|
|
|
|
2007-11-19 07:22:00 +01:00
|
|
|
test_done
|