Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5621-clone-revision.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5621-clone-revision.sh` 130 lines ยท 4609 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='tests for git clone --revision' 4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 6 7 . ./test-lib.sh 8 9 test_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 18 test_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 30 test_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 44 test_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 56 test_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 68 test_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 81 test_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 93 test_expect_success 'clone with --revision and protocol v0' ' 94 test_when_finished "rm -rf dst" && 95 git -c protocol.version=0 clone --no-local --revision=refs/heads/main . dst && 96 git rev-parse refs/heads/main >expect && 97 git -C dst rev-parse HEAD >actual && 98 test_cmp expect actual 99 ' 100 101 test_expect_success 'clone with --revision being a short raw commit hash' ' 102 test_when_finished "rm -rf dst" && 103 oid=$(git rev-parse --short refs/heads/feature) && 104 test_must_fail git clone --revision=$oid . dst 2>err && 105 test_grep "fatal: Remote revision $oid not found in upstream origin" err 106 ' 107 108 test_expect_success 'clone with --revision being a tree hash' ' 109 test_when_finished "rm -rf dst" && 110 oid=$(git rev-parse refs/heads/feature^{tree}) && 111 test_must_fail git clone --revision=$oid . dst 2>err && 112 test_grep "error: object $oid is a tree, not a commit" err 113 ' 114 115 test_expect_success 'clone with --revision being the parent of a ref fails' ' 116 test_when_finished "rm -rf dst" && 117 test_must_fail git clone --revision=refs/heads/main^ . dst 118 ' 119 120 test_expect_success 'clone with --revision and --branch fails' ' 121 test_when_finished "rm -rf dst" && 122 test_must_fail git clone --revision=refs/heads/main --branch=main . dst 123 ' 124 125 test_expect_success 'clone with --revision and --mirror fails' ' 126 test_when_finished "rm -rf dst" && 127 test_must_fail git clone --revision=refs/heads/main --mirror . dst 128 ' 129 130 test_done