Imported Upstream version 2.13.0
[platform/upstream/git.git] / t / t7004-tag.sh
index 072e6c6..bb2e4d7 100755 (executable)
@@ -16,7 +16,6 @@ tag_exists () {
        git show-ref --quiet --verify refs/tags/"$1"
 }
 
-# todo: git tag -l now returns always zero, when fixed, change this test
 test_expect_success 'listing all tags in an empty tree should succeed' '
        git tag -l &&
        git tag
@@ -81,9 +80,25 @@ test_expect_success 'creating a tag using default HEAD should succeed' '
 '
 
 test_expect_success 'creating a tag with --create-reflog should create reflog' '
+       git log -1 \
+               --format="format:tag: tagging %h (%s, %cd)%n" \
+               --date=format:%Y-%m-%d >expected &&
        test_when_finished "git tag -d tag_with_reflog" &&
        git tag --create-reflog tag_with_reflog &&
-       git reflog exists refs/tags/tag_with_reflog
+       git reflog exists refs/tags/tag_with_reflog &&
+       sed -e "s/^.*   //" .git/logs/refs/tags/tag_with_reflog >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'annotated tag with --create-reflog has correct message' '
+       git log -1 \
+               --format="format:tag: tagging %h (%s, %cd)%n" \
+               --date=format:%Y-%m-%d >expected &&
+       test_when_finished "git tag -d tag_with_reflog" &&
+       git tag -m "annotated tag" --create-reflog tag_with_reflog &&
+       git reflog exists refs/tags/tag_with_reflog &&
+       sed -e "s/^.*   //" .git/logs/refs/tags/tag_with_reflog >actual &&
+       test_cmp expected actual
 '
 
 test_expect_success '--create-reflog does not create reflog on failure' '
@@ -103,6 +118,18 @@ test_expect_success 'listing all tags if one exists should succeed' '
        git tag
 '
 
+cat >expect <<EOF
+mytag
+EOF
+test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
+       git tag -l -l >actual &&
+       test_cmp expect actual &&
+       git tag --list --list >actual &&
+       test_cmp expect actual &&
+       git tag --list -l --list >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'listing all tags if one exists should output that tag' '
        test $(git tag -l) = mytag &&
        test $(git tag) = mytag
@@ -120,9 +147,8 @@ test_expect_success \
        'listing a tag using a matching pattern should output that tag' \
        'test $(git tag -l mytag) = mytag'
 
-# todo: git tag -l now returns always zero, when fixed, change this test
 test_expect_success \
-       'listing tags using a non-matching pattern should suceed' \
+       'listing tags using a non-matching pattern should succeed' \
        'git tag -l xxx'
 
 test_expect_success \
@@ -322,6 +348,19 @@ test_expect_success 'tag -l can accept multiple patterns' '
        test_cmp expect actual
 '
 
+# Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
+# could leave you with the impression that "-l <pattern> -l <pattern>"
+# was how we wanted to accept multiple patterns.
+#
+# This test should not imply that this is a sane thing to support. but
+# since the documentation was worded like it was let's at least find
+# out if we're going to break this long-documented form of taking
+# multiple patterns.
+test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
+       git tag -l "v1*" -l "v0*" >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'listing tags in column' '
        COLUMNS=40 git tag -l --column=row >actual &&
        cat >expected <<\EOF &&
@@ -604,6 +643,11 @@ test_expect_success \
        git tag -n0 -l tag-one-line >actual &&
        test_cmp expect actual &&
 
+       git tag -n0 | grep "^tag-one-line" >actual &&
+       test_cmp expect actual &&
+       git tag -n0 tag-one-line >actual &&
+       test_cmp expect actual &&
+
        echo "tag-one-line    A msg" >expect &&
        git tag -n1 -l | grep "^tag-one-line" >actual &&
        test_cmp expect actual &&
@@ -617,6 +661,17 @@ test_expect_success \
        test_cmp expect actual
 '
 
+test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
+       >expect &&
+       git tag -n 100 >actual &&
+       test_cmp expect actual &&
+
+       git tag -m "A msg" 100 &&
+       echo "100             A msg" >expect &&
+       git tag -n 100 >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success \
        'listing the zero-lines message of a non-signed tag should succeed' '
        git tag -m "" tag-zero-lines &&
@@ -879,18 +934,16 @@ test_expect_success GPG 'verifying a forged tag should fail' '
        test_must_fail git tag -v forged-tag
 '
 
-test_expect_success 'verifying a proper tag with --format pass and format accordingly' '
-       cat >expect <<-\EOF
+test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
+       cat >expect <<-\EOF &&
        tagname : signed-tag
