TUTORIAL (8216B)
1 hosting public git repos on tildes 2 ================================== 3 4 You don't actually need the Gitea instance of tildeverse [1] to host your 5 public git repositories. As long as your shell provider allows you to use git 6 serve public web pages via HTTP, you could easily set up a read-only clone URL 7 fetchable using git clone similar to this one: 8 9 $ git clone https://tilde.team/~kst/grm.tilde.git 10 11 We will use tilde.team as an example, but it should work on all tildes/pubnix 12 servers with minor modifications. 13 14 tl;dr 15 ----- 16 17 If you are not interested in the details, I wrote a minimal front end called 18 "git repo manager" [2]. It should take care of all the details for you. 19 20 creating a repo 21 --------------- 22 23 On tilde.team, the structure of ~name/public_html/<path> is mapped to 24 25 https://tilde.team/~name/<path> 26 27 so anything inside the ~name/public_html directory is publicly accessible. If 28 you want to create a publicly accessible git repository, all you need to do is 29 to create a "bare" repository [3] inside ~name/public_html: 30 31 $ cd ~/public_html 32 $ git init --bare my_repo.git 33 Initialized empty Git repository in /home/name/public_html/my_repo.git/ 34 35 The .git suffix is a convention for bare repositories. If you have used GitHub, 36 GitLab, or Gitea before, you should have noticed that the clone URLs all have 37 the .git suffix. 38 39 After you have created the bare repository for your project, the URL 40 41 https://tilde.team/~name/my_repo.git 42 43 is not ready for clone yet. Because we are serving the repository using GET 44 requests, or what git internally called the "dumb" HTTP protocol [4], git needs 45 some extra info files for cloning the repository. They can be generated by 46 47 $ cd ~/public_html/my_repo.git 48 $ git update-server-info 49 50 Now you should be able to clone the repository using 51 52 $ git clone https://tilde.team/~name/my_repo.git 53 Cloning into 'my_repo'... 54 warning: You appear to have cloned an empty repository. 55 56 The 57 58 $ git update-server-info 59 60 command needs to be run after every update to the repository. This could be 61 automated using the post-update git hook [5]. Since the sample post-update hook 62 in 63 64 ~/public_html/my_repo.git/hooks 65 66 already contains this command, we simply rename the sample hook 67 68 $ cd ~/public_html/my_repo.git 69 $ mv hooks/post-update.sample hooks/post-update 70 71 so that git will run this script after every update. 72 73 push via ssh 74 ------------ 75 76 Note that the HTTP clone URL is *read-only*, you can't push anything using this 77 URL. Normally you would need to set up the "smart" protocol [4] for authentica- 78 tion, but since most tildes uses SSH already, we could use a remote path of the 79 form `name@host:path`, similar to the arguments of scp, as the git remote url, 80 so you could use 81 82 $ git clone name@tilde.team:~/public_html/my_repo.git 83 84 to clone the repository on your local machine, or 85 86 $ git clone ~/public_html/my_repo.git 87 88 if you want to work on the server directly. If you have already made some 89 changes to the local repo, use 90 91 $ git remote set-url origin <url> 92 93 to update the remote URL. Now you should be able to push to your remote repo 94 using 95 96 $ git push 97 98 if you have a correct SSH keypair setup. 99 100 web front end 101 ------------ 102 103 Now that we have already figured out the push and clone access of our 104 repository. You could call it an end here, but one of the most important 105 features of git hosting services is a web interface so that people could browse 106 and discuss the source code without cloning it. 107 108 For this, we could use stagit [6], which is a tool for generating static HTML 109 pages from a git repository. The generated web pages are even browsable using 110 terminal browsers such as elinks, w3m, and lynx. For example, try 111 112 $ lynx https://tilde.team/~kst/git/grm.tilde/file/TUTORIAL.html 113 114 If your server have libgit2 installed, simply clone the repo and build it: 115 116 $ git clone git://git.codemadness.org/stagit 117 $ cd stagit 118 $ make 119 $ cp stagit stagit-index ~/bin/ 120 121 If not, ask the admin to install it, or follow the instruction in stagit 122 README [7] to build a statically-linked binary on your local machine and copy 123 it to the server. 124 125 Here, we will assume that the index page of stagit, which lists all the repos 126 you have, is 127 128 https://tilde.team/~name/git/ 129 130 and the index page of each repository is 131 132 https://tilde.team/~name/git/my_repo 133 134 To build the HTML pages for my_repo, we first make the corresponding directory 135 136 $ mkdir -p ~/public_html/git/my_repo 137 $ cd ~/public_html/git/my_repo 138 139 and add some metadata to your bare git repo 140 141 $ echo 'a cool project' > ~/public_html/my_repo.git/description 142 $ echo 'https://tilde.team/~name/my_repo.git' > ~/public_html/my_repo.git/url 143 $ echo 'name' > ~/public_html/my_repo.git/owner 144 145 then run 146 147 $ stagit ~/public_html/my_repo.git 148 149 to generate HTML files in the current directory. You could link index.html to 150 log.html 151 152 $ ln -sf log.html index.html 153 154 so that the URL 155 156 https://tilde.team/~name/git/my_repo 157 158 is pointed to the commit log page. 159 160 To generate the repository index, go back to 161 162 $ cd ~/public_html/git/ 163 164 and run 165 166 $ stagit-index ~/public_html/my_repo.git > index.html 167 168 Note that the output will be empty if my_repo has no commits. In general, use 169 170 $ stagit-index repo_dir1 repo_dir2 ... > index.html 171 172 to generate index for multiple repositories. You should also copy over or 173 symlink some of the assets files in stagit's repository, such as style.css, 174 logo.png, etc. to 175 176 ~/public_html/git/ 177 178 and 179 180 ~/public_html/git/my_repo/ 181 182 you could also modify the source code of stagit to use a common location for 183 the assets. 184 185 Because the web pages generated by stagit is static, you need to run stagit and 186 stagit-index after each push operation to your repository in order to update 187 the HTML files. This process can be easily automated using a post-receive hook. 188 An example of the post-receive hook can be found at [8]. To install it: 189 190 $ cd ~/public_html/my_repo.git/hooks 191 $ curl -o stagit-post-receive https://tilde.team/~kst/bin/stagit-post-receive 192 $ chmod +x stagit-post-receive 193 194 Now you should see something like this when you do a git push 195 196 $ git push 197 ... 198 remote: [my_repo] stagit HTML pages... done! 199 ... 200 201 a minimal front end for stagit 202 ------------------------------ 203 204 Since the process of creating repositories and recompiling stagit pages can be 205 very tedious, I wrote up a simple front end called git repo manager (grm) to 206 deal with the chore, see the readme [9] if you want to use grm to automate this 207 process. 208 209 If you want to host git repositories on your own server, you could use the git 210 daemon [10] to better manage the visibility of your repositories. The remote 211 address exposed by the git daemon will have git:// prefix. Check out the master 212 branch of grm [11] if you want to use git daemon instead. 213 214 accepting patches 215 ----------------- 216 217 Hosting git repositories this way means there will be no fancy features such as 218 issues and pull requests, but git have built-in support for email workflows [12]. 219 220 Contributors could format their commits to patches using 221 222 $ git format-patch 223 224 and use the 225 226 $ git send-email <patches> 227 228 command [13] to send the patches to you, and you could apply the patches by 229 piping the email message or attached patches to the `git am` command 230 231 $ git am < <patch> 232 233 See the blog post of Drew DeVault [14] for using git with mutt, and check out 234 aerc [15] if you want an modern alternative for mutt built from such workflow. 235 236 [1]: https://tildegit.org/ 237 [2]: https://tilde.team/~kst/git/grm.tilde/file/README.html 238 [3]: https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server 239 [4]: https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols 240 [5]: https://git-scm.com/docs/githooks 241 [6]: https://git.codemadness.org/stagit/ 242 [7]: https://git.codemadness.org/stagit/file/README.html 243 [8]: https://tilde.team/~kst/git/stagit-postrecv/file/stagit-post-receive.html 244 [9]: https://tilde.team/~kst/git/grm.tilde/file/README.html 245 [10]: https://git-scm.com/book/en/v2/Git-on-the-Server-Git-Daemon 246 [11]: https://sink.krj.st/grm/file/README.html 247 [12]: https://git-scm.com/docs/gitworkflows#_patch_workflow 248 [13]: https://git-send-email.io/ 249 [14]: https://drewdevault.com/2019/05/13/Git-email-webcast.html 250 [15]: https://aerc-mail.org/