007-git-coding.txt (2320B) [raw]
1 # 007-git-coding 2 3 _Fri Sept 24, 2021_ 4 5 git(1) is one of my favorite tools. All good tilde's should host it! 6 After all, tilde's are for sharing and what better way to share than 7 publishing your code! 8 9 ## Git Hosting 10 11 Out of the box, git supports hosting for users with accounts via ssh. 12 You can clone like so: 13 14 user@host:path/relative/to/home 15 16 or: 17 18 user@host:/abs/path/on/host 19 20 For anonymous access, git-daemon(1) can be configured to serve over 21 the git:// protocol. On OpenBSD, enable and start it with the path 22 to the directories to serve: 23 24 $ rcctl enable gitdaemon 25 $ rcctl set gitdaemon flags "--base-path=/var/git" 26 $ rcctl start gitdaemon 27 28 The last bit of the puzzle is of course the shared git layout! For 29 git-daemon to work, we need all users to put their files under the 30 same dir (/var/git). But, we want to prevent accidental clobbering 31 via stray rm -rf, so we make a directory for each user and chown 32 it to their account so soley they can access it: 33 34 /var/git/alex 35 .../www 36 .../config 37 /var/git/anthony 38 ... 39 40 Then, for easy clone URLs, we ln(1) the dir into the home directory: 41 42 ln -s /var/git/$USER /home/$USER/git 43 44 Now they can clone via $USER@garbash.com:git/REPO 45 46 ## Web Hosting 47 48 git hosting is one thing, but these days everyone likes to show off 49 their code in the browser for onlookers. Enter stagit(1). 50 51 I tried cgit(1), one of the more popular git-frontends, but with httpd(8)'s 52 chroot(8)-ing, it was kind of a pain to get the more advanced features. 53 54 stagit(1) generates static HTML for individual repos, which is a nice 55 balance of flexible and lightweight. 56 57 The hardest part here was that I had to hack stagit(1) and stagit-index(1) 58 to support our two-tiered directory layout (by default it only supports 59 single directory layouts). This turned out to be not _that_ hard. See 60 my [fork](https://git.alexkarle.com/garbash-stagit/) for the specifics. 61 62 These HTML files are then generated on-the-fly at push time via git-hooks, 63 specifically a post-receive hook. 64 65 The whole process requires quite a bit of setup at repo-creation time 66 (assigning ownership, description, clone-url, and the post-receive hook), 67 so I rolled it all into a script globally available to our users: `newrepo`. 68 That too is available via the system [config files](https://git.alexkarle.com/garbash-config/). 69 Give it a look!