-       EOF &&
+       EOF
        git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
        test_cmp expect actual
 '
 
-test_expect_success 'verifying a forged tag with --format fail and format accordingly' '
-       cat >expect <<-\EOF
-       tagname : forged-tag
-       EOF &&
+test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
+       >expect &&
        test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
        test_cmp expect actual
 '
@@ -1369,6 +1422,23 @@ test_expect_success 'checking that first commit is in all tags (relative)' "
        test_cmp expected actual
 "
 
+# All the --contains tests above, but with --no-contains
+test_expect_success 'checking that first commit is not listed in any tag with --no-contains  (hash)' "
+       >expected &&
+       git tag -l --no-contains $hash1 v* >actual &&
+       test_cmp expected actual
+"
+
+test_expect_success 'checking that first commit is in all tags (tag)' "
+       git tag -l --no-contains v1.0 v* >actual &&
+       test_cmp expected actual
+"
+
+test_expect_success 'checking that first commit is in all tags (relative)' "
+       git tag -l --no-contains HEAD~2 v* >actual &&
+       test_cmp expected actual
+"
+
 cat > expected <<EOF
 v2.0
 EOF
@@ -1378,6 +1448,17 @@ test_expect_success 'checking that second commit only has one tag' "
        test_cmp expected actual
 "
 
+cat > expected <<EOF
+v0.2.1
+v1.0
+v1.0.1
+v1.1.3
+EOF
+
+test_expect_success 'inverse of the last test, with --no-contains' "
+       git tag -l --no-contains $hash2 v* >actual &&
+       test_cmp expected actual
+"
 
 cat > expected <<EOF
 EOF
@@ -1387,6 +1468,19 @@ test_expect_success 'checking that third commit has no tags' "
        test_cmp expected actual
 "
 
+cat > expected <<EOF
+v0.2.1
+v1.0
+v1.0.1
+v1.1.3
+v2.0
+EOF
+
+test_expect_success 'conversely --no-contains on the third commit lists all tags' "
+       git tag -l --no-contains $hash3 v* >actual &&
+       test_cmp expected actual
+"
+
 # how about a simple merge?
 
 test_expect_success 'creating simple branch' '
@@ -1408,6 +1502,19 @@ test_expect_success 'checking that branch head only has one tag' "
        test_cmp expected actual
 "
 
+cat > expected <<EOF
+v0.2.1
+v1.0
+v1.0.1
+v1.1.3
+v2.0
+EOF
+
+test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
+       git tag -l --no-contains $hash4 v* >actual &&
+       test_cmp expected actual
+"
+
 test_expect_success 'merging original branch into this branch' '
        git merge --strategy=ours master &&
         git tag v4.0
@@ -1429,6 +1536,20 @@ v1.0.1
 v1.1.3
 v2.0
 v3.0
+EOF
+
+test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
+       git tag -l --no-contains $hash3 v* >actual &&
+       test_cmp expected actual
+"
+
+cat > expected <<EOF
+v0.2.1
+v1.0
+v1.0.1
+v1.1.3
+v2.0
+v3.0
 v4.0
 EOF
 
@@ -1437,21 +1558,76 @@ test_expect_success 'checking that initial commit is in all tags' "
        test_cmp expected actual
 "
 
+test_expect_success 'checking that --contains can be used in non-list mode' '
+       git tag --contains $hash1 v* >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'checking that initial commit is in all tags with --no-contains' "
+       >expected &&
+       git tag -l --no-contains $hash1 v* >actual &&
+       test_cmp expected actual
+"
+
 # mixing modes and options:
 
 test_expect_success 'mixing incompatibles modes and options is forbidden' '
        test_must_fail git tag -a &&
+       test_must_fail git tag -a -l &&
+       test_must_fail git tag -s &&
+       test_must_fail git tag -s -l &&
+       test_must_fail git tag -m &&
+       test_must_fail git tag -m -l &&
+       test_must_fail git tag -m "hlagh" &&
+       test_must_fail git tag -m "hlagh" -l &&
+       test_must_fail git tag -F &&
+       test_must_fail git tag -F -l &&
+       test_must_fail git tag -f &&
+       test_must_fail git tag -f -l &&
+       test_must_fail git tag -a -s -m -F &&
+       test_must_fail git tag -a -s -m -F -l &&
        test_must_fail git tag -l -v &&
-       test_must_fail git tag -n 100 &&
+       test_must_fail git tag -l -d &&
+       test_must_fail git tag -l -v -d &&
+       test_must_fail git tag -n 100 -v &&
        test_must_fail git tag -l -m msg &&
        test_must_fail git tag -l -F some file &&
