#!/bin/bash

# ----------------------------------------------------------------------------
# Adapted from this StackOverflow thread: https://stackoverflow.com/a/49181193
# ----------------------------------------------------------------------------

if [ ! $# == 1 ]; then {
    echo "Usage: $0 <foldername[HoloTomo, PXCT]>"
    echo "Example: $0 HoloTomo"
    exit 
} fi

localRepo=$1 # Holtomo or PXCT
remoteRepo=https://github.com/jcesardasilva/toupy.git # github repo
subDir=templates/$1 # subdirectory

# Create local repository for subdirectory checkout, make it hidden to avoid having to drill down to the subfolder
if [ ! -d ./.$localRepo ]; then
  mkdir ./.$localRepo
fi
cd ./.$localRepo
git init
git remote add -f origin $remoteRepo
git config core.sparseCheckout true

# Add the subdirectory of interest to the sparse checkout.
echo $subDir >> .git/info/sparse-checkout

git pull origin master

# Change name of the subdirectory of interest
cd ..
mv ./.$localRepo/$subDir $localRepo
