#!/usr/bin/bash

set -x

export GIT_CONFIG_COUNT=2

export GIT_CONFIG_KEY_0=protocol.file.allow
export GIT_CONFIG_VALUE_0=always
export GIT_CONFIG_KEY_1=init.defaultBranch
export GIT_CONFIG_VALUE_1=main

export GIT_AUTHOR_NAME=testname
export GIT_AUTHOR_EMAIL=test@suse.com
export GIT_AUTHOR_DATE='2005-04-07T22:13:13'
export GIT_COMMITTER_NAME=testname
export GIT_COMMITTER_EMAIL=test@suse.com
export GIT_COMMITTER_DATE='2005-04-07T22:13:13'

create_prjgit_sample() {
	mkdir prjgit
	pushd prjgit

	git init -q --object-format=sha256 -b main
	echo Project git is here > README.md
	git add README.md
	git config receive.denyCurrentBranch ignore

	git submodule init
	git submodule -q add ../pkgA pkgA
	git submodule -q add ../pkgB pkgB
	git submodule -q add ../pkgC pkgC
	git commit -q -m 'first commit'

	git checkout -b base_add_b1 main
	git submodule -q add ../pkgB1 pkgB1
	git commit -q -m "pkgB1 added"

	git checkout -b base_add_b2 main
	git clean -ffxd
	git submodule -q add ../pkgB2 pkgB2
	git commit -q -m "pkgB2 added"

	git checkout main
	git clean -ffxd
	git submodule -q add -f ../pkgB1 pkgB1
	git commit -q -m "main adding pkgB1"

	popd
}

create_pkgA() {
	mkdir pkgA
	pushd pkgA

	git init -q --object-format=sha256
	git config receive.denyCurrentBranch ignore
	echo "Package A" > README.md
	git add README.md

	git commit -q -m 'Something base here'

	popd
}

create_pkgB() {
	mkdir pkgB
	pushd pkgB

	git init -q --object-format=sha256
	git config receive.denyCurrentBranch ignore
	echo "Package B" > README.md
	git add README.md

	git commit -q -m 'Something also base here'

	popd
}

create_pkgB1() {
	mkdir pkgB1
	pushd pkgB1

	git init -q --object-format=sha256
	git config receive.denyCurrentBranch ignore
	echo "Package B1" > README.md
	git add README.md

	git commit -q -m 'Something also base here'

	popd
}

create_pkgB2() {
	mkdir pkgB2
	pushd pkgB2

	git init -q --object-format=sha256
	git config receive.denyCurrentBranch ignore
	echo "Package B2" > README.md
	git add README.md

	git commit -q -m 'Something also base here'

	popd
}

create_pkgC() {
	mkdir pkgC
	pushd pkgC

	git init -q --object-format=sha256
	git config receive.denyCurrentBranch ignore
	echo "Package C" > README.md
	git add README.md

	git commit -q -m 'Something another base here'

	popd
}

create_pkgA
create_pkgB
create_pkgB1
create_pkgB2
create_pkgC
create_prjgit_sample

