git-http-mock-server

raw JSON →
2.0.0 verified Sat Apr 25 auth: no javascript

A lightweight HTTP/SSH mock server for testing Git clone and push operations against test fixture repositories. Version 2.0.0 (June 2020) adds full Git Protocol Version 2 support. Designed specifically for test suites, it uses copy-on-write to prevent persistent changes to repos and supports parallel test execution. Unlike git-http-server, it includes built-in CORS headers for browser tests with isomorphic-git, HTTP Basic Auth for 401 testing, and Git hooks. The SSH variant (git-ssh-mock-server) supports anonymous, password, and public key authentication. Released under MIT license with moderate maintenance activity.

error Error: spawn git-http-backend ENOENT
cause git is not installed or not in PATH.
fix
Install git and ensure it's available in your system PATH.
error Error: listen EADDRINUSE :::8174
cause Port 8174 is already in use by another process.
fix
Set GIT_HTTP_MOCK_SERVER_PORT to a different port, e.g., export GIT_HTTP_MOCK_SERVER_PORT=9000
breaking Version 2.0.0 drops support for git-http-backend npm module, requiring native git installation.
fix Ensure git is installed on the machine and available in PATH.
gotcha SSH server requires the ssh2 npm module, which may have native compilation issues on some platforms.
fix Install build tools if using npm install; consider using pre-built binaries.
gotcha The server writes PID file to current working directory; running 'start' and 'stop' from different directories will not stop the server.
fix Always run start/stop from the same working directory.
npm install git-http-mock-server
yarn add git-http-mock-server
pnpm add git-http-mock-server

Installs and runs the mock server via CLI, demonstrating clone/push operations and daemon mode with environment variables.

// No programmatic API; CLI usage shown below
// Step 1: Install as dev dependency
// npm install --save-dev git-http-mock-server
// Step 2: cd to a directory with bare git repos
// For example: __fixtures__ containing test-repo1.git
// Step 3: Start the HTTP server
// $ git-http-mock-server
// Step 4: In another shell, clone and push
// $ git clone http://localhost:8174/test-repo1.git
// $ git push http://localhost:8174/test-repo1.git main
// For SSH version:
// $ git-ssh-mock-server
// $ git clone ssh://localhost:2222/test-repo1.git
// To run as daemon:
// $ git-http-mock-server start
// $ # do tests
// $ git-http-mock-server stop
// Environment variables:
// GIT_HTTP_MOCK_SERVER_PORT (default 8174)
// GIT_SSH_MOCK_SERVER_PORT (default 2222)
// GIT_HTTP_MOCK_SERVER_ROOT (default cwd)
// GIT_HTTP_MOCK_SERVER_ALLOW_ORIGIN (default *)
// GIT_SSH_MOCK_SERVER_PASSWORD (set for password auth)