#!/bin/sh global test_description := ''Test git update-ref error handling'' source ./test-lib.sh # Create some references, perhaps run pack-refs --all, then try to # create some more references. Ensure that the second creation fails # with the correct error message. # Usage: test_update_rejected # is a ws-separated list of refs to create before the test # (true or false) tells whether to pack the refs before the test # is a list of variables to attempt creating # is a string to look for in the stderr of update-ref. # All references are created in the namespace specified by the current # value of $prefix. proc test_update_rejected { global before := $1 && global pack := $2 && global create := $3 && global error := $4 && printf "create $prefix/%s $C\n" $before | git update-ref --stdin && git for-each-ref $prefix >unchanged && if $pack { git pack-refs --all } && printf "create $prefix/%s $C\n" $create >input && test_must_fail git update-ref --stdin output.err && grep -F $error output.err && git for-each-ref $prefix >actual && test_cmp unchanged actual } global Q := '"''" test_expect_success 'setup' ' git commit --allow-empty -m Initial && C=$(git rev-parse HEAD) && git commit --allow-empty -m Second && D=$(git rev-parse HEAD) && git commit --allow-empty -m Third && E=$(git rev-parse HEAD) ' test_expect_success 'existing loose ref is a simple prefix of new' ' prefix=refs/1l && test_update_rejected "a c e" false "b c/x d" \ "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q" ' test_expect_success 'existing packed ref is a simple prefix of new' ' prefix=refs/1p && test_update_rejected "a c e" true "b c/x d" \ "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q" ' test_expect_success 'existing loose ref is a deeper prefix of new' ' prefix=refs/2l && test_update_rejected "a c e" false "b c/x/y d" \ "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q" ' test_expect_success 'existing packed ref is a deeper prefix of new' ' prefix=refs/2p && test_update_rejected "a c e" true "b c/x/y d" \ "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q" ' test_expect_success 'new ref is a simple prefix of existing loose' ' prefix=refs/3l && test_update_rejected "a c/x e" false "b c d" \ "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q" ' test_expect_success 'new ref is a simple prefix of existing packed' ' prefix=refs/3p && test_update_rejected "a c/x e" true "b c d" \ "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q" ' test_expect_success 'new ref is a deeper prefix of existing loose' ' prefix=refs/4l && test_update_rejected "a c/x/y e" false "b c d" \ "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q" ' test_expect_success 'new ref is a deeper prefix of existing packed' ' prefix=refs/4p && test_update_rejected "a c/x/y e" true "b c d" \ "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q" ' test_expect_success 'one new ref is a simple prefix of another' ' prefix=refs/5 && test_update_rejected "a e" false "b c c/x d" \ "cannot process $Q$prefix/c$Q and $Q$prefix/c/x$Q at the same time" ' test_expect_success 'empty directory should not fool rev-parse' ' prefix=refs/e-rev-parse && git update-ref $prefix/foo $C && git pack-refs --all && mkdir -p .git/$prefix/foo/bar/baz && echo "$C" >expected && git rev-parse $prefix/foo >actual && test_cmp expected actual ' test_expect_success 'empty directory should not fool for-each-ref' ' prefix=refs/e-for-each-ref && git update-ref $prefix/foo $C && git for-each-ref $prefix >expected && git pack-refs --all && mkdir -p .git/$prefix/foo/bar/baz && git for-each-ref $prefix >actual && test_cmp expected actual ' test_expect_success 'empty directory should not fool create' ' prefix=refs/e-create && mkdir -p .git/$prefix/foo/bar/baz && printf "create %s $C\n" $prefix/foo | git update-ref --stdin ' test_expect_success 'empty directory should not fool verify' ' prefix=refs/e-verify && git update-ref $prefix/foo $C && git pack-refs --all && mkdir -p .git/$prefix/foo/bar/baz && printf "verify %s $C\n" $prefix/foo | git update-ref --stdin ' test_expect_success 'empty directory should not fool 1-arg update' ' prefix=refs/e-update-1 && git update-ref $prefix/foo $C && git pack-refs --all && mkdir -p .git/$prefix/foo/bar/baz && printf "update %s $D\n" $prefix/foo | git update-ref --stdin ' test_expect_success 'empty directory should not fool 2-arg update' ' prefix=refs/e-update-2 && git update-ref $prefix/foo $C && git pack-refs --all && mkdir -p .git/$prefix/foo/bar/baz && printf "update %s $D $C\n" $prefix/foo | git update-ref --stdin ' test_expect_success 'empty directory should not fool 0-arg delete' ' prefix=refs/e-delete-0 && git update-ref $prefix/foo $C && git pack-refs --all && mkdir -p .git/$prefix/foo/bar/baz && printf "delete %s\n" $prefix/foo | git update-ref --stdin ' test_expect_success 'empty directory should not fool 1-arg delete' ' prefix=refs/e-delete-1 && git update-ref $prefix/foo $C && git pack-refs --all && mkdir -p .git/$prefix/foo/bar/baz && printf "delete %s $C\n" $prefix/foo | git update-ref --stdin ' # Test various errors when reading the old values of references... test_expect_success 'missing old value blocks update' ' prefix=refs/missing-update && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/foo$Q: unable to resolve reference $Q$prefix/foo$Q EOF printf "%s\n" "update $prefix/foo $E $D" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'incorrect old value blocks update' ' prefix=refs/incorrect-update && git update-ref $prefix/foo $C && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/foo$Q: is at $C but expected $D EOF printf "%s\n" "update $prefix/foo $E $D" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'existing old value blocks create' ' prefix=refs/existing-create && git update-ref $prefix/foo $C && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/foo$Q: reference already exists EOF printf "%s\n" "create $prefix/foo $E" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'incorrect old value blocks delete' ' prefix=refs/incorrect-delete && git update-ref $prefix/foo $C && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/foo$Q: is at $C but expected $D EOF printf "%s\n" "delete $prefix/foo $D" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'missing old value blocks indirect update' ' prefix=refs/missing-indirect-update && git symbolic-ref $prefix/symref $prefix/foo && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: unable to resolve reference $Q$prefix/foo$Q EOF printf "%s\n" "update $prefix/symref $E $D" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'incorrect old value blocks indirect update' ' prefix=refs/incorrect-indirect-update && git symbolic-ref $prefix/symref $prefix/foo && git update-ref $prefix/foo $C && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: is at $C but expected $D EOF printf "%s\n" "update $prefix/symref $E $D" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'existing old value blocks indirect create' ' prefix=refs/existing-indirect-create && git symbolic-ref $prefix/symref $prefix/foo && git update-ref $prefix/foo $C && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: reference already exists EOF printf "%s\n" "create $prefix/symref $E" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'incorrect old value blocks indirect delete' ' prefix=refs/incorrect-indirect-delete && git symbolic-ref $prefix/symref $prefix/foo && git update-ref $prefix/foo $C && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: is at $C but expected $D EOF printf "%s\n" "delete $prefix/symref $D" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'missing old value blocks indirect no-deref update' ' prefix=refs/missing-noderef-update && git symbolic-ref $prefix/symref $prefix/foo && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: reference is missing but expected $D EOF printf "%s\n" "option no-deref" "update $prefix/symref $E $D" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'incorrect old value blocks indirect no-deref update' ' prefix=refs/incorrect-noderef-update && git symbolic-ref $prefix/symref $prefix/foo && git update-ref $prefix/foo $C && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: is at $C but expected $D EOF printf "%s\n" "option no-deref" "update $prefix/symref $E $D" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'existing old value blocks indirect no-deref create' ' prefix=refs/existing-noderef-create && git symbolic-ref $prefix/symref $prefix/foo && git update-ref $prefix/foo $C && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: reference already exists EOF printf "%s\n" "option no-deref" "create $prefix/symref $E" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'incorrect old value blocks indirect no-deref delete' ' prefix=refs/incorrect-noderef-delete && git symbolic-ref $prefix/symref $prefix/foo && git update-ref $prefix/foo $C && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: is at $C but expected $D EOF printf "%s\n" "option no-deref" "delete $prefix/symref $D" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'non-empty directory blocks create' ' prefix=refs/ne-create && mkdir -p .git/$prefix/foo/bar && : >.git/$prefix/foo/bar/baz.lock && test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/foo$Q: there is a non-empty directory $Q.git/$prefix/foo$Q blocking reference $Q$prefix/foo$Q EOF printf "%s\n" "update $prefix/foo $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/foo$Q: unable to resolve reference $Q$prefix/foo$Q EOF printf "%s\n" "update $prefix/foo $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'broken reference blocks create' ' prefix=refs/broken-create && mkdir -p .git/$prefix && echo "gobbledigook" >.git/$prefix/foo && test_when_finished "rm -f .git/$prefix/foo" && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/foo$Q: unable to resolve reference $Q$prefix/foo$Q: reference broken EOF printf "%s\n" "update $prefix/foo $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/foo$Q: unable to resolve reference $Q$prefix/foo$Q: reference broken EOF printf "%s\n" "update $prefix/foo $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'non-empty directory blocks indirect create' ' prefix=refs/ne-indirect-create && git symbolic-ref $prefix/symref $prefix/foo && mkdir -p .git/$prefix/foo/bar && : >.git/$prefix/foo/bar/baz.lock && test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: there is a non-empty directory $Q.git/$prefix/foo$Q blocking reference $Q$prefix/foo$Q EOF printf "%s\n" "update $prefix/symref $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: unable to resolve reference $Q$prefix/foo$Q EOF printf "%s\n" "update $prefix/symref $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_expect_success 'broken reference blocks indirect create' ' prefix=refs/broken-indirect-create && git symbolic-ref $prefix/symref $prefix/foo && echo "gobbledigook" >.git/$prefix/foo && test_when_finished "rm -f .git/$prefix/foo" && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: unable to resolve reference $Q$prefix/foo$Q: reference broken EOF printf "%s\n" "update $prefix/symref $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && fatal: cannot lock ref $Q$prefix/symref$Q: unable to resolve reference $Q$prefix/foo$Q: reference broken EOF printf "%s\n" "update $prefix/symref $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"Test git update-ref error handling">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: test_update_rejected body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:before) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [52] ) ] spids: [52] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:pack) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [60] ) ] spids: [60] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:create) op: Equal rhs: {(DQ ($ VSub_Number "$3"))} spids: [68] ) ] spids: [68] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:error) op: Equal rhs: {(DQ ($ VSub_Number "$4"))} spids: [76] ) ] spids: [76] ) (AndOr children: [ (Pipeline children: [ (C {(printf)} { (DQ ("create ") ($ VSub_Name "$prefix") ("/%s ") ($ VSub_Name "$C") (EscapedLiteralPart token:) ) } {($ VSub_Name "$before")} ) (C {(git)} {(update-ref)} {(--stdin)}) ] negated: False ) (AndOr children: [ (SimpleCommand words: [{(git)} {(for-each-ref)} {($ VSub_Name "$prefix")}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(unchanged)} spids: [114] ) ] ) (AndOr children: [ (If arms: [ (if_arm cond: [(C {($ VSub_Name "$pack")})] action: [(C {(git)} {(pack-refs)} {(--all)})] spids: [-1 125] ) ] spids: [-1 135] ) (AndOr children: [ (SimpleCommand words: [ {(printf)} { (DQ ("create ") ($ VSub_Name "$prefix") ("/%s ") ($ VSub_Name "$C") (EscapedLiteralPart token:) ) } {($ VSub_Name "$create")} ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(input)} spids: [152] ) ] ) (AndOr children: [ (SimpleCommand words: [ {(test_must_fail)} {(git)} {(update-ref)} {(--stdin)} ] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(input)} spids: [166] ) (Redir op_id: Redir_Great fd: 2 arg_word: {(output.err)} spids: [169] ) ] ) (AndOr children: [ (C {(grep)} {(-F)} {(DQ ($ VSub_Name "$error"))} {(output.err)} ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(for-each-ref)} {($ VSub_Name "$prefix")} ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(actual)} spids: [194] ) ] ) (C {(test_cmp)} {(unchanged)} {(actual)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [49] ) spids: [44 48] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:Q) op:Equal rhs:{(DQ ("'"))} spids:[209])] spids: [209] ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\n"> <"\tgit commit --allow-empty -m Initial &&\n"> <"\tC=$(git rev-parse HEAD) &&\n"> <"\tgit commit --allow-empty -m Second &&\n"> <"\tD=$(git rev-parse HEAD) &&\n"> <"\tgit commit --allow-empty -m Third &&\n"> <"\tE=$(git rev-parse HEAD)\n"> ) } ) (C {(test_expect_success)} {(SQ <"existing loose ref is a simple prefix of new">)} { (SQ <"\n"> <"\n"> <"\tprefix=refs/1l &&\n"> <"\ttest_update_rejected \"a c e\" false \"b c/x d\" \\\n"> <"\t\t\"$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"existing packed ref is a simple prefix of new">)} { (SQ <"\n"> <"\n"> <"\tprefix=refs/1p &&\n"> <"\ttest_update_rejected \"a c e\" true \"b c/x d\" \\\n"> <"\t\t\"$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"existing loose ref is a deeper prefix of new">)} { (SQ <"\n"> <"\n"> <"\tprefix=refs/2l &&\n"> <"\ttest_update_rejected \"a c e\" false \"b c/x/y d\" \\\n"> <"\t\t\"$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"existing packed ref is a deeper prefix of new">)} { (SQ <"\n"> <"\n"> <"\tprefix=refs/2p &&\n"> <"\ttest_update_rejected \"a c e\" true \"b c/x/y d\" \\\n"> <"\t\t\"$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"new ref is a simple prefix of existing loose">)} { (SQ <"\n"> <"\n"> <"\tprefix=refs/3l &&\n"> <"\ttest_update_rejected \"a c/x e\" false \"b c d\" \\\n"> <"\t\t\"$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"new ref is a simple prefix of existing packed">)} { (SQ <"\n"> <"\n"> <"\tprefix=refs/3p &&\n"> <"\ttest_update_rejected \"a c/x e\" true \"b c d\" \\\n"> <"\t\t\"$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"new ref is a deeper prefix of existing loose">)} { (SQ <"\n"> <"\n"> <"\tprefix=refs/4l &&\n"> <"\ttest_update_rejected \"a c/x/y e\" false \"b c d\" \\\n"> <"\t\t\"$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"new ref is a deeper prefix of existing packed">)} { (SQ <"\n"> <"\n"> <"\tprefix=refs/4p &&\n"> <"\ttest_update_rejected \"a c/x/y e\" true \"b c d\" \\\n"> <"\t\t\"$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"one new ref is a simple prefix of another">)} { (SQ <"\n"> <"\n"> <"\tprefix=refs/5 &&\n"> <"\ttest_update_rejected \"a e\" false \"b c c/x d\" \\\n"> <"\t\t\"cannot process $Q$prefix/c$Q and $Q$prefix/c/x$Q at the same time\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"empty directory should not fool rev-parse">)} { (SQ <"\n"> <"\tprefix=refs/e-rev-parse &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tgit pack-refs --all &&\n"> <"\tmkdir -p .git/$prefix/foo/bar/baz &&\n"> <"\techo \"$C\" >expected &&\n"> <"\tgit rev-parse $prefix/foo >actual &&\n"> <"\ttest_cmp expected actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"empty directory should not fool for-each-ref">)} { (SQ <"\n"> <"\tprefix=refs/e-for-each-ref &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tgit for-each-ref $prefix >expected &&\n"> <"\tgit pack-refs --all &&\n"> <"\tmkdir -p .git/$prefix/foo/bar/baz &&\n"> <"\tgit for-each-ref $prefix >actual &&\n"> <"\ttest_cmp expected actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"empty directory should not fool create">)} { (SQ <"\n"> <"\tprefix=refs/e-create &&\n"> <"\tmkdir -p .git/$prefix/foo/bar/baz &&\n"> <"\tprintf \"create %s $C\\n\" $prefix/foo |\n"> <"\tgit update-ref --stdin\n"> ) } ) (C {(test_expect_success)} {(SQ <"empty directory should not fool verify">)} { (SQ <"\n"> <"\tprefix=refs/e-verify &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tgit pack-refs --all &&\n"> <"\tmkdir -p .git/$prefix/foo/bar/baz &&\n"> <"\tprintf \"verify %s $C\\n\" $prefix/foo |\n"> <"\tgit update-ref --stdin\n"> ) } ) (C {(test_expect_success)} {(SQ <"empty directory should not fool 1-arg update">)} { (SQ <"\n"> <"\tprefix=refs/e-update-1 &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tgit pack-refs --all &&\n"> <"\tmkdir -p .git/$prefix/foo/bar/baz &&\n"> <"\tprintf \"update %s $D\\n\" $prefix/foo |\n"> <"\tgit update-ref --stdin\n"> ) } ) (C {(test_expect_success)} {(SQ <"empty directory should not fool 2-arg update">)} { (SQ <"\n"> <"\tprefix=refs/e-update-2 &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tgit pack-refs --all &&\n"> <"\tmkdir -p .git/$prefix/foo/bar/baz &&\n"> <"\tprintf \"update %s $D $C\\n\" $prefix/foo |\n"> <"\tgit update-ref --stdin\n"> ) } ) (C {(test_expect_success)} {(SQ <"empty directory should not fool 0-arg delete">)} { (SQ <"\n"> <"\tprefix=refs/e-delete-0 &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tgit pack-refs --all &&\n"> <"\tmkdir -p .git/$prefix/foo/bar/baz &&\n"> <"\tprintf \"delete %s\\n\" $prefix/foo |\n"> <"\tgit update-ref --stdin\n"> ) } ) (C {(test_expect_success)} {(SQ <"empty directory should not fool 1-arg delete">)} { (SQ <"\n"> <"\tprefix=refs/e-delete-1 &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tgit pack-refs --all &&\n"> <"\tmkdir -p .git/$prefix/foo/bar/baz &&\n"> <"\tprintf \"delete %s $C\\n\" $prefix/foo |\n"> <"\tgit update-ref --stdin\n"> ) } ) (C {(test_expect_success)} {(SQ <"missing old value blocks update">)} { (SQ <"\n"> <"\tprefix=refs/missing-update &&\n"> <"\tcat >expected <<-EOF &&\n"> < "\tfatal: cannot lock ref $Q$prefix/foo$Q: unable to resolve reference $Q$prefix/foo$Q\n" > <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/foo $E $D\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"incorrect old value blocks update">)} { (SQ <"\n"> <"\tprefix=refs/incorrect-update &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tcat >expected <<-EOF &&\n"> <"\tfatal: cannot lock ref $Q$prefix/foo$Q: is at $C but expected $D\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/foo $E $D\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"existing old value blocks create">)} { (SQ <"\n"> <"\tprefix=refs/existing-create &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tcat >expected <<-EOF &&\n"> <"\tfatal: cannot lock ref $Q$prefix/foo$Q: reference already exists\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" \"create $prefix/foo $E\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"incorrect old value blocks delete">)} { (SQ <"\n"> <"\tprefix=refs/incorrect-delete &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tcat >expected <<-EOF &&\n"> <"\tfatal: cannot lock ref $Q$prefix/foo$Q: is at $C but expected $D\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" \"delete $prefix/foo $D\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"missing old value blocks indirect update">)} { (SQ <"\n"> <"\tprefix=refs/missing-indirect-update &&\n"> <"\tgit symbolic-ref $prefix/symref $prefix/foo &&\n"> <"\tcat >expected <<-EOF &&\n"> < "\tfatal: cannot lock ref $Q$prefix/symref$Q: unable to resolve reference $Q$prefix/foo$Q\n" > <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/symref $E $D\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"incorrect old value blocks indirect update">)} { (SQ <"\n"> <"\tprefix=refs/incorrect-indirect-update &&\n"> <"\tgit symbolic-ref $prefix/symref $prefix/foo &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tcat >expected <<-EOF &&\n"> <"\tfatal: cannot lock ref $Q$prefix/symref$Q: is at $C but expected $D\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/symref $E $D\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"existing old value blocks indirect create">)} { (SQ <"\n"> <"\tprefix=refs/existing-indirect-create &&\n"> <"\tgit symbolic-ref $prefix/symref $prefix/foo &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tcat >expected <<-EOF &&\n"> <"\tfatal: cannot lock ref $Q$prefix/symref$Q: reference already exists\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" \"create $prefix/symref $E\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"incorrect old value blocks indirect delete">)} { (SQ <"\n"> <"\tprefix=refs/incorrect-indirect-delete &&\n"> <"\tgit symbolic-ref $prefix/symref $prefix/foo &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tcat >expected <<-EOF &&\n"> <"\tfatal: cannot lock ref $Q$prefix/symref$Q: is at $C but expected $D\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" \"delete $prefix/symref $D\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"missing old value blocks indirect no-deref update">)} { (SQ <"\n"> <"\tprefix=refs/missing-noderef-update &&\n"> <"\tgit symbolic-ref $prefix/symref $prefix/foo &&\n"> <"\tcat >expected <<-EOF &&\n"> <"\tfatal: cannot lock ref $Q$prefix/symref$Q: reference is missing but expected $D\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" \"option no-deref\" \"update $prefix/symref $E $D\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"incorrect old value blocks indirect no-deref update">)} { (SQ <"\n"> <"\tprefix=refs/incorrect-noderef-update &&\n"> <"\tgit symbolic-ref $prefix/symref $prefix/foo &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tcat >expected <<-EOF &&\n"> <"\tfatal: cannot lock ref $Q$prefix/symref$Q: is at $C but expected $D\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" \"option no-deref\" \"update $prefix/symref $E $D\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"existing old value blocks indirect no-deref create">)} { (SQ <"\n"> <"\tprefix=refs/existing-noderef-create &&\n"> <"\tgit symbolic-ref $prefix/symref $prefix/foo &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tcat >expected <<-EOF &&\n"> <"\tfatal: cannot lock ref $Q$prefix/symref$Q: reference already exists\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" \"option no-deref\" \"create $prefix/symref $E\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"incorrect old value blocks indirect no-deref delete">)} { (SQ <"\n"> <"\tprefix=refs/incorrect-noderef-delete &&\n"> <"\tgit symbolic-ref $prefix/symref $prefix/foo &&\n"> <"\tgit update-ref $prefix/foo $C &&\n"> <"\tcat >expected <<-EOF &&\n"> <"\tfatal: cannot lock ref $Q$prefix/symref$Q: is at $C but expected $D\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" \"option no-deref\" \"delete $prefix/symref $D\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"non-empty directory blocks create">)} { (SQ <"\n"> <"\tprefix=refs/ne-create &&\n"> <"\tmkdir -p .git/$prefix/foo/bar &&\n"> <"\t: >.git/$prefix/foo/bar/baz.lock &&\n"> <"\ttest_when_finished \"rm -f .git/$prefix/foo/bar/baz.lock\" &&\n"> <"\tcat >expected <<-EOF &&\n"> < "\tfatal: cannot lock ref $Q$prefix/foo$Q: there is a non-empty directory $Q.git/$prefix/foo$Q blocking reference $Q$prefix/foo$Q\n" > <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/foo $C\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err &&\n"> <"\tcat >expected <<-EOF &&\n"> < "\tfatal: cannot lock ref $Q$prefix/foo$Q: unable to resolve reference $Q$prefix/foo$Q\n" > <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/foo $D $C\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"broken reference blocks create">)} { (SQ <"\n"> <"\tprefix=refs/broken-create &&\n"> <"\tmkdir -p .git/$prefix &&\n"> <"\techo \"gobbledigook\" >.git/$prefix/foo &&\n"> <"\ttest_when_finished \"rm -f .git/$prefix/foo\" &&\n"> <"\tcat >expected <<-EOF &&\n"> < "\tfatal: cannot lock ref $Q$prefix/foo$Q: unable to resolve reference $Q$prefix/foo$Q: reference broken\n" > <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/foo $C\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err &&\n"> <"\tcat >expected <<-EOF &&\n"> < "\tfatal: cannot lock ref $Q$prefix/foo$Q: unable to resolve reference $Q$prefix/foo$Q: reference broken\n" > <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/foo $D $C\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"non-empty directory blocks indirect create">)} { (SQ <"\n"> <"\tprefix=refs/ne-indirect-create &&\n"> <"\tgit symbolic-ref $prefix/symref $prefix/foo &&\n"> <"\tmkdir -p .git/$prefix/foo/bar &&\n"> <"\t: >.git/$prefix/foo/bar/baz.lock &&\n"> <"\ttest_when_finished \"rm -f .git/$prefix/foo/bar/baz.lock\" &&\n"> <"\tcat >expected <<-EOF &&\n"> < "\tfatal: cannot lock ref $Q$prefix/symref$Q: there is a non-empty directory $Q.git/$prefix/foo$Q blocking reference $Q$prefix/foo$Q\n" > <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/symref $C\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err &&\n"> <"\tcat >expected <<-EOF &&\n"> < "\tfatal: cannot lock ref $Q$prefix/symref$Q: unable to resolve reference $Q$prefix/foo$Q\n" > <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/symref $D $C\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"broken reference blocks indirect create">)} { (SQ <"\n"> <"\tprefix=refs/broken-indirect-create &&\n"> <"\tgit symbolic-ref $prefix/symref $prefix/foo &&\n"> <"\techo \"gobbledigook\" >.git/$prefix/foo &&\n"> <"\ttest_when_finished \"rm -f .git/$prefix/foo\" &&\n"> <"\tcat >expected <<-EOF &&\n"> < "\tfatal: cannot lock ref $Q$prefix/symref$Q: unable to resolve reference $Q$prefix/foo$Q: reference broken\n" > <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/symref $C\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err &&\n"> <"\tcat >expected <<-EOF &&\n"> < "\tfatal: cannot lock ref $Q$prefix/symref$Q: unable to resolve reference $Q$prefix/foo$Q: reference broken\n" > <"\tEOF\n"> <"\tprintf \"%s\\n\" \"update $prefix/symref $D $C\" |\n"> <"\ttest_must_fail git update-ref --stdin 2>output.err &&\n"> <"\ttest_cmp expected output.err\n"> ) } ) (C {(test_done)}) ] )