]>
Commit | Line | Data |
---|---|---|
1 | # Scripts for self-hosted git admin | |
2 | ||
3 | Recently I've been using my own git server [1,2] to host my repositories, and for simplicity I decided to go with GitWeb [3]. This also means that I don't get a web management UI, which turns out is a great thing with a few helper scripts. | |
4 | ||
5 | => https://git.unlimited.pizza [1] git @ unlimited.pizza (https) | |
6 | => gemini://gemini.unlimited.pizza/git [2] git @ unlimited.pizza (gemini) | |
7 | => https://git-scm.com/book/en/v2/Git-on-the-Server-GitWeb [3] GitWeb | |
8 | ||
9 | ## repo_name to fetch repository name | |
10 | ||
11 | I want to use the same <username>/<repo> structure across services, and this utility helps me extract it. It fetches the push origin remote, grabs the last two fragments of the URL and then removes any leading tilde (for compatibility with sourcehut). I don't really use this one directly, but all other scripts depend on it. | |
12 | ||
13 | ``` | |
14 | function repo_name { | |
15 | git remote -v | grep origin | grep push | grep -o '[^:/]\+\/[^/]\+\s\+' | grep -o '[^~:]\+\/[^ ]\+' | |
16 | } | |
17 | ``` | |
18 | ||
19 | ## sync_to_conchos creates the repository | |
20 | ||
21 | My upstream is called conchos [4], and this function checks if the origin exists and then pushes everything. The server is setup to create a private repository if it's not found. | |
22 | ||
23 | ``` | |
24 | function sync_to_conchos { | |
25 | if git config remote.conchos.url > /dev/null; then; else | |
26 | git remote add conchos "git@git.unlimited.pizza:$(repo_name)" | |
27 | fi | |
28 | git push conchos --all | |
29 | git push conchos --tags | |
30 | } | |
31 | ||
32 | // eg. | |
33 | % cd ~/projects/web/blog && sync_to_conchos | |
34 | ``` | |
35 | ||
36 | => https://en.wikipedia.org/wiki/Rio_Conchos [4] Rio Conchos | |
37 | ||
38 | ## make_public /make_private control a repo's visibility | |
39 | ||
40 | The git daemon controls public access with a file called `git-daemon-export-ok`, so controlling visibilitiy is as easy as touching or removing a file. If I run these from the root of the project, it controls its visibility. | |
41 | ||
42 | ``` | |
43 | function make_public { | |
44 | ssh git@git.unlimited.pizza -T "touch /srv/git/$(repo_name)/git-daemon-export-ok" | |
45 | } | |
46 | ||
47 | function make_private { | |
48 | ssh git@git.unlimited.pizza -T "rm /srv/git/$(repo_name)/git-daemon-export-ok" | |
49 | } | |
50 | ||
51 | // eg. | |
52 | % cd ~/projects/web/blog && make_public | |
53 | ``` | |
54 | ||
55 | ## describe adds a description for the repo | |
56 | ||
57 | The git daemon uses a file called `description` to show a description on the web. | |
58 | ||
59 | ``` | |
60 | function describe { | |
61 | ssh git@git.unlimited.pizza -T "echo '$1' > /srv/git/$(repo_name)/description" | |
62 | } | |
63 | ||
64 | // eg. | |
65 | % cd ~/projects/web/blog && describe 'An (almost) ephemeral blog #cli' | |
66 | ``` | |
67 | ||
68 | ## That's it! | |
69 | ||
70 | This has made managing my repositories a lot easier as I don't have to fiddle with a web UI at all. If you're also self-hosting git, maybe you'll also find them helpful! |