Auto Publish Git Repos

Today, to both see if it could be done and to make dealing with all my source code easier, I setup a set of git repositories that automatically publish to IPFS when a “git push origin” is run.

First, I setup the file structure to keep things organized.

./publish
./public/
./public/ipfs-auto-repo.git
./public/ipfs-scanner.git
#    et cetera

To initialize the repo being published, I did the following.

git init
cd public/ipfs-auto-repo.git
git init --bare
vim hooks/post-update

This was then entered into post-update:

#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".

#exec git update-server-info

cd ../../
exec ./publish.sh

When you push to the remote, this is what it looks like. In this case, all the files had previously been published because I deleted a repo then pushed to get the output for this part of the post.

Enumerating objects: 80, done.
Counting objects: 100% (80/80), done.
Delta compression using up to 2 threads
Compressing objects: 100% (78/78), done.
Writing objects: 100% (80/80), 42.36 KiB | 1.84 MiB/s, done.
Total 80 (delta 36), reused 0 (delta 0), pack-reused 0
remote: + KEY=git-repos
remote: + cd public
remote: + for DIR in *
remote: + cd ipfs-scanner.git
remote: + git update-server-info

                                    ** snip **

remote: ++ ipfs key list -l --ipns-base b58mh
remote: ++ cut '-d ' -f1
remote: ++ grep git-repos
remote: + ID=/ipns/QmYR2kCv2z2BryEqxgxpGscMaX4PRyjMpPaLrknegHDTSx
remote: ++ ipfs name resolve /ipns/QmYR2kCv2z2BryEqxgxpGscMaX4PRyjMpPaLrknegHDTSx
remote: + OLD_HASH=/ipfs/QmNxd8irfnXK2ecQZsV6LkUMEnBL7kiYLVt98zsbsruQ3H
remote: ++ cut '-d ' -f2
remote: ++ tail -n1
remote: ++ ipfs add -r public
remote:  23 B / ? [----------------------------------------------------------------------------------------------------------=----------------
remote:  23 B / ? [----------------------------------------------------------------------------------------------------------=----------------
remote:  89 B / ? [----------------------------------------=----------------------------------------------------------------------------------
remote:  89 B / ? [----------------------------------------=----------------------------------------------------------------------------------

                                    ** snip **

remote:  284.38 KiB / 284.38 KiB [===========================================================================================================]
remote:  284.38 KiB / 284.38 KiB [===========================================================================================================]
remote:  284.38 KiB / 284.38 KiB [===========================================================================================================]
remote:  284.38 KiB / 284.38 KiB [===========================================================================================================] 100.00%
remote: + NEW_HASH=/ipfs/QmNxd8irfnXK2ecQZsV6LkUMEnBL7kiYLVt98zsbsruQ3H
remote: + [[ /ipfs/QmNxd8irfnXK2ecQZsV6LkUMEnBL7kiYLVt98zsbsruQ3H != \/\i\p\f\s\/\Q\m\N\x\d\8\i\r\f\n\X\K\2\e\c\Q\Z\s\V\6\L\k\U\M\E\n\B\L\7\k\i\Y\L\V\t\9\8\z\s\b\s\r\u\Q\3\H ]]
To file:///home/teknomunk/www/git-repos/public/ipfs-scanner.git
 * [new branch]      master -> master

The repos used for the above can be found here.

Comments