#!/bin/sh # # Copyright (c) 2007 Nguyễn Thái Ngọc Duy # global test_description := ''Test repository version check'' source ./test-lib.sh test_expect_success 'setup' ' cat >test.patch <<-\EOF && diff --git a/test.txt b/test.txt new file mode 100644 --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +123 EOF test_create_repo "test" && test_create_repo "test2" && git config --file=test2/.git/config core.repositoryformatversion 99 ' test_expect_success 'gitdir selection on normal repos' ' echo 0 >expect && git config core.repositoryformatversion >actual && git -C test config core.repositoryformatversion >actual2 && test_cmp expect actual && test_cmp expect actual2 ' test_expect_success 'gitdir selection on unsupported repo' ' # Make sure it would stop at test2, not trash test_expect_code 1 git -C test2 config core.repositoryformatversion >actual ' test_expect_success 'gitdir not required mode' ' git apply --stat test.patch && git -C test apply --stat ../test.patch && git -C test2 apply --stat ../test.patch ' test_expect_success 'gitdir required mode' ' git apply --check --index test.patch && git -C test apply --check --index ../test.patch && test_must_fail git -C test2 apply --check --index ../test.patch ' proc check_allow { git rev-parse --git-dir >actual && echo .git >expect && test_cmp expect actual } proc check_abort { test_must_fail git rev-parse --git-dir } # avoid git-config, since it cannot be trusted to run # in a repository with a broken version proc mkconfig { echo '[core]' && echo "repositoryformatversion = $1" && shift && if test $Argc -gt 0 { echo '[extensions]' && for i in [@Argv] { echo $i } } } while read outcome version extensions { test_expect_success "$outcome version=$version $extensions" " mkconfig $version $extensions >.git/config && check_$(outcome) " } <<\EOF test_expect_success 'precious-objects allowed' ' mkconfig 1 preciousObjects >.git/config && check_allow ' test_expect_success 'precious-objects blocks destructive repack' ' test_must_fail git repack -ad ' test_expect_success 'other repacks are OK' ' test_commit foo && git repack ' test_expect_success 'precious-objects blocks prune' ' test_must_fail git prune ' test_expect_success 'gc runs without complaint' ' git gc ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"Test repository version check">)} spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tcat >test.patch <<-\\EOF &&\n"> <"\tdiff --git a/test.txt b/test.txt\n"> <"\tnew file mode 100644\n"> <"\t--- /dev/null\n"> <"\t+++ b/test.txt\n"> <"\t@@ -0,0 +1 @@\n"> <"\t+123\n"> <"\tEOF\n"> <"\n"> <"\ttest_create_repo \"test\" &&\n"> <"\ttest_create_repo \"test2\" &&\n"> <"\tgit config --file=test2/.git/config core.repositoryformatversion 99\n"> ) } ) (C {(test_expect_success)} {(SQ <"gitdir selection on normal repos">)} { (SQ <"\n"> <"\techo 0 >expect &&\n"> <"\tgit config core.repositoryformatversion >actual &&\n"> <"\tgit -C test config core.repositoryformatversion >actual2 &&\n"> <"\ttest_cmp expect actual &&\n"> <"\ttest_cmp expect actual2\n"> ) } ) (C {(test_expect_success)} {(SQ <"gitdir selection on unsupported repo">)} { (SQ <"\n"> <"\t# Make sure it would stop at test2, not trash\n"> <"\ttest_expect_code 1 git -C test2 config core.repositoryformatversion >actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"gitdir not required mode">)} { (SQ <"\n"> <"\tgit apply --stat test.patch &&\n"> <"\tgit -C test apply --stat ../test.patch &&\n"> <"\tgit -C test2 apply --stat ../test.patch\n"> ) } ) (C {(test_expect_success)} {(SQ <"gitdir required mode">)} { (SQ <"\n"> <"\tgit apply --check --index test.patch &&\n"> <"\tgit -C test apply --check --index ../test.patch &&\n"> <"\ttest_must_fail git -C test2 apply --check --index ../test.patch\n"> ) } ) (FuncDef name: check_allow body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [{(git)} {(rev-parse)} {(--git-dir)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(actual)} spids:[118])] ) (AndOr children: [ (SimpleCommand words: [{(echo)} {(.git)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(expect)} spids:[128])] ) (C {(test_cmp)} {(expect)} {(actual)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [109] ) spids: [104 108] ) (FuncDef name: check_abort body: (BraceGroup children: [(C {(test_must_fail)} {(git)} {(rev-parse)} {(--git-dir)})] spids: [148] ) spids: [143 147] ) (FuncDef name: mkconfig body: (BraceGroup children: [ (AndOr children: [ (C {(echo)} {(SQ <"[core]">)}) (AndOr children: [ (C {(echo)} {(DQ ("repositoryformatversion = ") ($ VSub_Number "$1"))}) (AndOr children: [ (C {(shift)}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(test)} {($ VSub_Pound "$#")} {(-gt)} {(0)}) terminator: ) ] action: [ (AndOr children: [ (C {(echo)} {(SQ <"[extensions]">)}) (ForEach iter_name: i iter_words: [{(DQ ($ VSub_At "$@"))}] do_arg_iter: False body: (DoGroup children: [(C {(echo)} {(DQ ($ VSub_Name "$i"))})] spids: [235 245] ) spids: [229 233] ) ] op_id: Op_DAmp ) ] spids: [-1 212] ) ] spids: [-1 248] ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [173] ) spids: [168 172] ) (While cond: [ (Sentence child: (C {(read)} {(outcome)} {(version)} {(extensions)}) terminator: ) ] body: (DoGroup children: [ (C {(test_expect_success)} { (DQ ($ VSub_Name "$outcome") (" version=") ($ VSub_Name "$version") (" ") ($ VSub_Name "$extensions") ) } { (DQ ("\n") ("\t\tmkconfig ") ($ VSub_Name "$version") (" ") ($ VSub_Name "$extensions") (" >.git/config &&\n") ("\t\tcheck_") (${ VSub_Name outcome) ("\n") ("\t") ) } ) ] spids: [264 292] ) redirects: [ (HereDoc op_id: Redir_DLess fd: -1 body: {("allow 0\n") ("allow 1\n") ("allow 1 noop\n") ("abort 1 no-such-extension\n") ("allow 0 no-such-extension\n") } do_expansion: False here_end: EOF was_filled: True spids: [294] ) ] ) (C {(test_expect_success)} {(SQ <"precious-objects allowed">)} {(SQ <"\n"> <"\tmkconfig 1 preciousObjects >.git/config &&\n"> <"\tcheck_allow\n">)} ) (C {(test_expect_success)} {(SQ <"precious-objects blocks destructive repack">)} {(SQ <"\n"> <"\ttest_must_fail git repack -ad\n">)} ) (C {(test_expect_success)} {(SQ <"other repacks are OK">)} {(SQ <"\n"> <"\ttest_commit foo &&\n"> <"\tgit repack\n">)} ) (C {(test_expect_success)} {(SQ <"precious-objects blocks prune">)} {(SQ <"\n"> <"\ttest_must_fail git prune\n">)} ) (C {(test_expect_success)} {(SQ <"gc runs without complaint">)} {(SQ <"\n"> <"\tgit gc\n">)}) (C {(test_done)}) ] )