Skip to content

Instantly share code, notes, and snippets.

@MattWoelk
Forked from 5sw/hh_to_git.sh
Last active August 29, 2015 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattWoelk/32d1681bc69e0d0d06ee to your computer and use it in GitHub Desktop.
Save MattWoelk/32d1681bc69e0d0d06ee to your computer and use it in GitHub Desktop.
Take a Handmade Hero .zip and make it a git repo, with one commit for each day.
#!/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=$(readlink -f "${args[0]}")
repo="HandmadeHero"
mkdir -p "$repo"
rm -rf "$repo/.git"
cd "$repo"
git init
unzip -o "$source" -d ./sources
folders="$(ls "./sources" | sort)"
while read -r folder; do
base=$(basename "$folder")
day="${base:18:3}"
echo "FOLDER $folder"
tag="day$day"
unzip -o "./sources/$folder"
git add .
git commit -am "Importing code for day $day" && git tag "$tag"
done <<< "$folders"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment