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
|
|
|
|
|
|
|
. ./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 &&
|
|
|
|
>expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'branch --no-contains master' '
|
|
|
|
|
|
|
|
git branch --no-contains master >actual &&
|
|
|
|
>expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
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 &&
|
|
|
|
>expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
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 &&
|
|
|
|
>expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
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 &&
|
|
|
|
>expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
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
|
|
|
'
|
|
|
|
|
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.
|
|
|
|
test_expect_success 'branch --merged with --verbose' '
|
|
|
|
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 &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
master c77a0a9 second on master
|
|
|
|
* topic 2c939f4 [ahead 1] foo
|
|
|
|
zzz c77a0a9 second on master
|
|
|
|
EOF
|
2016-06-17 22:21:07 +02:00
|
|
|
test_i18ncmp expect actual
|
2014-09-18 12:49:43 +02: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 --contains combined with --no-contains' '
|
|
|
|
git branch --contains zzz --no-contains topic >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
master
|
|
|
|
side
|
|
|
|
zzz
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-11-19 07:22:00 +01:00
|
|
|
test_done
|