The git charm deploys and controls a git-over-ssh server.

The git charm deploys a server with git set up to serve over ssh.
In addition to that, the charm exposes actions that make handling the
management of users and repositories easy.

The charms uses and depends on actions, a feature not yet present in juju-core 1.22.
To use it, download and build the juju-core 1.23 or later branch (https://github.com/juju/juju/tree/1.23).

Deploying the charm is as easy as:
juju deploy cs:~tasdomas/trusty/git

Getting the list of defined actions:

$ juju action defined git
juju action defined git
add-repo: Create a git repository.
add-repo-user: Give a user permissions to access a repository.
add-user: Create a new user.
get-repo: Return the repository's path.
list-repo-users: List all users who have access to a repository.
list-repos: List existing git repositories.
list-user-repos: List all the repositories a user has access to.
list-users: List all users.
remove-repo: Remove a git repository.
remove-repo-user: Revoke a user's permissions to access a repository.
remove-user: Remove a user.

Configuration values

The charm exposes a single configuration value - the repository directory:

$ juju get git
juju get git
charm: git
service: git
settings:
  repository_dir:
    default: true
    description: Directory for storing git repositories.
    type: string
    value: /var/git/`

Repository management

Creating a repository

The add-repo action creates a repository with the specified name.

$ juju action do git/0 add-repo repo=myproject
juju action do git/0 add-repo repo=myproject
Action queued with id: 09b9916a-dc25-4113-8233-cc16f6ad11a4
$ juju action fetch 09b9916a-dc25-4113-8233-cc16f6ad11a4
juju action fetch 09b9916a-dc25-4113-8233-cc16f6ad11a4
results:
  dir: /var/git/myproject.git
status: completed
timing:
  completed: 2015-07-10 10:28:11 -0600 MDT
  enqueued: 2015-07-10 10:28:06 -0600 MDT
  started: 2015-07-10 10:28:09 -0600 MDT

The action results will indicate the location of the repository on the server.

Removing a repository

To remove a repository, use the remove-repo command.

$ juju action do git/0 remove-repo repo=myproject sure=yes
juju action do git/0 remove-repo repo=myproject
Action queued with id: f5b3cb3f-8386-49e7-813b-407347094248
$ juju action fetch f5b3cb3f-8386-49e7-813b-407347094248
juju action fetch f5b3cb3f-8386-49e7-813b-407347094248
status: completed
timing:
  completed: 2015-07-10 10:39:36 -0600 MDT
  enqueued: 2015-07-10 10:39:29 -0600 MDT
  started: 2015-07-10 10:39:34 -0600 MDT

Since this is an irreversible operation, an additional parameter (sure) is required.

Listing all available repositories

To list all repositories handled by the charm, use the list-repos command.

$ juju action do git/0 list-repos
juju action do git/0 list-repos
Action queued with id: 6cc783f2-5d68-4850-89e8-fe5d5c79e174
$ juju action fetch 6cc783f2-5d68-4850-89e8-fe5d5c79e174
juju action fetch 6cc783f2-5d68-4850-89e8-fe5d5c79e174
results:
  myproject: /var/git/myproject.git
  mysecretproject: /var/git/mysecretproject.git
status: completed
timing:
  completed: 2015-07-10 10:48:46 -0600 MDT
  enqueued: 2015-07-10 10:48:40 -0600 MDT
  started: 2015-07-10 10:48:44 -0600 MDT

The actions's output with show a list of git repositories and their paths.

Getting information for a repository

To get the information for a single repository, use the get-repo action:

$ juju action do git/0 get-repo repo=myproject
juju action do git/0 get-repo repo=myproject
Action queued with id: 7cb488c6-6e9b-4de8-8488-3c854364231d
$ juju action fetch 7cb488c6-6e9b-4de8-8488-3c854364231d
juju action fetch 7cb488c6-6e9b-4de8-8488-3c854364231d
results:
  myproject: /var/git/myproject.git
status: completed
timing:
  completed: 2015-07-10 10:53:11 -0600 MDT
  enqueued: 2015-07-10 10:53:05 -0600 MDT
  started: 2015-07-10 10:53:09 -0600 MDT

Managing users

Adding users

The add-user command creates a user.

$ juju action do git/0 add-user user=me key="`cat ~/.ssh/id_rsa.pub`"
juju action do git/0 add-user user=me key="`cat ~/.ssh/id_rsa.pub`"
Action queued with id: ff361e1d-0957-4c29-832b-bcfefe8a1751
$ juju action fetch ff361e1d-0957-4c29-832b-bcfefe8a1751
juju action fetch ff361e1d-0957-4c29-832b-bcfefe8a1751
status: completed
timing:
  completed: 2015-07-10 10:31:06 -0600 MDT
  enqueued: 2015-07-10 10:31:01 -0600 MDT
  started: 2015-07-10 10:31:04 -0600 MDT

Adding a user requires two parameters: the name and the public ssh key. Since actions don't support file parameters,
you will need to pass the key string as the key parameter.

Removing users

To remove a user, user the remove-user action.

$ juju action do git/0 remove-user user=me sure=yes
juju action do git/0 remove-user user=me
Action queued with id: c5f8c740-9659-4714-8b64-8c0921308bab
$ juju action fetch c5f8c740-9659-4714-8b64-8c0921308bab
juju action fetch c5f8c740-9659-4714-8b64-8c0921308bab
status: completed
timing:
  completed: 2015-07-10 10:54:51 -0600 MDT
  enqueued: 2015-07-10 10:54:44 -0600 MDT
  started: 2015-07-10 10:54:49 -0600 MDT

Since this is an irreversible operation, an additional parameter (sure) is required.

Showing all users

To list all users, use the list-users action.

$ juju action do git/0 list-users
juju action do git/0 list-users
Action queued with id: e50ef05a-c012-4a89-82cd-016ca60f7e06
$ juju action fetch e50ef05a-c012-4a89-82cd-016ca60f7e06
juju action fetch e50ef05a-c012-4a89-82cd-016ca60f7e06
results:
  users: me, him
status: completed
timing:
  completed: 2015-07-10 10:59:01 -0600 MDT
  enqueued: 2015-07-10 10:58:57 -0600 MDT
  started: 2015-07-10 10:58:59 -0600 MDT

Managing user repository access

Managing users and repositories is just half of the story. To have a useful git service, we need
to be able to grant users access to a repository.

Granting users access to a repository

To grant a user access to a repository, we use the add-repo-user action and pass it two parameters:
the username and repository name.

$ juju action do git/0 add-repo-user repo=myproject user=me
juju action do git/0 add-repo-user repo=myproject user=me
Action queued with id: c8fb9cdd-df9f-4dbb-8925-973e518be73a
$ juju action fetch c8fb9cdd-df9f-4dbb-8925-973e518be73a
juju action fetch c8fb9cdd-df9f-4dbb-8925-973e518be73a
status: completed
timing:
  completed: 2015-07-10 11:03:06 -0600 MDT
  enqueued: 2015-07-10 11:03:01 -0600 MDT
  started: 2015-07-10 11:03:04 -0600 MDT

Once this is done, the user will be able to access the repository:

$ git remote add upstream me@10.0.3.81:/var/git/myproject.git
git remote add upstream me@10.0.3.81:/var/git/myproject.git
$ git fetch upstream
git fetch upstream
Warning: Permanently added '10.0.3.81' (RSA) to the list of known hosts.

Removing a user's access to a repository

The remove-repo-user action is similar to add-repo-user: it takes two parameters as well, user and repo.

$ juju action do git/0 remove-repo-user user=me repo=myproject
juju action do git/0 remove-repo-user user=me repo=myproject
Action queued with id: 6c8e028c-0a0e-4f24-8317-140507d10e76
$ juju action fetch 6c8e028c-0a0e-4f24-8317-140507d10e76
juju action fetch 6c8e028c-0a0e-4f24-8317-140507d10e76
status: completed
timing:
  completed: 2015-07-10 11:08:11 -0600 MDT
  enqueued: 2015-07-10 11:08:07 -0600 MDT
  started: 2015-07-10 11:08:09 -0600 MDT

This will cause the user to lose access to the repository:

$ git pull upstream
git pull upstream
Warning: Permanently added '10.0.3.81' (RSA) to the list of known hosts.
fatal: '/var/git/myproject.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Listing all users who have access to a repository

The list-repo-users action will return a list of users who have access to a repository.

$ juju action do git/0 list-repo-users repo=myproject
juju action do git/0 list-repo-users repo=myproject
Action queued with id: a97e26f1-5a1a-4174-8cee-d16eada55bf9
$ juju action fetch a97e26f1-5a1a-4174-8cee-d16eada55bf9
juju action fetch a97e26f1-5a1a-4174-8cee-d16eada55bf9
results:
  users: me, him
status: completed
timing:
  completed: 2015-07-10 11:10:57 -0600 MDT
  enqueued: 2015-07-10 11:10:51 -0600 MDT
  started: 2015-07-10 11:10:54 -0600 MDT

Listing all repositories a user has access to

In some cases it may not be sufficient to know which users have access to a repository. So, to
find out which repositories a user has access to, user the list-user-repos action.

$ juju action do git/0 list-user-repos user=me
juju action do git/0 list-user-repos user=me
Action queued with id: ef308404-ac24-4329-8df9-4df3452f6a4c
$ juju action fetch ef308404-ac24-4329-8df9-4df3452f6a4c
juju action fetch ef308404-ac24-4329-8df9-4df3452f6a4c
results:
  me: myproject, mysecretproject
status: completed
timing:
  completed: 2015-07-10 11:13:31 -0600 MDT
  enqueued: 2015-07-10 11:13:24 -0600 MDT
  started: 2015-07-10 11:13:29 -0600 MDT

Configuration

repository_dir
(string)
                            Directory for storing git repositories.
                        
/var/git/