#!/bin/sh global test_description := ''git remote group handling'' source ./test-lib.sh proc mark { echo $1 >mark } proc update_repo { shell {cd $1 && echo content >>file && git add file && git commit -F ../mark} } proc update_repos { update_repo one $1 && update_repo two $1 } proc repo_fetched { if test $[git log -1 --pretty=format:%s $1 --] = $[cat mark] { echo >&2 "repo was fetched: $1> !2 "repo was fetched: $1" return 0 } echo >&2 "repo was not fetched: $1> !2 "repo was not fetched: $1" return 1 } test_expect_success 'setup' ' mkdir one && (cd one && git init) && mkdir two && (cd two && git init) && git remote add -m master one one && git remote add -m master two two ' test_expect_success 'no group updates all' ' mark update-all && update_repos && git remote update && repo_fetched one && repo_fetched two ' test_expect_success 'nonexistent group produces error' ' mark nonexistent && update_repos && test_must_fail git remote update nonexistent && ! repo_fetched one && ! repo_fetched two ' test_expect_success 'updating group updates all members (remote update)' ' mark group-all && update_repos && git config --add remotes.all one && git config --add remotes.all two && git remote update all && repo_fetched one && repo_fetched two ' test_expect_success 'updating group updates all members (fetch)' ' mark fetch-group-all && update_repos && git fetch all && repo_fetched one && repo_fetched two ' test_expect_success 'updating group does not update non-members (remote update)' ' mark group-some && update_repos && git config --add remotes.some one && git remote update some && repo_fetched one && ! repo_fetched two ' test_expect_success 'updating group does not update non-members (fetch)' ' mark fetch-group-some && update_repos && git config --add remotes.some one && git remote update some && repo_fetched one && ! repo_fetched two ' test_expect_success 'updating remote name updates that remote' ' mark remote-name && update_repos && git remote update one && repo_fetched one && ! repo_fetched two ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git remote group handling">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: mark body: (BraceGroup children: [ (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Number "$1"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(mark)} spids:[27])] ) ] spids: [18] ) spids: [14 17] ) (FuncDef name: update_repo body: (BraceGroup children: [ (Subshell child: (AndOr children: [ (C {(cd)} {($ VSub_Number "$1")}) (AndOr children: [ (SimpleCommand words: [{(echo)} {(content)}] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{(file)} spids:[52])] ) (AndOr children: [ (C {(git)} {(add)} {(file)}) (C {(git)} {(commit)} {(-F)} {(../mark)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) spids: [40 74] ) ] spids: [37] ) spids: [33 36] ) (FuncDef name: update_repos body: (BraceGroup children: [ (AndOr children: [ (C {(update_repo)} {(one)} {($ VSub_Number "$1")}) (C {(update_repo)} {(two)} {($ VSub_Number "$1")}) ] op_id: Op_DAmp ) ] spids: [83] ) spids: [79 82] ) (FuncDef name: repo_fetched body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(test)} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(log)} {(-1)} {(--pretty) (Lit_Other "=") (format) (Lit_Other ":") (Lit_Other "%") (s) } {($ VSub_Number "$1")} {(--)} ) ] ) left_token: spids: [116 133] ) ) } {(Lit_Other "=")} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(cat)} {(mark)})]) left_token: spids: [139 143] ) ) } ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("repo was fetched: ") ($ VSub_Number "$1"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[152])] ) (ControlFlow token: arg_word:{(0)}) ] spids: [-1 147] ) ] spids: [-1 166] ) (SimpleCommand words: [{(echo)} {(DQ ("repo was not fetched: ") ($ VSub_Number "$1"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[171])] ) (ControlFlow token: arg_word:{(1)}) ] spids: [108] ) spids: [104 107] ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tmkdir one && (cd one && git init) &&\n"> <"\tmkdir two && (cd two && git init) &&\n"> <"\tgit remote add -m master one one &&\n"> <"\tgit remote add -m master two two\n"> ) } ) (C {(test_expect_success)} {(SQ <"no group updates all">)} { (SQ <"\n"> <"\tmark update-all &&\n"> <"\tupdate_repos &&\n"> <"\tgit remote update &&\n"> <"\trepo_fetched one &&\n"> <"\trepo_fetched two\n"> ) } ) (C {(test_expect_success)} {(SQ <"nonexistent group produces error">)} { (SQ <"\n"> <"\tmark nonexistent &&\n"> <"\tupdate_repos &&\n"> <"\ttest_must_fail git remote update nonexistent &&\n"> <"\t! repo_fetched one &&\n"> <"\t! repo_fetched two\n"> ) } ) (C {(test_expect_success)} {(SQ <"updating group updates all members (remote update)">)} { (SQ <"\n"> <"\tmark group-all &&\n"> <"\tupdate_repos &&\n"> <"\tgit config --add remotes.all one &&\n"> <"\tgit config --add remotes.all two &&\n"> <"\tgit remote update all &&\n"> <"\trepo_fetched one &&\n"> <"\trepo_fetched two\n"> ) } ) (C {(test_expect_success)} {(SQ <"updating group updates all members (fetch)">)} { (SQ <"\n"> <"\tmark fetch-group-all &&\n"> <"\tupdate_repos &&\n"> <"\tgit fetch all &&\n"> <"\trepo_fetched one &&\n"> <"\trepo_fetched two\n"> ) } ) (C {(test_expect_success)} {(SQ <"updating group does not update non-members (remote update)">)} { (SQ <"\n"> <"\tmark group-some &&\n"> <"\tupdate_repos &&\n"> <"\tgit config --add remotes.some one &&\n"> <"\tgit remote update some &&\n"> <"\trepo_fetched one &&\n"> <"\t! repo_fetched two\n"> ) } ) (C {(test_expect_success)} {(SQ <"updating group does not update non-members (fetch)">)} { (SQ <"\n"> <"\tmark fetch-group-some &&\n"> <"\tupdate_repos &&\n"> <"\tgit config --add remotes.some one &&\n"> <"\tgit remote update some &&\n"> <"\trepo_fetched one &&\n"> <"\t! repo_fetched two\n"> ) } ) (C {(test_expect_success)} {(SQ <"updating remote name updates that remote">)} { (SQ <"\n"> <"\tmark remote-name &&\n"> <"\tupdate_repos &&\n"> <"\tgit remote update one &&\n"> <"\trepo_fetched one &&\n"> <"\t! repo_fetched two\n"> ) } ) (C {(test_done)}) ] )