#!/bin/sh global test_description := ''fetch/push involving alternates'' source ./test-lib.sh proc count_objects { global loose := '0', inpack := '0' eval $[ git count-objects -v | sed -n -e 's/^count: \(.*\)/loose=\1/p' \ -e 's/^in-pack: \(.*\)/inpack=\1/p] && echo $( $loose + $inpack ) } test_expect_success setup ' ( git init original && cd original && i=0 && while test $i -le 100 do echo "$i" >count && git add count && git commit -m "$i" || exit i=$(($i + 1)) done ) && ( git clone --reference=original "file://$(pwd)/original" one && cd one && echo Z >count && git add count && git commit -m Z && count_objects >../one.count ) && A=$(pwd)/original/.git/objects && git init receiver && echo "$A" >receiver/.git/objects/info/alternates && git init fetcher && echo "$A" >fetcher/.git/objects/info/alternates ' test_expect_success 'pushing into a repository with the same alternate' ' ( cd one && git push ../receiver master:refs/heads/it ) && ( cd receiver && count_objects >../receiver.count ) && test_cmp one.count receiver.count ' test_expect_success 'fetching from a repository with the same alternate' ' ( cd fetcher && git fetch ../one master:refs/heads/it && count_objects >../fetcher.count ) && test_cmp one.count fetcher.count ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"fetch/push involving alternates">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: count_objects body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs:(LhsName name:loose) op:Equal rhs:{(0)} spids:[22]) (assign_pair lhs:(LhsName name:inpack) op:Equal rhs:{(0)} spids:[25]) ] spids: [22] ) (AndOr children: [ (C {(eval)} { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(git)} {(count-objects)} {(-v)}) (C {(sed)} {(-n)} {(-e)} {(SQ <"s/^count: \\(.*\\)/loose=\\1/p">)} {(-e)} {(SQ <"s/^in-pack: \\(.*\\)/inpack=\\1/p">)} ) ] negated: False ) ] ) left_token: spids: [32 63] ) ) } ) (C {(echo)} { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$loose")}) right: (ArithWord w:{($ VSub_Name "$inpack")}) ) spids: [71 80] ) } ) ] op_id: Op_DAmp ) ] spids: [19] ) spids: [14 18] ) (C {(test_expect_success)} {(setup)} { (SQ <"\n"> <"\t(\n"> <"\t\tgit init original &&\n"> <"\t\tcd original &&\n"> <"\t\ti=0 &&\n"> <"\t\twhile test $i -le 100\n"> <"\t\tdo\n"> <"\t\t\techo \"$i\" >count &&\n"> <"\t\t\tgit add count &&\n"> <"\t\t\tgit commit -m \"$i\" || exit\n"> <"\t\t\ti=$(($i + 1))\n"> <"\t\tdone\n"> <"\t) &&\n"> <"\t(\n"> <"\t\tgit clone --reference=original \"file://$(pwd)/original\" one &&\n"> <"\t\tcd one &&\n"> <"\t\techo Z >count &&\n"> <"\t\tgit add count &&\n"> <"\t\tgit commit -m Z &&\n"> <"\t\tcount_objects >../one.count\n"> <"\t) &&\n"> <"\tA=$(pwd)/original/.git/objects &&\n"> <"\tgit init receiver &&\n"> <"\techo \"$A\" >receiver/.git/objects/info/alternates &&\n"> <"\tgit init fetcher &&\n"> <"\techo \"$A\" >fetcher/.git/objects/info/alternates\n"> ) } ) (C {(test_expect_success)} {(SQ <"pushing into a repository with the same alternate">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd one &&\n"> <"\t\tgit push ../receiver master:refs/heads/it\n"> <"\t) &&\n"> <"\t(\n"> <"\t\tcd receiver &&\n"> <"\t\tcount_objects >../receiver.count\n"> <"\t) &&\n"> <"\ttest_cmp one.count receiver.count\n"> ) } ) (C {(test_expect_success)} {(SQ <"fetching from a repository with the same alternate">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd fetcher &&\n"> <"\t\tgit fetch ../one master:refs/heads/it &&\n"> <"\t\tcount_objects >../fetcher.count\n"> <"\t) &&\n"> <"\ttest_cmp one.count fetcher.count\n"> ) } ) (C {(test_done)}) ] )