summaryrefslogtreecommitdiff
path: root/content/cgit.md
blob: a2da04c0c1f5f57974570eaa1331b6c37bddd299 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
---
title: "Cgit"
date: 2021-09-14
short_desc: "A hyperfast web frontend for git repositories."
icon: "cgit.svg"
tags: ["service"]
---

Once you have your server hosting your git repositories, you might want
to allow others to browse your repositories on the web. Cgit is a Free
Software that allows browsing git repositories through the web.

Note that Cgit is a read-only frontend for Git repositories and doesn\'t
have issues, pull requests or user management. If that\'s what you want,
consider installing [Gitea](/gitea) instead.

## Installing cgit and fcgiwrap

### Install fcgiwrap

NGINX doesn\'t have the capability to run CGI scripts by itself, it
depends on an intermediate layer like fcgiwrap to run CGI scripts like
cgit:

```sh
apt install fcgiwrap
```

And now we can install cgit itself with:

```sh
apt install cgit
```

## Setting up NGINX

You should have an NGINX server running with a TLS certificate by now.
Add the following configuration to your server to pass the requests to
Cgit, while serving static files directly:

```nginx
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_certificate /etc/ssl/nginx/{{<hl>}}git.example.org{{</hl>}}.crt;
    ssl_certificate_key /etc/ssl/nginx/{{<hl>}}git.example.org{{</hl>}}.key;
    server_name {{<hl>}}git.example.org{{</hl>}};

    root /usr/share/cgit ;
    try_files $uri @cgit ;

    location ~ /.+/(info/refs|git-upload-pack) {
        include             fastcgi_params;
        fastcgi_param       SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
        fastcgi_param       PATH_INFO           $uri;
        fastcgi_param       GIT_HTTP_EXPORT_ALL 1;
        fastcgi_param       GIT_PROJECT_ROOT    /var/git;
        fastcgi_param       HOME                /var/git;
        fastcgi_pass        unix:/run/fcgiwrap.socket;
    }

    location @cgit {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi;
        fastcgi_param PATH_INFO $uri;
        fastcgi_param QUERY_STRING $args;
        fastcgi_param HTTP_HOST $server_name;
        fastcgi_pass unix:/run/fcgiwrap.socket;
    }
}
```

Then get NGINX to reload your configuration. This configuration also enables
cloning via HTTPS, so make sure to point the `fastcgi_param GIT_PROJECT_ROOT`
to the directory where you store your repositories.

## Configuring cgit

You\'ve got cgit up and running now, but you\'ll probably see it without
any style and without any repository. To change this, we need to
configure Cgit to our liking, by editing `/etc/cgitrc`.

```txt
css=/cgit.css
logo=/cgit.svg
virtual-root=/
clone-prefix=https://{{<hl>}}git.example.org{{</hl>}}

# Title and description shown on top of each page
root-title={{<hl>}}Chad's git server{{</hl>}}
root-desc={{<hl>}}A web interface to SiCh's git repositories, powered by Cgit{{</hl>}}

# The location where git repos are stored on the server
scan-path=/var/git/
```

This configuration assumes you followed the [git hosting guide](/git)
and store your repositories on the `/var/git/` directory.

Cgit\'s configuration allows changing many settings, as documented on
the cgitrc(5) manpage installed with Cgit.

### Changing the displayed repository owner

Cgit\'s main page shows each repo\'s owner, which is \"git\" in case you
followed the git hosting guide, but you might want to change the name to
yours. Cgit shows the owner\'s system name, so you need to modify the
git user to give it your name:

```sh
usermod -c "{{<hl>}}Your Name{{</hl>}}" git
```

### Changing the repository description

Navigate to your bare repository on the server and edit the
`description` file inside it

### Displaying the repository idle time

To do this, we need to create a post-receive hook for each repository
that updates the file cgit uses to determine the idle time. Inside your
repository, create a file `hooks/post-receive` and add the following
contents:

```sh
#!/bin/sh

agefile="$(git rev-parse --git-dir)"/info/web/last-modified

mkdir -p "$(dirname "$agefile")" &&
git for-each-ref \
    --sort=-authordate --count=1 \
    --format='%(authordate:iso8601)' \
    >"$agefile"
```

And give it execution permissions with:

```sh
chmod +x hooks/post-receive
```

Next time you push to that repository, the idle time should reset and
show the correct value.

## Contribution

- Ariel Costas -- [website](https://costas.dev)