#!/bin/bash

# Run the merge set-up script to create a clean DeepDive1 dir.

SCRIPT_DIR=$(cd $(dirname ${0}); pwd)

. ${SCRIPT_DIR}/utils.sh

REPO_DIR=${SCRIPT_DIR}/largeFileRepo

${SCRIPT_DIR}/simple-setup.sh ${REPO_DIR}

cd ${REPO_DIR}

declaim "Creating tags"
git_command git tag Rel1.0.lw Rel1
git_command git tag -m "\"An annotated tag for the Rel1 release\"" Rel1.0.a Rel1
git_command git tag Rel2.0.lw Rel2
git_command git tag -m "\"An annotated tag for the Rel1 release\"" Rel2.0.a Rel2

declaim "Merging Rel1 and Rel2 into master"
git_command git checkout master
git_command git merge Rel1
git_command git merge -m "\"commit8\"" Rel2

declaim "Repository size in kibibytes: $(du -sk .)"

declaim "Creating a 10MiB binary file"

gzip -9 -c information.md > information_compressed.out

counter=0
while [ ${counter} -lt 15 ];
do
  cat information_compressed.out information_compressed.out > information_compressed2.out
  mv information_compressed2.out information_compressed.out
  counter=$(( $counter + 1 ))
done
mv information_compressed.out largeInformation.md

declaim "Adding and commiting that new file"
git_command git add largeInformation.md
git_command git commit -m "\"A large, awkwardly binary file\""

declaim "Creating and checking out the Rel3 branch"
git_command git checkout -b Rel3

declaim "Modifying the large binary file on Rel3"
cat information.md information.md information.md >> largeInformation.md

declaim "Adding and commiting that change to the binary file."
git_command git add largeInformation.md
git_command git commit -m "\"Changes to that large file\""

declaim "Creating and checking out the Rel4 branch"
git_command git checkout master
git_command git checkout -b Rel4

declaim "Modifying the large binary file on Rel4"
cat largeInformation.md largeInformation.md > largeInformation2.md
rm largeInformation.md
mv largeInformation{2,}.md

declaim "Adding and commiting that change to the binary file."
git_command git add largeInformation.md
git_command git commit -m "\"An even larger file\""

declaim "Merging Rel3 and Rel4 into master"
git_command git checkout master
git_command git merge Rel3
git_command git merge -s recursive -Xtheirs -m "\"Merge of Rel4 into master\"" Rel4

declaim "Removing that large file, now."
git_command git rm largeInformation.md
git_command git commit -m "\"large binary file gone again\""

git_command git log --oneline --graph --decorate --all

declaim "Repository size in kibibytes: $(du -sk .)"
