Last active
March 31, 2016 06:50
-
-
Save yrps/45f1c6d38853a9ecc129 to your computer and use it in GitHub Desktop.
bash script to convert archives to git tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/sh | |
| set -o errexit | |
| archdir=$(pwd)/arch-to-git/archives | |
| repodir=$(pwd)/arch-to-git/repo | |
| mkdir -p "$archdir" "$repodir" | |
| pushd "$archdir" | |
| touch junk.exe trash.cab | |
| echo 'revision one' > data.txt | |
| zip -q 'archive one' data* junk* trash* | |
| echo 'revision two' >> data.txt | |
| zip -q 'archive two' data* junk* trash* | |
| echo 'revision three' >> data.txt | |
| zip -q 'archive three' data* junk* trash* | |
| rm data* junk* trash* | |
| touch 'archive one.zip' --date='2016-03-01 -13 days' | |
| touch 'archive two.zip' --date='2016-03-01 -12 days' | |
| touch 'archive three.zip' --date='2016-03-01 -11 days' | |
| find . -type f -name '*.zip' -printf "%T@\t%P\n" | sort >manifest.tsv | |
| delim=$'\t' | |
| popd | |
| pushd "$repodir" | |
| git init | |
| printf '*.exe\n*.cab' > .gitignore | |
| git add .gitignore | |
| git commit -m 'first commit; adding gitignore' | |
| author='--author="joe <joe@company.org>"' | |
| cutoff='archive three.zip' | |
| while IFS=$delim read backdate archname; do | |
| [ "$archname" = "$cutoff" ] && author= | |
| unzip -q "$archdir/$archname" | |
| git add --all | |
| git commit -m "from archive: $archname" --date="$backdate" "$author" | |
| mv .git .gitignore .. | |
| rm -rf ./* | |
| mv ../.git ../.gitignore . | |
| echo | |
| done <"$archdir/manifest.tsv" | |
| git checkout -- . | |
| git --no-pager log --reverse --format='%h %ad %an "%s"' | |
| popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment