garbash-www

archive of ~alex garbash.com page
git clone git://git.alexkarle.com.com/garbash-www
Log | Files | Refs | README | LICENSE

007-git-coding.md (2378B) [raw]


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