-       test_must_fail git tag -v -s
-'
+       test_must_fail git tag -v -s &&
+       test_must_fail git tag --contains tag-tree &&
+       test_must_fail git tag --contains tag-blob &&
+       test_must_fail git tag --no-contains tag-tree &&
+       test_must_fail git tag --no-contains tag-blob &&
+       test_must_fail git tag --contains --no-contains &&
+       test_must_fail git tag --no-with HEAD &&
+       test_must_fail git tag --no-without HEAD
+'
+
+for option in --contains --with --no-contains --without --merged --no-merged --points-at
+do
+       test_expect_success "mixing incompatible modes with $option is forbidden" "
+               test_must_fail git tag -d $option HEAD &&
+               test_must_fail git tag -d $option HEAD some-tag &&
+               test_must_fail git tag -v $option HEAD
+       "
+       test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
+               git tag -n $option HEAD HEAD &&
+               git tag $option HEAD HEAD &&
+               git tag $option
+       "
+done
 
 # check points-at
 
-test_expect_success '--points-at cannot be used in non-list mode' '
-       test_must_fail git tag --points-at=v4.0 foo
+test_expect_success '--points-at can be used in non-list mode' '
+       echo v4.0 >expect &&
+       git tag --points-at=v4.0 "v*" >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--points-at is a synonym for --points-at HEAD' '
+       echo v4.0 >expect &&
+       git tag --points-at >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success '--points-at finds lightweight tags' '
@@ -1693,7 +1869,7 @@ run_with_limited_stack () {
 test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
 
 # we require ulimit, this excludes Windows
-test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' '
+test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
        >expect &&
        i=1 &&
        while test $i -lt 8000
@@ -1709,7 +1885,9 @@ EOF"
        git checkout master &&
        git tag far-far-away HEAD^ &&
        run_with_limited_stack git tag --contains HEAD >actual &&
-       test_cmp expect actual
+       test_cmp expect actual &&
+       run_with_limited_stack git tag --no-contains HEAD >actual &&
+       test_line_count ">" 10 actual
 '
 
 test_expect_success '--format should list tags as per format given' '
@@ -1728,8 +1906,17 @@ test_expect_success 'setup --merged test tags' '
        git tag mergetest-3 HEAD
 '
 
-test_expect_success '--merged cannot be used in non-list mode' '
-       test_must_fail git tag --merged=mergetest-2 foo
+test_expect_success '--merged can be used in non-list mode' '
+       cat >expect <<-\EOF &&
+       mergetest-1
+       mergetest-2
+       EOF
+       git tag --merged=mergetest-2 "mergetest*" >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--merged is incompatible with --no-merged' '
+       test_must_fail git tag --merged HEAD --no-merged HEAD
 '
 
 test_expect_success '--merged shows merged tags' '
@@ -1749,6 +1936,11 @@ test_expect_success '--no-merged show unmerged tags' '
        test_cmp expect actual
 '
 
+test_expect_success '--no-merged can be used in non-list mode' '
+       git tag --no-merged=mergetest-2 mergetest-* >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'ambiguous branch/tags not marked' '
        git tag ambiguous &&
        git branch ambiguous &&
@@ -1757,4 +1949,47 @@ test_expect_success 'ambiguous branch/tags not marked' '
        test_cmp expect actual
 '
 
+test_expect_success '--contains combined with --no-contains' '
+       (
+               git init no-contains &&
+               cd no-contains &&
+               test_commit v0.1 &&
+               test_commit v0.2 &&
+               test_commit v0.3 &&
+               test_commit v0.4 &&
+               test_commit v0.5 &&
+               cat >expected <<-\EOF &&
+               v0.2
+               v0.3
+               v0.4
+               EOF
+               git tag --contains v0.2 --no-contains v0.5 >actual &&
+               test_cmp expected actual
+       )
+'
+
+# As the docs say, list tags which contain a specified *commit*. We
+# don't recurse down to tags for trees or blobs pointed to by *those*
+# commits.
+test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
+       cd no-contains &&
+       blob=$(git rev-parse v0.3:v0.3.t) &&
+       tree=$(git rev-parse v0.3^{tree}) &&
+       git tag tag-blob $blob &&
+       git tag tag-tree $tree &&
+       git tag --contains v0.3 >actual &&
+       cat >expected <<-\EOF &&
+       v0.3
+       v0.4
+       v0.5
+       EOF
+       test_cmp expected actual &&
+       git tag --no-contains v0.3 >actual &&
+       cat >expected <<-\EOF &&
+       v0.1
+       v0.2
+       EOF
+       test_cmp expected actual
+'
+
 test_done