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/t1467-refs-rename.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 / t1467-refs-rename.sh` 144 lines ยท 3832 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='git refs rename' 4 5 . ./test-lib.sh 6 7 setup_repo () { 8 git init "$1" && 9 test_commit -C "$1" A && 10 test_commit -C "$1" B 11 } 12 13 test_ref_matches () { 14 git rev-parse "$1" >expect && 15 echo "$2" >actual && 16 test_cmp expect actual 17 } 18 19 test_expect_success 'rename an existing reference' ' 20 test_when_finished "rm -rf repo" && 21 setup_repo repo && 22 ( 23 cd repo && 24 A=$(git rev-parse A) && 25 git refs update refs/heads/foo $A && 26 git refs rename refs/heads/foo refs/heads/bar && 27 test_must_fail git refs exists refs/heads/foo && 28 test_ref_matches refs/heads/bar $A 29 ) 30 ' 31 32 test_expect_success 'rename moves the reflog along with the reference' ' 33 test_when_finished "rm -rf repo" && 34 setup_repo repo && 35 ( 36 cd repo && 37 A=$(git rev-parse A) && 38 git refs update --message="rename me" refs/heads/foo $A && 39 git refs rename refs/heads/foo refs/heads/bar && 40 git reflog show refs/heads/bar >reflog && 41 test_grep "rename me" reflog && 42 test_must_fail git reflog exists refs/heads/foo 43 ) 44 ' 45 46 test_expect_success 'rename with message records reason in reflog' ' 47 test_when_finished "rm -rf repo" && 48 setup_repo repo && 49 ( 50 cd repo && 51 A=$(git rev-parse A) && 52 git refs update refs/heads/foo $A && 53 git refs rename --message="rename reason" refs/heads/foo refs/heads/bar && 54 git reflog show refs/heads/bar >actual && 55 test_grep "rename reason" actual 56 ) 57 ' 58 59 test_expect_success 'rename a nonexistent reference fails' ' 60 test_when_finished "rm -rf repo" && 61 setup_repo repo && 62 ( 63 cd repo && 64 test_must_fail git refs rename refs/heads/foo refs/heads/bar 2>err && 65 test_grep "reference does not exist" err 66 ) 67 ' 68 69 test_expect_success 'rename to an existing reference fails' ' 70 test_when_finished "rm -rf repo" && 71 setup_repo repo && 72 ( 73 cd repo && 74 A=$(git rev-parse A) && 75 B=$(git rev-parse B) && 76 git refs update refs/heads/foo $A && 77 git refs update refs/heads/bar $B && 78 test_must_fail git refs rename refs/heads/foo refs/heads/bar 2>err && 79 test_grep "reference already exists" err 80 ) 81 ' 82 83 test_expect_success 'rename with symbolic ref fails' ' 84 test_when_finished "rm -rf repo" && 85 setup_repo repo && 86 ( 87 cd repo && 88 A=$(git rev-parse A) && 89 git refs create refs/heads/target $A && 90 git symbolic-ref refs/heads/symref refs/heads/target && 91 test_must_fail git refs rename refs/heads/symref refs/heads/renamed 2>err && 92 test_grep "is a symbolic ref, .* not supported" err 93 ) 94 ' 95 96 test_expect_success 'rename with empty message fails' ' 97 test_when_finished "rm -rf repo" && 98 setup_repo repo && 99 ( 100 cd repo && 101 A=$(git rev-parse A) && 102 git refs update refs/heads/foo $A && 103 test_must_fail git refs rename --message= refs/heads/foo refs/heads/bar 2>err && 104 test_grep "empty message" err 105 ) 106 ' 107 108 test_expect_success 'rename with invalid old reference name fails' ' 109 test_when_finished "rm -rf repo" && 110 setup_repo repo && 111 ( 112 cd repo && 113 test_must_fail git refs rename "refs/heads/foo..bar" refs/heads/bar 2>err && 114 test_grep "invalid ref format" err 115 ) 116 ' 117 118 test_expect_success 'rename with invalid new reference name fails' ' 119 test_when_finished "rm -rf repo" && 120 setup_repo repo && 121 ( 122 cd repo && 123 A=$(git rev-parse A) && 124 git refs update refs/heads/foo $A && 125 test_must_fail git refs rename refs/heads/foo "refs/heads/bar..baz" 2>err && 126 test_grep "invalid ref format" err 127 ) 128 ' 129 130 test_expect_success 'rename with too few arguments fails' ' 131 test_when_finished "rm -rf repo" && 132 setup_repo repo && 133 test_must_fail git -C repo refs rename refs/heads/foo 2>err && 134 test_grep "requires old and new reference name" err 135 ' 136 137 test_expect_success 'rename with too many arguments fails' ' 138 test_when_finished "rm -rf repo" && 139 setup_repo repo && 140 test_must_fail git -C repo refs rename refs/heads/foo refs/heads/bar refs/heads/baz 2>err && 141 test_grep "requires old and new reference name" err 142 ' 143 144 test_done