Merge branch 'fc/fast-import-broken-marks-file'
[gitweb.git] / t / t1430-bad-ref-name.sh
index 005e2b1756d1f04bfc6fcb68d9b336d089cdbf92..25ddab4e984877cb9361919a893fce391d2f066a 100755 (executable)
@@ -147,22 +147,28 @@ test_expect_success 'rev-parse skips symref pointing to broken name' '
        test_when_finished "rm -f .git/refs/heads/broken...ref" &&
        git branch shadow one &&
        cp .git/refs/heads/master .git/refs/heads/broken...ref &&
-       git symbolic-ref refs/tags/shadow refs/heads/broken...ref &&
-
+       printf "ref: refs/heads/broken...ref\n" >.git/refs/tags/shadow &&
+       test_when_finished "rm -f .git/refs/tags/shadow" &&
        git rev-parse --verify one >expect &&
        git rev-parse --verify shadow >actual 2>err &&
        test_cmp expect actual &&
        test_i18ngrep "ignoring dangling symref refs/tags/shadow" err
 '
 
-test_expect_success 'update-ref --no-deref -d can delete reference to broken name' '
-       git symbolic-ref refs/heads/badname refs/heads/broken...ref &&
+test_expect_success 'for-each-ref emits warnings for broken names' '
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname &&
        test_when_finished "rm -f .git/refs/heads/badname" &&
-       test_path_is_file .git/refs/heads/badname &&
-       git update-ref --no-deref -d refs/heads/badname >output 2>error &&
-       test_path_is_missing .git/refs/heads/badname &&
-       test_must_be_empty output &&
-       test_must_be_empty error
+       printf "ref: refs/heads/master\n" >.git/refs/heads/broken...symref &&
+       test_when_finished "rm -f .git/refs/heads/broken...symref" &&
+       git for-each-ref >output 2>error &&
+       ! grep -e "broken\.\.\.ref" output &&
+       ! grep -e "badname" output &&
+       ! grep -e "broken\.\.\.symref" output &&
+       test_i18ngrep "ignoring ref with broken name refs/heads/broken\.\.\.ref" error &&
+       test_i18ngrep "ignoring broken ref refs/heads/badname" error &&
+       test_i18ngrep "ignoring ref with broken name refs/heads/broken\.\.\.symref" error
 '
 
 test_expect_success 'update-ref -d can delete broken name' '
@@ -176,6 +182,104 @@ test_expect_success 'update-ref -d can delete broken name' '
        ! grep -e "broken\.\.\.ref" output
 '
 
+test_expect_success 'branch -d can delete broken name' '
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       git branch -d broken...ref >output 2>error &&
+       test_i18ngrep "Deleted branch broken...ref (was broken)" output &&
+       test_must_be_empty error &&
+       git branch >output 2>error &&
+       ! grep -e "broken\.\.\.ref" error &&
+       ! grep -e "broken\.\.\.ref" output
+'
+
+test_expect_success 'update-ref --no-deref -d can delete symref to broken name' '
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname &&
+       test_when_finished "rm -f .git/refs/heads/badname" &&
+       git update-ref --no-deref -d refs/heads/badname >output 2>error &&
+       test_path_is_missing .git/refs/heads/badname &&
+       test_must_be_empty output &&
+       test_must_be_empty error
+'
+
+test_expect_success 'branch -d can delete symref to broken name' '
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname &&
+       test_when_finished "rm -f .git/refs/heads/badname" &&
+       git branch -d badname >output 2>error &&
+       test_path_is_missing .git/refs/heads/badname &&
+       test_i18ngrep "Deleted branch badname (was refs/heads/broken\.\.\.ref)" output &&
+       test_must_be_empty error
+'
+
+test_expect_success 'update-ref --no-deref -d can delete dangling symref to broken name' '
+       printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname &&
+       test_when_finished "rm -f .git/refs/heads/badname" &&
+       git update-ref --no-deref -d refs/heads/badname >output 2>error &&
+       test_path_is_missing .git/refs/heads/badname &&
+       test_must_be_empty output &&
+       test_must_be_empty error
+'
+
+test_expect_success 'branch -d can delete dangling symref to broken name' '
+       printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname &&
+       test_when_finished "rm -f .git/refs/heads/badname" &&
+       git branch -d badname >output 2>error &&
+       test_path_is_missing .git/refs/heads/badname &&
+       test_i18ngrep "Deleted branch badname (was refs/heads/broken\.\.\.ref)" output &&
+       test_must_be_empty error
+'
+
+test_expect_success 'update-ref -d can delete broken name through symref' '
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname &&
+       test_when_finished "rm -f .git/refs/heads/badname" &&
+       git update-ref -d refs/heads/badname >output 2>error &&
+       test_path_is_missing .git/refs/heads/broken...ref &&
+       test_must_be_empty output &&
+       test_must_be_empty error
+'
+
+test_expect_success 'update-ref --no-deref -d can delete symref with broken name' '
+       printf "ref: refs/heads/master\n" >.git/refs/heads/broken...symref &&
+       test_when_finished "rm -f .git/refs/heads/broken...symref" &&
+       git update-ref --no-deref -d refs/heads/broken...symref >output 2>error &&
+       test_path_is_missing .git/refs/heads/broken...symref &&
+       test_must_be_empty output &&
+       test_must_be_empty error
+'
+
+test_expect_success 'branch -d can delete symref with broken name' '
+       printf "ref: refs/heads/master\n" >.git/refs/heads/broken...symref &&
+       test_when_finished "rm -f .git/refs/heads/broken...symref" &&
+       git branch -d broken...symref >output 2>error &&
+       test_path_is_missing .git/refs/heads/broken...symref &&
+       test_i18ngrep "Deleted branch broken...symref (was refs/heads/master)" output &&
+       test_must_be_empty error
+'
+
+test_expect_success 'update-ref --no-deref -d can delete dangling symref with broken name' '
+       printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref &&
+       test_when_finished "rm -f .git/refs/heads/broken...symref" &&
+       git update-ref --no-deref -d refs/heads/broken...symref >output 2>error &&
+       test_path_is_missing .git/refs/heads/broken...symref &&
+       test_must_be_empty output &&
+       test_must_be_empty error
+'
+
+test_expect_success 'branch -d can delete dangling symref with broken name' '
+       printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref &&
+       test_when_finished "rm -f .git/refs/heads/broken...symref" &&
+       git branch -d broken...symref >output 2>error &&
+       test_path_is_missing .git/refs/heads/broken...symref &&
+       test_i18ngrep "Deleted branch broken...symref (was refs/heads/idonotexist)" output &&
+       test_must_be_empty error
+'
+
 test_expect_success 'update-ref -d cannot delete non-ref in .git dir' '
        echo precious >.git/my-private-file &&
        echo precious >expect &&