Skip to content

Commit

Permalink
Improve create/list, update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarbonne committed Feb 5, 2024
1 parent 52e7df6 commit c2aa895
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 42 deletions.
58 changes: 21 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# minimal-git-server
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Tag](https://img.shields.io/github/v/tag/mcarbonne/minimal-git-server)](https://github.com/mcarbonne/minimal-git-server/tags)
[![Stars](https://img.shields.io/github/stars/mcarbonne/minimal-git-server.svg)](https://github.com/mcarbonne/minimal-git-server)

Originally inspired by https://github.com/jkarlosb/git-server-docker

This container allows to run a minimal git server with a basic CLI to manage repositories.
It supports multiple accounts.

# Minimal configuration
## Features
- support multiple accounts (config.yml)
- basic CLI to manage repositories (list/create/rename/remove/...)
- easily usable in scripts
- tested on docker and podman

## Minimal configuration

This container requires 3 volumes in order to work:
- `/srv/ssh` to persist generated server keys
Expand All @@ -16,7 +27,7 @@ docker run -v .../ssh:/srv/ssh -v .../git:/srv/git -v .../config.yml:/srv/config
```


# config.yml
## config.yml

```yaml
external_hostname: localhost
Expand All @@ -32,40 +43,13 @@ accounts:
```


# Usage
## Basic Usage
To manage your repositories, simply login to the desired account:
```console
$ ssh ACCOUNT@HOSTNAME -p PORT
Availables commands :
create: [REPO_NAME] create a git repo
exists: [REPO_NAME] if REPO_NAME exists and is a valid git repository, return 0 otherwise 1
list: list all available repositories
remove: [TARGET] remove TARGET directory/repo
rename: [SOURCE TARGET] rename SOURCE to TARGET. Might either be folders of git repos
show: [REPO_NAME] show clone URL

git> list
git> create tests/repo-a
Creating repo tests/repo-a
[ ... ]
Initialized empty Git repository in /srv/git/ACCOUNT/tests/repo-a/
You can now clone it :
git clone ssh://ACCOUNT@HOSTNAME:PORT/srv/git/ACCOUNT/tests/repo-a
git> create tests/repo-b
Creating repo tests/repo-b
[ ... ]
Initialized empty Git repository in /srv/git/ACCOUNT/tests/repo-b/
You can now clone it :
git clone ssh://ACCOUNT@HOSTNAME:PORT/srv/git/ACCOUNT/tests/repo-b
git> create repo-c
Creating repo repo-c
[ ... ]
Initialized empty Git repository in /srv/git/ACCOUNT/repo-c/
You can now clone it :
git clone ssh://ACCOUNT@HOSTNAME:PORT/srv/git/ACCOUNT/repo-c
git> list
repo-c
tests/repo-a
tests/repo-b
git>
![Basic Usage](doc/basic-usage.png)

## How to script ?
You can easily embed any supported command in your scripts:
```console
$ ssh ACCOUNT@HOSTNAME -p PORT create project1/my_repo
```
Have a look at `test.sh` for more examples.
5 changes: 2 additions & 3 deletions conf/git-shell-commands/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ then
exit 1
fi

ok "Creating repo $1"
GIT_REPO="${REPO_ROOT}/$USER/$1"
if [ -d "$GIT_REPO" ]; then
die "Already exists, skipped !"
fi
git init --bare "$GIT_REPO"
git init -q --bare "$GIT_REPO"


ok "You can now clone it :"
echo "You can now clone it :"
ok "git clone ssh://${USER}@$EXTERNAL_HOSTNAME:$EXTERNAL_PORT${GIT_REPO}"
7 changes: 5 additions & 2 deletions conf/git-shell-commands/list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

#HELP list all available repositories

#shellcheck disable=SC1091
# shellcheck disable=SC1091
. /srv/env
# shellcheck source=git-shell-commands-common.sh
. /srv/git-shell-commands-common.sh


for repo in $(find "$REPO_ROOT/$USER" -name "config" | sort)
do
folder=$(dirname "$repo")
repo_name=${folder#"$REPO_ROOT/$USER/"}
echo "$repo_name"
safe_tput setaf 5; echo -en "$repo_name\t"; safe_tput sgr0
echo "ssh://${USER}@$EXTERNAL_HOSTNAME:$EXTERNAL_PORT${folder}"
done
Binary file added doc/basic-usage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c2aa895

Please sign in to comment.