README.md

  1# Soft Serve
  2
  3<p>
  4    <img style="width: 451px" src="https://stuff.charm.sh/soft-serve/soft-serve-header.png?0" alt="A nice rendering of some melting ice cream with the words ā€˜Charm Soft Serve’ next to it"><br>
  5    <a href="https://github.com/charmbracelet/soft-serve/releases"><img src="https://img.shields.io/github/release/charmbracelet/soft-serve.svg" alt="Latest Release"></a>
  6    <a href="https://pkg.go.dev/github.com/charmbracelet/soft-serve?tab=doc"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a>
  7    <a href="https://github.com/charmbracelet/soft-serve/actions"><img src="https://github.com/charmbracelet/soft-serve/workflows/build/badge.svg" alt="Build Status"></a>
  8    <a href="https://nightly.link/charmbracelet/soft-serve/workflows/nightly/main"><img src="https://shields.io/badge/-Nightly%20Builds-orange?logo=hackthebox&logoColor=fff&style=appveyor"/></a>
  9</p>
 10
 11A tasty, self-hostable Git server for the command line. šŸ¦
 12
 13<picture>
 14  <source media="(max-width: 750px)" srcset="https://github.com/charmbracelet/soft-serve/assets/42545625/c754c746-dc4c-44a6-9c39-28649264cbf2">
 15  <source media="(min-width: 750px)" width="750" srcset="https://github.com/charmbracelet/soft-serve/assets/42545625/c754c746-dc4c-44a6-9c39-28649264cbf2">
 16  <img src="https://github.com/charmbracelet/soft-serve/assets/42545625/c754c746-dc4c-44a6-9c39-28649264cbf2" alt="Soft Serve screencast">
 17</picture>
 18
 19- Easy to navigate TUI available over SSH
 20- Clone repos over SSH, HTTP, or Git protocol
 21- Git LFS support with both HTTP and SSH backends
 22- Manage repos with SSH
 23- Create repos on demand with SSH or `git push`
 24- Browse repos, files and commits with SSH-accessible UI
 25- Print files over SSH with or without syntax highlighting and line numbers
 26- Easy access control
 27  - SSH authentication using public keys
 28  - Allow/disallow anonymous access
 29  - Add collaborators with SSH public keys
 30  - Repos can be public or private
 31  - User access tokens
 32
 33## Where can I see it?
 34
 35Just run `ssh git.charm.sh` for an example. You can also try some of the following commands:
 36
 37```bash
 38# Jump directly to a repo in the TUI
 39ssh git.charm.sh -t soft-serve
 40
 41# Print out a directory tree for a repo
 42ssh git.charm.sh repo tree soft-serve
 43
 44# Print a specific file
 45ssh git.charm.sh repo blob soft-serve cmd/soft/main.go
 46
 47# Print a file with syntax highlighting and line numbers
 48ssh git.charm.sh repo blob soft-serve cmd/soft/main.go -c -l
 49```
 50
 51Or you can use Soft Serve to browse local repositories using `soft browse
 52[directory]` or running `soft` within a Git repository.
 53
 54## Installation
 55
 56Soft Serve is a single binary called `soft`. You can get it from a package
 57manager:
 58
 59```bash
 60# macOS or Linux
 61brew install charmbracelet/tap/soft-serve
 62
 63# Windows (with Winget)
 64winget install charmbracelet.soft-serve
 65
 66# Arch Linux
 67pacman -S soft-serve
 68
 69# Nix
 70nix-env -iA nixpkgs.soft-serve
 71
 72# Debian/Ubuntu
 73sudo mkdir -p /etc/apt/keyrings
 74curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
 75echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
 76sudo apt update && sudo apt install soft-serve
 77
 78# Fedora/RHEL
 79echo '[charm]
 80name=Charm
 81baseurl=https://repo.charm.sh/yum/
 82enabled=1
 83gpgcheck=1
 84gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo
 85sudo yum install soft-serve
 86```
 87
 88You can also download a binary from the [releases][releases] page. Packages are
 89available in Alpine, Debian, and RPM formats. Binaries are available for Linux,
 90macOS, and Windows.
 91
 92[releases]: https://github.com/charmbracelet/soft-serve/releases
 93
 94Or just install it with `go`:
 95
 96```bash
 97go install github.com/charmbracelet/soft-serve/cmd/soft@latest
 98```
 99
