Created
December 21, 2024 22:51
-
-
Save rofl0r/217d40455dc6bbac2b6452c740b1991d to your computer and use it in GitHub Desktop.
create git repo from a set of release tarballs
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
#!/bin/sh | |
test -z "$2" && { | |
echo "$0 DIR FILELIST.TXT" | |
echo "create a git repository in DIR from tarballs listed in FILELIST" | |
echo "you can create the FILELIST with ls -1 *.tar* and then edit it" | |
echo "so the order is correct." | |
echo | |
echo "this script abuses the fact that the combination of git rm and" | |
echo "git add successfully detects renamed files, so the process is" | |
echo "a lot simpler than it would otherwise be." | |
exit 1 | |
} | |
dir="$(readlink -f "$1")" | |
filelist="$(readlink -f "$2")" | |
tmpdir=/tmp/gft.$$.tmp | |
this=$(pwd) | |
mkdir "$dir" | |
cd "$dir" | |
git init | |
cat << EOF > .gitignore | |
*.o | |
*.a | |
EOF | |
git add .gitignore | |
git commit -m "root" | |
for t in `cat "$filelist"` ; do | |
cd "$this" | |
tar="$(readlink -f "$t")" | |
cd "$dir" | |
# remove empty directories, as they're not in git index and cause git rm * to fail | |
find . -type d -exec rmdir {} \; 2>/dev/null | |
git rm -r * | |
mkdir "$tmpdir" | |
cd "$tmpdir" | |
tar xf "$tar" | |
cd * | |
cp -a * "$dir"/ | |
cd "$dir" | |
rm -rf "$tmpdir" | |
git add * | |
git commit -m "import $(basename "$t")" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment