# vim: syn=sh:
for wr in 0 1
do
    for bc in 0 1
    do
        for ais in 0 1
        do
            cd $TESTDIR
            $TESTDIR/rollback || die "rollback failed"
            editrc GL_WILDREPOS $wr
            editrc GL_BIG_CONFIG $bc
            echo "\$GL_ALL_INCLUDES_SPECIAL = $ais;" | addrc

            # ----------
            name "INTERNAL"
            echo|ugc
            name "daemon access for testing repo"
            runremote ls -al $TEST_BASE/testing.git/git-daemon-export-ok
            [ "$ais" = "0" ] && expect "ls: cannot access $TEST_BASE/testing.git/git-daemon-export-ok: No such file or directory"
            [ "$ais" = "1" ] && expect "$USER $USER .* $TEST_BASE/testing.git/git-daemon-export-ok"

            name "INTERNAL"
            echo "
                @leads = u1 u2
                @devs = u1 u2 u3 u4

                @gbar = bar
                repo    @gbar
                    RW+             =   @leads
                    RW              =   @devs
            " | ugc
            expect_push_ok "master -> master"
            runremote ls -al $TEST_BASE/bar.git/git-daemon-export-ok
            expect "ls: cannot access $TEST_BASE/bar.git/git-daemon-export-ok: No such file or directory"
            runremote ls -al projects.list
            [ "$ais" = "0" ] && expect "$USER $USER 0 .* projects.list"
            [ "$ais" = "1" ] && expect "$USER $USER 12 .* projects.list"
            runremote cat projects.list
            [ "$ais" = "0" ] && notexpect "testing.git"
            [ "$ais" = "1" ] && expect "testing.git"

            name "add daemon access to bar"
            echo "
                    R               =   daemon
            " | ugc
            runremote ls -al $TEST_BASE/bar.git/git-daemon-export-ok
            expect "$USER $USER .* $TEST_BASE/bar.git/git-daemon-export-ok"
            runremote ls -al projects.list
            [ "$ais" = "0" ] && expect "$USER $USER 0 .* projects.list"
            [ "$ais" = "1" ] && expect "$USER $USER 12 .* projects.list"

            name "add foo with gitweb access"
            echo "
                @leads = u1 u2
                @devs = u1 u2 u3 u4

                @gfoo = foo
                repo    @gfoo
                    RW+             =   @leads
                    RW              =   @devs
                    R               =   gitweb
            " | ugc
            expect_push_ok "master -> master"
            runremote ls -al projects.list
            [ "$ais" = "0" ] && expect "$USER $USER 8 .* projects.list"
            [ "$ais" = "1" ] && expect "$USER $USER 20 .* projects.list"
            runremote cat projects.list
            [ "$ais" = "0" ] && notexpect "testing.git"
            [ "$ais" = "1" ] && expect "testing.git"
            expect "foo.git"

            name "add gitweb access to bar"
            echo "
                repo    @gbar
                    R               =   gitweb
            " | ugc
            expect_push_ok "master -> master"
            runremote ls -al projects.list
            [ "$ais" = "0" ] && expect "$USER $USER 16 .* projects.list"
            [ "$ais" = "1" ] && expect "$USER $USER 28 .* projects.list"
            runremote cat projects.list
            [ "$ais" = "0" ] && notexpect "testing.git"
            [ "$ais" = "1" ] && expect "testing.git"
            expect "foo.git"
            expect "bar.git"

            name "add repo baz with description"
            echo "
                @gbaz = baz
                repo    @gbaz
                    RW              =   @leads

                baz     =   \"this is repo baz\"
            " | ugc
            expect_push_ok "master -> master"
            expect "remote: Initialized empty Git repository in $TEST_BASE_FULL/baz.git/"
            runremote ls -al projects.list
            [ "$ais" = "0" ] && expect "$USER $USER 24 .* projects.list"
            [ "$ais" = "1" ] && expect "$USER $USER 36 .* projects.list"
            runremote cat projects.list
            [ "$ais" = "0" ] && notexpect "testing.git"
            [ "$ais" = "1" ] && expect "testing.git"
            expect "foo.git"
            expect "bar.git"
            expect "baz.git"
            runremote ls -al $TEST_BASE/baz.git/description
            expect "$USER $USER 17 .* $TEST_BASE/baz.git/description"
            runremote cat $TEST_BASE/baz.git/description
            expect "this is repo baz"

            name "add owner to testing repo"
            echo "
                testing \"sitaram\"     =   \"this is the testing repo\"
            " | ugc
            expect_push_ok "master -> master"
            runremote ls -al projects.list
            expect "$USER $USER 36 .* projects.list"
            runremote cat projects.list
            expect "testing.git"
            expect "foo.git"
            expect "bar.git"
            expect "baz.git"
            runremote cat $TEST_BASE/testing.git/config
            expect "\[gitweb\]"
            expect "owner = sitaram"
            runremote ls -al $TEST_BASE/testing.git/description
            expect "$USER $USER 25 .* $TEST_BASE/testing.git/description"
            runremote cat $TEST_BASE/testing.git/description
            expect "this is the testing repo"

            name INTERNAL
        done
    done
done