#!/bin/sh global test_description := ''send-pack --stdin tests'' source ./test-lib.sh proc create_ref { global tree := $[git write-tree] && test_tick && global commit := $[echo $1 | git commit-tree $tree] && git update-ref $1 $commit } proc clear_remote { rm -rf remote.git && git init --bare remote.git } proc verify_push { git rev-parse $1 >expect && git --git-dir=remote.git rev-parse $(2:-$1) >actual && test_cmp expect actual } test_expect_success 'setup refs' ' cat >refs <<-\EOF && refs/heads/A refs/heads/C refs/tags/D refs/heads/B refs/tags/E EOF for i in $(cat refs); do create_ref $i || return 1 done ' # sanity check our setup test_expect_success 'refs on cmdline' ' clear_remote && git send-pack remote.git $(cat refs) && for i in $(cat refs); do verify_push $i || return 1 done ' test_expect_success 'refs over stdin' ' clear_remote && git send-pack remote.git --stdin input && git send-pack remote.git --stdin input && git send-pack remote.git --stdin B input && test_must_fail git send-pack remote.git --stdin B:foo )} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: create_ref body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:tree) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(git)} {(write-tree)})]) left_token: spids: [23 27] ) } spids: [22] ) ] spids: [22] ) (AndOr children: [ (C {(test_tick)}) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:commit) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Number "$1"))}) (C {(git)} {(commit-tree)} {($ VSub_Name "$tree")}) ] negated: False ) ] ) left_token: spids: [38 52] ) } spids: [37] ) ] spids: [37] ) (C {(git)} {(update-ref)} {(DQ ($ VSub_Number "$1"))} {($ VSub_Name "$commit")}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [19] ) spids: [14 18] ) (FuncDef name: clear_remote body: (BraceGroup children: [ (AndOr children: [ (C {(rm)} {(-rf)} {(remote.git)}) (C {(git)} {(init)} {(--bare)} {(remote.git)}) ] op_id: Op_DAmp ) ] spids: [75] ) spids: [70 74] ) (FuncDef name: verify_push body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [{(git)} {(rev-parse)} {(DQ ($ VSub_Number "$1"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(expect)} spids:[114])] ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(--git-dir) (Lit_Other "=") (remote.git)} {(rev-parse)} { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {($ VSub_Number "$1")} ) spids: [129 133] ) ) } ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(actual)} spids:[136])] ) (C {(test_cmp)} {(expect)} {(actual)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [103] ) spids: [98 102] ) (C {(test_expect_success)} {(SQ <"setup refs">)} { (SQ <"\n"> <"\tcat >refs <<-\\EOF &&\n"> <"\trefs/heads/A\n"> <"\trefs/heads/C\n"> <"\trefs/tags/D\n"> <"\trefs/heads/B\n"> <"\trefs/tags/E\n"> <"\tEOF\n"> <"\tfor i in $(cat refs); do\n"> <"\t\tcreate_ref $i || return 1\n"> <"\tdone\n"> ) } ) (C {(test_expect_success)} {(SQ <"refs on cmdline">)} { (SQ <"\n"> <"\tclear_remote &&\n"> <"\tgit send-pack remote.git $(cat refs) &&\n"> <"\tfor i in $(cat refs); do\n"> <"\t\tverify_push $i || return 1\n"> <"\tdone\n"> ) } ) (C {(test_expect_success)} {(SQ <"refs over stdin">)} { (SQ <"\n"> <"\tclear_remote &&\n"> <"\tgit send-pack remote.git --stdin <"\tfor i in $(cat refs); do\n"> <"\t\tverify_push $i || return 1\n"> <"\tdone\n"> ) } ) (C {(test_expect_success)} {(SQ <"stdin lines are full refspecs">)} { (SQ <"\n"> <"\tclear_remote &&\n"> <"\techo \"A:other\" >input &&\n"> <"\tgit send-pack remote.git --stdin <"\tverify_push refs/heads/A refs/heads/other\n"> ) } ) (C {(test_expect_success)} {(SQ <"stdin mixed with cmdline">)} { (SQ <"\n"> <"\tclear_remote &&\n"> <"\techo A >input &&\n"> <"\tgit send-pack remote.git --stdin B <"\tverify_push A &&\n"> <"\tverify_push B\n"> ) } ) (C {(test_expect_success)} {(SQ <"cmdline refs written in order">)} { (SQ <"\n"> <"\tclear_remote &&\n"> <"\ttest_must_fail git send-pack remote.git A:foo B:foo &&\n"> <"\tverify_push A foo\n"> ) } ) (C {(test_expect_success)} {(SQ <"--stdin refs come after cmdline">)} { (SQ <"\n"> <"\tclear_remote &&\n"> <"\techo A:foo >input &&\n"> <"\ttest_must_fail git send-pack remote.git --stdin B:foo <"\tverify_push B foo\n"> ) } ) (C {(test_expect_success)} {(SQ <"refspecs and --mirror do not mix (cmdline)">)} { (SQ <"\n"> <"\tclear_remote &&\n"> <"\ttest_must_fail git send-pack remote.git --mirror $(cat refs)\n"> ) } ) (C {(test_expect_success)} {(SQ <"refspecs and --mirror do not mix (stdin)">)} { (SQ <"\n"> <"\tclear_remote &&\n"> <"\ttest_must_fail git send-pack remote.git --mirror --stdin ) } ) (C {(test_done)}) ] )