#!/bin/sh global test_description := ''pushing to a mirror repository'' source ./test-lib.sh global D := $[pwd] proc invert { if @Argv { return 1 } else { return 0 } } proc mk_repo_pair { rm -rf master mirror && mkdir mirror && shell { cd mirror && git init && git config receive.denyCurrentBranch warn } && mkdir master && shell { cd master && git init && git remote add $1 up ../mirror } } # BRANCH tests test_expect_success 'push mirror creates new branches' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git push --mirror up ) && master_master=$(cd master && git show-ref -s --verify refs/heads/master) && mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) && test "$master_master" = "$mirror_master" ' test_expect_success 'push mirror updates existing branches' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git push --mirror up && echo two >foo && git add foo && git commit -m two && git push --mirror up ) && master_master=$(cd master && git show-ref -s --verify refs/heads/master) && mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) && test "$master_master" = "$mirror_master" ' test_expect_success 'push mirror force updates existing branches' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git push --mirror up && echo two >foo && git add foo && git commit -m two && git push --mirror up && git reset --hard HEAD^ git push --mirror up ) && master_master=$(cd master && git show-ref -s --verify refs/heads/master) && mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) && test "$master_master" = "$mirror_master" ' test_expect_success 'push mirror removes branches' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git branch remove master && git push --mirror up && git branch -D remove git push --mirror up ) && ( cd mirror && invert git show-ref -s --verify refs/heads/remove ) ' test_expect_success 'push mirror adds, updates and removes branches together' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git branch remove master && git push --mirror up && git branch -D remove && git branch add master && echo two >foo && git add foo && git commit -m two && git push --mirror up ) && master_master=$(cd master && git show-ref -s --verify refs/heads/master) && master_add=$(cd master && git show-ref -s --verify refs/heads/add) && mirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) && mirror_add=$(cd mirror && git show-ref -s --verify refs/heads/add) && test "$master_master" = "$mirror_master" && test "$master_add" = "$mirror_add" && ( cd mirror && invert git show-ref -s --verify refs/heads/remove ) ' # TAG tests test_expect_success 'push mirror creates new tags' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git tag -f tmaster master && git push --mirror up ) && master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) && mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) && test "$master_master" = "$mirror_master" ' test_expect_success 'push mirror updates existing tags' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git tag -f tmaster master && git push --mirror up && echo two >foo && git add foo && git commit -m two && git tag -f tmaster master && git push --mirror up ) && master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) && mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) && test "$master_master" = "$mirror_master" ' test_expect_success 'push mirror force updates existing tags' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git tag -f tmaster master && git push --mirror up && echo two >foo && git add foo && git commit -m two && git tag -f tmaster master && git push --mirror up && git reset --hard HEAD^ git tag -f tmaster master && git push --mirror up ) && master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) && mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) && test "$master_master" = "$mirror_master" ' test_expect_success 'push mirror removes tags' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git tag -f tremove master && git push --mirror up && git tag -d tremove git push --mirror up ) && ( cd mirror && invert git show-ref -s --verify refs/tags/tremove ) ' test_expect_success 'push mirror adds, updates and removes tags together' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git tag -f tmaster master && git tag -f tremove master && git push --mirror up && git tag -d tremove && git tag tadd master && echo two >foo && git add foo && git commit -m two && git tag -f tmaster master && git push --mirror up ) && master_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) && master_add=$(cd master && git show-ref -s --verify refs/tags/tadd) && mirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) && mirror_add=$(cd mirror && git show-ref -s --verify refs/tags/tadd) && test "$master_master" = "$mirror_master" && test "$master_add" = "$mirror_add" && ( cd mirror && invert git show-ref -s --verify refs/tags/tremove ) ' test_expect_success 'remote.foo.mirror adds and removes branches' ' mk_repo_pair --mirror && ( cd master && echo one >foo && git add foo && git commit -m one && git branch keep master && git branch remove master && git push up && git branch -D remove git push up ) && ( cd mirror && git show-ref -s --verify refs/heads/keep && invert git show-ref -s --verify refs/heads/remove ) ' test_expect_success 'remote.foo.mirror=no has no effect' ' mk_repo_pair && ( cd master && echo one >foo && git add foo && git commit -m one && git config --add remote.up.mirror no && git branch keep master && git push --mirror up && git branch -D keep && git push up : ) && ( cd mirror && git show-ref -s --verify refs/heads/keep ) ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"pushing to a mirror repository">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:D) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [16 18] ) } spids: [15] ) ] spids: [15] ) (FuncDef name: invert body: (BraceGroup children: [ (If arms: [ (if_arm cond: [(Sentence child:(C {(DQ ($ VSub_At "$@"))}) terminator:)] action: [(ControlFlow token: arg_word:{(1)})] spids: [-1 36] ) ] else_action: [(ControlFlow token: arg_word:{(0)})] spids: [44 52] ) ] spids: [26] ) spids: [21 25] ) (FuncDef name: mk_repo_pair body: (BraceGroup children: [ (AndOr children: [ (C {(rm)} {(-rf)} {(master)} {(mirror)}) (AndOr children: [ (C {(mkdir)} {(mirror)}) (AndOr children: [ (Subshell child: (AndOr children: [ (C {(cd)} {(mirror)}) (AndOr children: [ (C {(git)} {(init)}) (C {(git)} {(config)} {(receive.denyCurrentBranch)} {(warn)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) spids: [83 109] ) (AndOr children: [ (C {(mkdir)} {(master)}) (Subshell child: (AndOr children: [ (C {(cd)} {(master)}) (AndOr children: [ (C {(git)} {(init)}) (C {(git)} {(remote)} {(add)} {($ VSub_Number "$1")} {(up)} {(../mirror)} ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) spids: [121 151] ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [62] ) spids: [57 61] ) (C {(test_expect_success)} {(SQ <"push mirror creates new branches">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit push --mirror up\n"> <"\t) &&\n"> <"\tmaster_master=$(cd master && git show-ref -s --verify refs/heads/master) &&\n"> <"\tmirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&\n"> <"\ttest \"$master_master\" = \"$mirror_master\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"push mirror updates existing branches">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\techo two >foo && git add foo && git commit -m two &&\n"> <"\t\tgit push --mirror up\n"> <"\t) &&\n"> <"\tmaster_master=$(cd master && git show-ref -s --verify refs/heads/master) &&\n"> <"\tmirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&\n"> <"\ttest \"$master_master\" = \"$mirror_master\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"push mirror force updates existing branches">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\techo two >foo && git add foo && git commit -m two &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\tgit reset --hard HEAD^\n"> <"\t\tgit push --mirror up\n"> <"\t) &&\n"> <"\tmaster_master=$(cd master && git show-ref -s --verify refs/heads/master) &&\n"> <"\tmirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&\n"> <"\ttest \"$master_master\" = \"$mirror_master\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"push mirror removes branches">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit branch remove master &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\tgit branch -D remove\n"> <"\t\tgit push --mirror up\n"> <"\t) &&\n"> <"\t(\n"> <"\t\tcd mirror &&\n"> <"\t\tinvert git show-ref -s --verify refs/heads/remove\n"> <"\t)\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"push mirror adds, updates and removes branches together">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit branch remove master &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\tgit branch -D remove &&\n"> <"\t\tgit branch add master &&\n"> <"\t\techo two >foo && git add foo && git commit -m two &&\n"> <"\t\tgit push --mirror up\n"> <"\t) &&\n"> <"\tmaster_master=$(cd master && git show-ref -s --verify refs/heads/master) &&\n"> <"\tmaster_add=$(cd master && git show-ref -s --verify refs/heads/add) &&\n"> <"\tmirror_master=$(cd mirror && git show-ref -s --verify refs/heads/master) &&\n"> <"\tmirror_add=$(cd mirror && git show-ref -s --verify refs/heads/add) &&\n"> <"\ttest \"$master_master\" = \"$mirror_master\" &&\n"> <"\ttest \"$master_add\" = \"$mirror_add\" &&\n"> <"\t(\n"> <"\t\tcd mirror &&\n"> <"\t\tinvert git show-ref -s --verify refs/heads/remove\n"> <"\t)\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"push mirror creates new tags">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit tag -f tmaster master &&\n"> <"\t\tgit push --mirror up\n"> <"\t) &&\n"> <"\tmaster_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&\n"> <"\tmirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&\n"> <"\ttest \"$master_master\" = \"$mirror_master\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"push mirror updates existing tags">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit tag -f tmaster master &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\techo two >foo && git add foo && git commit -m two &&\n"> <"\t\tgit tag -f tmaster master &&\n"> <"\t\tgit push --mirror up\n"> <"\t) &&\n"> <"\tmaster_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&\n"> <"\tmirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&\n"> <"\ttest \"$master_master\" = \"$mirror_master\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"push mirror force updates existing tags">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit tag -f tmaster master &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\techo two >foo && git add foo && git commit -m two &&\n"> <"\t\tgit tag -f tmaster master &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\tgit reset --hard HEAD^\n"> <"\t\tgit tag -f tmaster master &&\n"> <"\t\tgit push --mirror up\n"> <"\t) &&\n"> <"\tmaster_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&\n"> <"\tmirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&\n"> <"\ttest \"$master_master\" = \"$mirror_master\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"push mirror removes tags">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit tag -f tremove master &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\tgit tag -d tremove\n"> <"\t\tgit push --mirror up\n"> <"\t) &&\n"> <"\t(\n"> <"\t\tcd mirror &&\n"> <"\t\tinvert git show-ref -s --verify refs/tags/tremove\n"> <"\t)\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"push mirror adds, updates and removes tags together">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit tag -f tmaster master &&\n"> <"\t\tgit tag -f tremove master &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\tgit tag -d tremove &&\n"> <"\t\tgit tag tadd master &&\n"> <"\t\techo two >foo && git add foo && git commit -m two &&\n"> <"\t\tgit tag -f tmaster master &&\n"> <"\t\tgit push --mirror up\n"> <"\t) &&\n"> <"\tmaster_master=$(cd master && git show-ref -s --verify refs/tags/tmaster) &&\n"> <"\tmaster_add=$(cd master && git show-ref -s --verify refs/tags/tadd) &&\n"> <"\tmirror_master=$(cd mirror && git show-ref -s --verify refs/tags/tmaster) &&\n"> <"\tmirror_add=$(cd mirror && git show-ref -s --verify refs/tags/tadd) &&\n"> <"\ttest \"$master_master\" = \"$mirror_master\" &&\n"> <"\ttest \"$master_add\" = \"$mirror_add\" &&\n"> <"\t(\n"> <"\t\tcd mirror &&\n"> <"\t\tinvert git show-ref -s --verify refs/tags/tremove\n"> <"\t)\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"remote.foo.mirror adds and removes branches">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair --mirror &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit branch keep master &&\n"> <"\t\tgit branch remove master &&\n"> <"\t\tgit push up &&\n"> <"\t\tgit branch -D remove\n"> <"\t\tgit push up\n"> <"\t) &&\n"> <"\t(\n"> <"\t\tcd mirror &&\n"> <"\t\tgit show-ref -s --verify refs/heads/keep &&\n"> <"\t\tinvert git show-ref -s --verify refs/heads/remove\n"> <"\t)\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"remote.foo.mirror=no has no effect">)} { (SQ <"\n"> <"\n"> <"\tmk_repo_pair &&\n"> <"\t(\n"> <"\t\tcd master &&\n"> <"\t\techo one >foo && git add foo && git commit -m one &&\n"> <"\t\tgit config --add remote.up.mirror no &&\n"> <"\t\tgit branch keep master &&\n"> <"\t\tgit push --mirror up &&\n"> <"\t\tgit branch -D keep &&\n"> <"\t\tgit push up :\n"> <"\t) &&\n"> <"\t(\n"> <"\t\tcd mirror &&\n"> <"\t\tgit show-ref -s --verify refs/heads/keep\n"> <"\t)\n"> <"\n"> ) } ) (C {(test_done)}) ] )