#!/bin/bash

Help()
{
   echo "
NAME
    creation_repo.sh
SYNOPSIS
    creation_repo.sh [SSH LINK to en empty remote git repository] 
DESCRIPTION
    This script is in writing.
    It creates a git repository in the current directory, linked to a remote passed as argument. Everything is up-to-date between the remote and the local versions. The data stored is generated randomly in binary.
OPTIONS
    -h prints the help. "
}
if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then
    while getopts ":h" option; do
   case $option in
      h) # display Help
         Help
         exit;;
     \?) # Invalid option
         echo "Error: Invalid option"
         exit;;
   esac
done
fi

create_random_file(){
    run dd if=/dev/urandom of=$1 bs=$2 count=1 &> /dev/null
}

REPO_NAME=performance_testing
REPO_PATH=./remote

if [ ! -d $REPO_PATH ]; then
    mkdir $REPO_PATH
fi
cd $REPO_PATH
if [ ! -d $REPO_NAME ]; then
    mkdir $REPO_NAME
    cd $REPO_NAME
    git init
    git branch -m main
    create_random_file 'sample0' '1M'
    git add .
    git commit -m"first 1M sample created"
    git tag start
    create_random_file 'sample1' '1M'
    git add sample1
    git commit -m"second 1M sample created"
    git branch secondary
    git checkout secondary
    create_random_file 'sample2' '500K'
    git add sample2  
    git commit -m"first 500K sample created in branch secondary"
    git checkout main
    create_random_file 'sample3' '1M'
    git add sample3
    git commit -m"third 1M sample created"
    create_random_file 'sample4' '5M'
    git add sample4
    git commit -m"first 5M sample created"
    rm sample4
    git add sample4
    git commit -m"sample4 deleted"
    cd ..
fi
cd ..