Git fork
at reftables-rust 122 lines 4.3 kB view raw
1#!/bin/sh 2 3test_description='tests for git clone --revision' 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 6 7. ./test-lib.sh 8 9test_expect_success 'setup' ' 10 test_commit --no-tag "initial commit" README "Hello" && 11 test_commit --annotate "second commit" README "Hello world" v1.0 && 12 test_commit --no-tag "third commit" README "Hello world!" && 13 git switch -c feature v1.0 && 14 test_commit --no-tag "feature commit" README "Hello world!" && 15 git switch main 16' 17 18test_expect_success 'clone with --revision being a branch' ' 19 test_when_finished "rm -rf dst" && 20 git clone --revision=refs/heads/feature . dst && 21 git rev-parse refs/heads/feature >expect && 22 git -C dst rev-parse HEAD >actual && 23 test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null && 24 test_cmp expect actual && 25 git -C dst for-each-ref refs >expect && 26 test_must_be_empty expect && 27 test_must_fail git -C dst config remote.origin.fetch 28' 29 30test_expect_success 'clone with --depth and --revision being a branch' ' 31 test_when_finished "rm -rf dst" && 32 git clone --no-local --depth=1 --revision=refs/heads/feature . dst && 33 git rev-parse refs/heads/feature >expect && 34 git -C dst rev-parse HEAD >actual && 35 test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null && 36 test_cmp expect actual && 37 git -C dst for-each-ref refs >expect && 38 test_must_be_empty expect && 39 test_must_fail git -C dst config remote.origin.fetch && 40 git -C dst rev-list HEAD >actual && 41 test_line_count = 1 actual 42' 43 44test_expect_success 'clone with --revision being a tag' ' 45 test_when_finished "rm -rf dst" && 46 git clone --revision=refs/tags/v1.0 . dst && 47 git rev-parse refs/tags/v1.0^{} >expect && 48 git -C dst rev-parse HEAD >actual && 49 test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null && 50 test_cmp expect actual && 51 git -C dst for-each-ref refs >expect && 52 test_must_be_empty expect && 53 test_must_fail git -C dst config remote.origin.fetch 54' 55 56test_expect_success 'clone with --revision being HEAD' ' 57 test_when_finished "rm -rf dst" && 58 git clone --revision=HEAD . dst && 59 git rev-parse HEAD >expect && 60 git -C dst rev-parse HEAD >actual && 61 test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null && 62 test_cmp expect actual && 63 git -C dst for-each-ref refs >expect && 64 test_must_be_empty expect && 65 test_must_fail git -C dst config remote.origin.fetch 66' 67 68test_expect_success 'clone with --revision being a raw commit hash' ' 69 test_when_finished "rm -rf dst" && 70 oid=$(git rev-parse refs/heads/feature) && 71 git clone --revision=$oid . dst && 72 echo $oid >expect && 73 git -C dst rev-parse HEAD >actual && 74 test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null && 75 test_cmp expect actual && 76 git -C dst for-each-ref refs >expect && 77 test_must_be_empty expect && 78 test_must_fail git -C dst config remote.origin.fetch 79' 80 81test_expect_success 'clone with --revision and --bare' ' 82 test_when_finished "rm -rf dst" && 83 git clone --revision=refs/heads/main --bare . dst && 84 oid=$(git rev-parse refs/heads/main) && 85 git -C dst cat-file -t $oid >actual && 86 echo "commit" >expect && 87 test_cmp expect actual && 88 git -C dst for-each-ref refs >expect && 89 test_must_be_empty expect && 90 test_must_fail git -C dst config remote.origin.fetch 91' 92 93test_expect_success 'clone with --revision being a short raw commit hash' ' 94 test_when_finished "rm -rf dst" && 95 oid=$(git rev-parse --short refs/heads/feature) && 96 test_must_fail git clone --revision=$oid . dst 2>err && 97 test_grep "fatal: Remote revision $oid not found in upstream origin" err 98' 99 100test_expect_success 'clone with --revision being a tree hash' ' 101 test_when_finished "rm -rf dst" && 102 oid=$(git rev-parse refs/heads/feature^{tree}) && 103 test_must_fail git clone --revision=$oid . dst 2>err && 104 test_grep "error: object $oid is a tree, not a commit" err 105' 106 107test_expect_success 'clone with --revision being the parent of a ref fails' ' 108 test_when_finished "rm -rf dst" && 109 test_must_fail git clone --revision=refs/heads/main^ . dst 110' 111 112test_expect_success 'clone with --revision and --branch fails' ' 113 test_when_finished "rm -rf dst" && 114 test_must_fail git clone --revision=refs/heads/main --branch=main . dst 115' 116 117test_expect_success 'clone with --revision and --mirror fails' ' 118 test_when_finished "rm -rf dst" && 119 test_must_fail git clone --revision=refs/heads/main --mirror . dst 120' 121 122test_done