100A [Docker image][docker] is also available.
101
102[docker]: https://github.com/charmbracelet/soft-serve/blob/main/docker.md
103
104## Setting up a server
105
106Make sure `git` is installed, then run `soft serve`. That’s it.
107
108This will create a `data` directory that will store all the repos, ssh keys,
109and database.
110
111By default, program configuration is stored within the `data` directory. But,
112this can be overridden by setting a custom path to a config file with `SOFT_SERVE_CONFIG_LOCATION`
113that is pre-created. If a config file pointed to by `SOFT_SERVE_CONFIG_LOCATION`, 
114the default location within the `data` dir is used for generating a default config.
115
116To change the default data path use `SOFT_SERVE_DATA_PATH` environment variable.
117
118```sh
119SOFT_SERVE_DATA_PATH=/var/lib/soft-serve soft serve
120```
121
122When you run Soft Serve for the first time, make sure you have the
123`SOFT_SERVE_INITIAL_ADMIN_KEYS` environment variable is set to your ssh
124authorized key. Any added key to this variable will be treated as admin with
125full privileges.
126
127Using this environment variable, Soft Serve will create a new `admin` user that
128has full privileges. You can rename and change the user settings later.
129
130Check out [Systemd][systemd] on how to run Soft Serve as a service using
131Systemd. Soft Serve packages in our Apt/Yum repositories come with Systemd
132service units.
133
134[systemd]: https://github.com/charmbracelet/soft-serve/blob/main/systemd.md
135
136### Server Configuration
137
138Once you start the server for the first time, the settings will be in
139`config.yaml` under your data directory. The default `config.yaml` is
140self-explanatory and will look like this:
141
142```yaml
143# Soft Serve Server configurations
144
145# The name of the server.
146# This is the name that will be displayed in the UI.
147name: "Soft Serve"
148
149# Log format to use. Valid values are "json", "logfmt", and "text".
150log_format: "text"
151
152# The SSH server configuration.
153ssh:
154  # The address on which the SSH server will listen.
155  listen_addr: ":23231"
156
157  # The public URL of the SSH server.
158  # This is the address that will be used to clone repositories.
159  public_url: "ssh://localhost:23231"
160
161  # The cross-origin request security options
162  cors:
163    # The allowed cross-origin headers
164    allowed_headers:
165      - Accept
166      - Accept-Language
167      - Content-Language
168      - Origin
169    #  - Content-Type
170    #  - X-Requested-With
171    #  - User-Agent
172    #  - Authorization
173    #  - Access-Control-Request-Method
174
175    # The allowed cross-origin URLs
176    # allowed_origins:
177    #    - *
178
179    # The allowed cross-origin methods
180    allowed_methods:
181       - GET
182       - HEAD
183       - POST
184    #   - PUT
185    #   - OPTIONS
186
187  # The path to the SSH server's private key.
188  key_path: "ssh/soft_serve_host"
189
190  # The path to the SSH server's client private key.
191  # This key will be used to authenticate the server to make git requests to
192  # ssh remotes.
193  client_key_path: "ssh/soft_serve_client"
194
195  # The maximum number of seconds a connection can take.
196  # A value of 0 means no timeout.
197  max_timeout: 0
198
199  # The number of seconds a connection can be idle before it is closed.
200  idle_timeout: 120
201
202# The Git daemon configuration.
203git:
204  # The address on which the Git daemon will listen.
205  listen_addr: ":9418"
206
207  # The maximum number of seconds a connection can take.
208  # A value of 0 means no timeout.
209  max_timeout: 0
210
211  # The number of seconds a connection can be idle before it is closed.
212  idle_timeout: 3
213
214  # The maximum number of concurrent connections.
215  max_connections: 32
216
217# The HTTP server configuration.
218http:
219  # The address on which the HTTP server will listen.
220  listen_addr: ":23232"
221
222  # The path to the TLS private key.
223  tls_key_path: ""
224
225  # The path to the TLS certificate.
226  tls_cert_path: ""
227
228  # The public URL of the HTTP server.
229  # This is the address that will be used to clone repositories.
230  # Make sure to use https:// if you are using TLS.
231  public_url: "http://localhost:23232"
232
233# The database configuration.
234db:
235  # The database driver to use.
236  # Valid values are "sqlite" and "postgres".
237  driver: "sqlite"
238  # The database data source name.
239  # This is driver specific and can be a file path or connection string.
240  # Make sure foreign key support is enabled when using SQLite.
241  data_source: "soft-serve.db?_pragma=busy_timeout(5000)&_pragma=foreign_keys(1)"
242
243# Git LFS configuration.
244lfs:
245  # Enable Git LFS.
246  enabled: true
247  # Enable Git SSH transfer.
248  ssh_enabled: false
249
250# Cron job configuration
251jobs:
252  mirror_pull: "@every 10m"
253
254# The stats server configuration.
255stats:
256  # The address on which the stats server will listen.
257  listen_addr: ":23233"
258# Additional admin keys.
259#initial_admin_keys:
260#  - "ssh-rsa AAAAB3NzaC1yc2..."
261```
262
263You can also use environment variables, to override these settings. All server
264settings environment variables start with `SOFT_SERVE_` followed by the setting
265name all in uppercase. Here are some examples:
266
267- `SOFT_SERVE_NAME`: The name of the server that will appear in the TUI
268- `SOFT_SERVE_SSH_LISTEN_ADDR`: SSH listen address
269- `SOFT_SERVE_SSH_KEY_PATH`: SSH host key-pair path
270- `SOFT_SERVE_HTTP_LISTEN_ADDR`: HTTP listen address
271- `SOFT_SERVE_HTTP_PUBLIC_URL`: HTTP public URL used for cloning
272- `SOFT_SERVE_GIT_MAX_CONNECTIONS`: The number of simultaneous connections to git daemon
273
274#### Database Configuration
275
276Soft Serve supports both SQLite and Postgres for its database. Like all other Soft Serve settings, you can change the database _driver_ and _data source_ using either `config.yaml` or environment variables. The default config uses SQLite as the default database driver.
277
278To use Postgres as your database, first create a Soft Serve database:
279
280```sh
281psql -h<hostname> -p<port> -U<user> -c 'CREATE DATABASE soft_serve'
282```
283
284Then set the database _data source_ to point to your Postgres database. For instance, if you're running Postgres locally, using the default user `postgres` and using a database name `soft_serve`, you would have this config in your config file or environment variable:
285
286```
287db:
288  driver: "postgres"
289  data_source: "postgres://postgres@localhost:5432/soft_serve?sslmode=disable"
290```
291
292Environment variables equivalent:
293
294```sh
295SOFT_SERVE_DB_DRIVER=postgres \
296SOFT_SERVE_DB_DATA_SOURCE="postgres://postgres@localhost:5432/soft_serve?sslmode=disable" \
297soft serve
298```
299
300You can specify a database connection password in the _data source_ url. For example, `postgres://myuser:dbpass@localhost:5432/my_soft_serve_db`.
301
302#### LFS Configuration
303
304Soft Serve supports both Git LFS [HTTP](https://github.com/git-lfs/git-lfs/blob/main/docs/api/README.md) and [SSH](https://github.com/git-lfs/git-lfs/blob/main/docs/proposals/ssh_adapter.md) protocols out of the box, there is no need to do any extra set up.
305
306Use the `lfs` config section to customize your Git LFS server.
307
308> **Note**: The pure-SSH transfer is disabled by default.
309
310## Server Access
311
312Soft Serve at its core manages your server authentication and authorization. Authentication verifies the identity of a user, while authorization determines their access rights to a repository.
313
314To manage the server users, access, and repos, you can use the SSH command line interface.
315
316Try `ssh localhost -i ~/.ssh/id_ed25519 -p 23231 help` for more info. Make sure
317you use your key here.
318
319For ease of use, instead of specifying the key, port, and hostname every time
320you SSH into Soft Serve, add your own Soft Serve instance entry to your SSH
321config. For instance, to use `ssh soft` instead of typing `ssh localhost -i
322~/.ssh/id_ed25519 -p 23231`, we can define a `soft` entry in our SSH config
323file `~/.ssh/config`.
324
325```conf
326Host soft
327  HostName localhost
328  Port 23231
329  IdentityFile ~/.ssh/id_ed25519
330```
331
332Now, we can do `ssh soft` to SSH into Soft Serve. Since `git` is also aware of
333this config, you can use `soft` as the hostname for your clone commands.
334
335```sh
336git clone ssh://soft/dotfiles
337# make changes
338# add & commit
339git push origin main
340```
341
342> **Note** The `-i` part will be omitted in the examples below for brevity. You
343> can add your server settings to your sshconfig for quicker access.
344
345### Authentication
346
347Everything that needs authentication is done using SSH. Make sure you have
348added an entry for your Soft Serve instance in your `~/.ssh/config` file.
349
350By default, Soft Serve gives read-only permission to anonymous connections to
351any of the above protocols. This is controlled by two settings `anon-access`
352and `allow-keyless`.
353
354- `anon-access`: Defines the access level for anonymous users. Available
355  options are `no-access`, `read-only`, `read-write`, and `admin-access`.
356  Default is `read-only`.
357- `allow-keyless`: Whether to allow connections that doesn't use keys to pass.
358  Setting this to `false` would disable access to SSH keyboard-interactive,
359  HTTP, and Git protocol connections. Default is `true`.
360
361```sh
362$ ssh -p 23231 localhost settings
363Manage server settings
364
365Usage:
366  ssh -p 23231 localhost settings [command]
367
368Available Commands:
369  allow-keyless Set or get allow keyless access to repositories
370  anon-access   Set or get the default access level for anonymous users
371
372Flags:
373  -h, --help   help for settings
374
375Use "ssh -p 23231 localhost settings [command] --help" for more information about a command.
376```
377
378> **Note** These settings can only be changed by admins.
379
380When `allow-keyless` is disabled, connections that don't use SSH Public Key
381authentication will get denied. This means cloning repos over HTTP(s) or git://
382will get denied.
383
384Meanwhile, `anon-access` controls the access level granted to connections that
385use SSH Public Key authentication but are not registered users. The default
386setting for this is `read-only`. This will grant anonymous connections that use
387SSH Public Key authentication `read-only` access to public repos.
388
389`anon-access` is also used in combination with `allow-keyless` to determine the
390access level for HTTP(s) and git:// clone requests.
391
392#### SSH
393
394Soft Serve doesn't allow duplicate SSH public keys for users. A public key can be associated with one user only. This makes SSH authentication simple and straight forward, add your public key to your Soft Serve user to be able to access Soft Serve.
395
396#### HTTP
397
398You can generate user access tokens through the SSH command line interface. Access tokens can have an optional expiration date. Use your access token as the basic auth user to access your Soft Serve repos through HTTP.
399
400```sh
401# Create a user token
402ssh -p 23231 localhost token create 'my new token'
403ss_1234abc56789012345678901234de246d798fghi
404
405# Or with an expiry date
406ssh -p 23231 localhost token create --expires-in 1y 'my other token'
407ss_98fghi1234abc56789012345678901234de246d7
408```
409
410Now you can access to repos that require `read-write` access.
411
412```sh
413git clone http://ss_98fghi1234abc56789012345678901234de246d7@localhost:23232/my-private-repo.git my-private-repo
414# Make changes and push
415```
416
417### Authorization
418
419Soft Serve offers a simple access control. There are four access levels,
420no-access, read-only, read-write, and admin-access.
421
422`admin-access` has full control of the server and can make changes to users and repos.
423
424`read-write` access gets full control of repos.
425
426`read-only` can read public repos.
427
428`no-access` denies access to all repos.
429
430## User Management
431
432Admins can manage users and their keys using the `user` command. Once a user is
433created and has access to the server, they can manage their own keys and
434settings.
435
436To create a new user simply use `user create`:
437
438```sh
439# Create a new user
440ssh -p 23231 localhost user create beatrice
441
442# Add user keys
443ssh -p 23231 localhost user add-pubkey beatrice ssh-rsa AAAAB3Nz...
444ssh -p 23231 localhost user add-pubkey beatrice ssh-ed25519 AAAA...
445
446# Create another user with public key
447ssh -p 23231 localhost user create frankie '-k "ssh-ed25519 AAAATzN..."'
448
449# Need help?
450ssh -p 23231 localhost user help
451```
452
453Once a user is created, they get `read-only` access to public repositories.
454They can also create new repositories on the server.
455
456Users can manage their keys using the `pubkey` command:
457
458```sh
459# List user keys
460ssh -p 23231 localhost pubkey list
461
462# Add key
463ssh -p 23231 localhost pubkey add ssh-ed25519 AAAA...
464
465# Wanna change your username?
466ssh -p 23231 localhost set-username yolo
467
468# To display user info
469ssh -p 23231 localhost info
470```
471
472## Repositories
473
474You can manage repositories using the `repo` command.
475
476```sh
477# Run repo help
478$ ssh -p 23231 localhost repo help
479Manage repositories
480
481Usage:
482  ssh -p 23231 localhost repo [command]
483
484Aliases:
485  repo, repos, repository, repositories
486
487Available Commands:
488  blob         Print out the contents of file at path
489  branch       Manage repository branches
490  collab       Manage collaborators
491  create       Create a new repository
492  delete       Delete a repository
493  description  Set or get the description for a repository
494  hide         Hide or unhide a repository
495  import       Import a new repository from remote
496  info         Get information about a repository
497  is-mirror    Whether a repository is a mirror
498  list         List repositories
499  private      Set or get a repository private property
500  project-name Set or get the project name for a repository
501  rename       Rename an existing repository
502  tag          Manage repository tags
503  tree         Print repository tree at path
504
505Flags:
506  -h, --help   help for repo
507
508Use "ssh -p 23231 localhost repo [command] --help" for more information about a command.
509```
510
511To use any of the above `repo` commands, a user must be a collaborator in the repository. More on this below.
512
513### Creating Repositories
514
515To create a repository, first make sure you are a registered user. Use the
516`repo create <repo>` command to create a new repository:
517
518```sh
519# Create a new repository
520ssh -p 23231 localhost repo create icecream
521
522# Create a repo with description
523ssh -p 23231 localhost repo create icecream '-d "This is an Ice Cream description"'
524
525# ... and project name
526ssh -p 23231 localhost repo create icecream '-d "This is an Ice Cream description"' '-n "Ice Cream"'
527
528# I need my repository private!
529ssh -p 23231 localhost repo create icecream -p '-d "This is an Ice Cream description"' '-n "Ice Cream"'
530
531# Help?
532ssh -p 23231 localhost repo create -h
533```
534
535Or you can add your Soft Serve server as a remote to any existing repo, given
536you have write access, and push to remote:
537
538```
539git remote add origin ssh://localhost:23231/icecream
540```
541
542After you’ve added the remote just go ahead and push. If the repo doesn’t exist
543on the server it’ll be created.
544
545```
546git push origin main
547```
548
549### Nested Repositories
550
551Repositories can be nested too:
552
553```sh
554# Create a new nested repository
555ssh -p 23231 localhost repo create charmbracelet/icecream
556
557# Or ...
558git remote add charm ssh://localhost:23231/charmbracelet/icecream
559git push charm main
560```
561
562### Mirrors
563
564You can also *import* repositories from any public remote. Use the `repo import` command.
565
566```sh
567ssh -p 23231 localhost repo import soft-serve https://github.com/charmbracelet/soft-serve
568```
569
570Use `--mirror` or `-m` to mark the repository as a *pull* mirror.
571
572### Deleting Repositories
573
574You can delete repositories using the `repo delete <repo>` command.
575
576```sh
577ssh -p 23231 localhost repo delete icecream
578```
579
580### Renaming Repositories
581
582Use the `repo rename <old> <new>` command to rename existing repositories.
583
584```sh
585ssh -p 23231 localhost repo rename icecream vanilla
586```
587
588### Repository Collaborators
589
590Sometimes you want to restrict write access to certain repositories. This can
591be achieved by adding a collaborator to your repository.
592
593Use the `repo collab <command> <repo>` command to manage repo collaborators.
594
595```sh
596# Add collaborator to soft-serve
597ssh -p 23231 localhost repo collab add soft-serve frankie
598
599# Add collaborator with a specific access level
600ssh -p 23231 localhost repo collab add soft-serve beatrice read-only
601
602# Remove collaborator
603ssh -p 23231 localhost repo collab remove soft-serve beatrice
604
605# List collaborators
606ssh -p 23231 localhost repo collab list soft-serve
607```
608
609### Repository Metadata
610
611You can also change the repo's description, project name, whether it's private,
612etc using the `repo <command>` command.
613
614```sh
615# Set description for repo
616ssh -p 23231 localhost repo description icecream "This is a new description"
617
618# Hide repo from listing
619ssh -p 23231 localhost repo hidden icecream true
620
621# List repository info (branches, tags, description, etc)
622ssh -p 23231 localhost repo icecream info
623```
624
625To make a repository private, use `repo private <repo> [true|false]`. Private
626repos can only be accessed by admins and collaborators.
627
628```sh
629ssh -p 23231 localhost repo private icecream true
630```
631
632### Repository Branches & Tags
633
634Use `repo branch` and `repo tag` to list, and delete branches or tags. You can
635also use `repo branch default` to set or get the repository default branch.
636
637### Repository Tree
638
639To print a file tree for the project, just use the `repo tree` command along with
640the repo name as the SSH command to your Soft Serve server:
641
642```sh
643ssh -p 23231 localhost repo tree soft-serve
644```
645
646You can also specify the sub-path and a specific reference or branch.
647
648```sh
649ssh -p 23231 localhost repo tree soft-serve server/config
650ssh -p 23231 localhost repo tree soft-serve main server/config
651```
652
653From there, you can print individual files using the `repo blob` command:
654
655```sh
656ssh -p 23231 localhost repo blob soft-serve cmd/soft/main.go
657```
658
659You can add the `-c` flag to enable syntax coloring and `-l` to print line
660numbers:
661
662```sh
663ssh -p 23231 localhost repo blob soft-serve cmd/soft/main.go -c -l
664
665```
666
667Use `--raw` to print raw file contents. This is useful for dumping binary data.
668
669### Repository webhooks
670
671Soft Serve supports repository webhooks using the `repo webhook` command. You
672can create and manage webhooks for different repository events such as _push_,
673_collaborators_, and _branch_tag_create_ events.
674
675```
676Manage repository webhooks
677
678Usage:
679  ssh -p 23231 localhost repo webhook [command]
680
681Aliases:
682  webhook, webhooks
683
684Available Commands:
685  create      Create a repository webhook
686  delete      Delete a repository webhook
687  deliveries  Manage webhook deliveries
688  list        List repository webhooks
689  update      Update a repository webhook
690
691Flags:
692  -h, --help   help for webhook
693```
694
695## The Soft Serve TUI
696
697<img src="https://stuff.charm.sh/soft-serve/soft-serve-demo-commit.png" width="750" alt="TUI example showing a diff">
698
699Soft Serve TUI is mainly used to browse repos over SSH. You can also use it to
700browse local repositories with `soft browse` or running `soft` within a Git
701repository.
702
703```sh
704ssh localhost -p 23231
705```
706
707It's also possible to ā€œlinkā€ to a specific repo:
708
709```sh
710ssh -p 23231 localhost -t soft-serve
711```
712
713You can copy text to your clipboard over SSH. For instance, you can press
714<kbd>c</kbd> on the highlighted repo in the menu to copy the clone command
715[^osc52].
716
717[^osc52]:
718    Copying over SSH depends on your terminal support of OSC52. Refer to
719    [go-osc52](https://github.com/aymanbagabas/go-osc52) for more information.
720
721## Hooks
722
723Soft Serve supports git server-side hooks `pre-receive`, `update`,
724`post-update`, and `post-receive`. This means you can define your own hooks to
725run on repository push events. Hooks can be defined as a per-repository hook,
726and/or global hooks that run for all repositories.
727
728You can find per-repository hooks under the repository `hooks` directory.
729
730Globs hooks can be found in your `SOFT_SERVE_DATA_PATH` directory under
731`hooks`. Defining global hooks is useful if you want to run CI/CD for example.
732
733Here's an example of sending a message after receiving a push event. Create an
734executable file `<data path>/hooks/update`:
735
736```sh
737#!/bin/sh
738#
739# An example hook script to echo information about the push
740# and send it to the client.
741
742refname="$1"
743oldrev="$2"
744newrev="$3"
745
746# Safety check
747if [ -z "$GIT_DIR" ]; then
748        echo "Don't run this script from the command line." >&2
749        echo " (if you want, you could supply GIT_DIR then run" >&2
750        echo "  $0 <ref> <oldrev> <newrev>)" >&2
751        exit 1
752fi
753
754if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
755        echo "usage: $0 <ref> <oldrev> <newrev>" >&2
756        exit 1
757fi
758
759# Check types
760# if $newrev is 0000...0000, it's a commit to delete a ref.
761zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
762if [ "$newrev" = "$zero" ]; then
763        newrev_type=delete
764else
765        newrev_type=$(git cat-file -t $newrev)
766fi
767
768echo "Hi from Soft Serve update hook!"
769echo
770echo "RefName: $refname"
771echo "Change Type: $newrev_type"
772echo "Old SHA1: $oldrev"
773echo "New SHA1: $newrev"
774
775exit 0
776```
777
778Now, you should get a message after pushing changes to any repository.
779
780## A note about RSA keys
781
782Unfortunately, due to a shortcoming in Go’s `x/crypto/ssh` package, Soft Serve
783does not currently support access via new SSH RSA keys: only the old SHA-1
784ones will work.
785
786Until we sort this out you’ll either need an SHA-1 RSA key or a key with
787another algorithm, e.g. Ed25519. Not sure what type of keys you have?
788You can check with the following:
789
790```sh
791$ find ~/.ssh/id_*.pub -exec ssh-keygen -l -f {} \;
792```
793
794If you’re curious about the inner workings of this problem have a look at:
795
796- https://github.com/golang/go/issues/37278
797- https://go-review.googlesource.com/c/crypto/+/220037
798- https://github.com/golang/crypto/pull/197
799
800## Feedback
801
802We’d love to hear your thoughts on this project. Feel free to drop us a note!
803
804- [Twitter](https://twitter.com/charmcli)
805- [The Fediverse](https://mastodon.social/@charmcli)
806- [Discord](https://charm.sh/chat)
807
808## License
809
810[MIT](https://github.com/charmbracelet/soft-serve/raw/main/LICENSE)
811
812---
813
814Part of [Charm](https://charm.sh).
815
816<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a>
817
818Charmēƒ­ēˆ±å¼€ęŗ • Charm loves open source