Skip to content

Instantly share code, notes, and snippets.

@nsenica
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsenica/cbc5a4975666d7b02164 to your computer and use it in GitHub Desktop.
Save nsenica/cbc5a4975666d7b02164 to your computer and use it in GitHub Desktop.
HandmadeHero to git
#!/bin/bash
# This script makes a HandmadeHero directory and populates it as a git repo with the supplied .zip file.
# Example: ./hh_to_git.sh handmade_hero_065_source.zip
args=("$@")
if [ ${#args[@]} -ne 1 ]
then
echo "Need one argument: the source zip file."
exit
fi
source=${args[0]}
repo="HandmadeHero"
last_day=0
if [[ ! -d "$repo" || ! -d "$repo/.git" ]]
then
mkdir -p "$repo"
cd "$repo"
git init
echo "sources/" > .gitignore
else
cd "$repo"
last_tag=$(git tag | sort | tail -n 1)
if [ ! -z "$last_tag" ]
then
last_day="${last_tag:3:3}"
fi
fi
unzip -o "$source" -d ./sources
folders="$(ls "./sources" | sort)"
while read -r folder; do
base=$(basename "$folder")
day="${base:18:3}"
if ! [[ "$base" =~ ^handmade_hero* ]]
then
echo "Skipping $base"
continue
fi
if [ "$day" -gt "$last_day" ]
then
echo "Processing $folder"
tag="day$day"
unzip -o "./sources/$folder"
git add .
git commit -am "Importing code for day $day" && git tag "$tag"
fi
done <<< "$folders"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment