Skip to content

krgn/SuaveGit

Repository files navigation

Suave.Git

Serve git repositories (bare & non-bare) via HTTP from Suave. These routes implement the Smart HTTP Protocol.

The following operations are known to work:

  • git pull
  • git push
  • git clone
  • git ls-remote

Build Status

Platform Status
Windows Build status
Mono/Linux Build status

Example

A short example how this API is used:

let dir = "/home/k/projects"
let name = "myproject"  // the directory containing .git (non-bare) or a bare repository

let createServer () =
  let cts = new CancellationTokenSource()

  let config =
    { defaultConfig with
        cancellationToken = cts.Token
        bindings = [ HttpBinding.create HTTP IPAddress.Loopback 7000us ] }

  // This will create the following routes:
  //
  // - GET  "/myproject/info/refs"
  // - POST "/myproject/git-upload-pack" 
  // - POST "/myproject/git-receive-pack" 
  //
  // If the first parmeter is `None`, the path will be in the root.
  
  Path.Combine(dir,name)
  |> gitServer (Some name) 
  |> startWebServerAsync config 
  |> (fun (_, server) -> Async.Start(server, cts.Token))

  // On very slow machines (AppVeyor) it sometimes takes
  // around 100ms, so we wait a little to make sure the server is up
  Thread.Sleep(150)

  { new IDisposable with
      member self.Dispose() =
        try
          cts.Cancel()
          cts.Dispose()
        with | _ -> () }

use server = createServer()

Once running, you can use the regular commands to add remotes and clone.

git clone http://localhost:7000/myproject myclone

Repository Configuration

If you intend to serve non-bare repositories, make sure you set this option on the repository to ensure git push will also update your currently checked out branch.

git config --local receive.denyCurrentBranch updateInstead

About

Routes for serving git repositories via Suave

Resources

License

Stars

Watchers

Forks

Packages

No packages published