git 服务器
GitHub 协议和 API 仿真 .
状态
说明
git-server 向 Git 客户端提供本地 Git 寄存器的分级服务 http:// 财务报告和审定财务报表 https:// 协议.
git-server 期望本地 Git 寄存器( 或克隆或创建于 git init在本地文件系统中组织如下:
<repos_root_dir>/
├── <owner_1>/
│ └── <repo_1>
│ └── <repo_2>
├── <owner_2>/
│ └── <repo_1>
│ └── <repo_2>
或者,虚拟寄存器映射允许“挂载”寄存器独立于文件系统中的位置 <owner>/<repo> 等级。 配置示例 :
virtualRepos: {
owner1: {
repo1: {
path: './repo1',
},
},
owner2: {
repo2: {
path: '/repos/repo2',
},
},
},
仓库通过 git-server 可以像GitHub上的任何寄存器一样使用,即你可以克隆它们并把更改推向.
该寄存器内容可以使用您将用来请求在 GitHub 上管理的文件的 URL 模式访问 .
目前支持以下协议和API:
安装
cd <checkout dir>
npm install
开始
git-server 通过 config.js 在当前工作目录中存在的文件。 默认配置如下:
{
appTitle: 'Helix Git Server',
repoRoot: './repos',
// repository mapping. allows to 'mount' repositories outside the 'repoRoot' structure.
virtualRepos: {
demoOwner: {
demoRepo: {
path: './virtual/example',
},
},
},
listen: {
http: {
port: 5000,
host: '0.0.0.0',
},
/*
// https is optional
https: {
// cert: if no file is specfied a selfsigned certificate will be generated on-the-fly
// cert: './localhost.crt',
// key: if no file is specfied a key will be generated on-the-fly
// key: './localhost.key',
port: 5443,
host: '0.0.0.0',
},
*/
},
subdomainMapping: {
// if enabled, <subdomain>.<baseDomain>/foo/bar/baz will be
// resolved/mapped to 127.0.0.1/<subdomain>/foo/bar/baz
enable: true,
baseDomains: [
// some wildcarded DNS domains resolving to 127.0.0.1
'localtest.me',
'lvh.me',
'vcap.me',
'lacolhost.com',
],
},
logs: {
level: 'info', // fatal, error, warn, info, verbose, debug, trace
logsDir: './logs',
reqLogFormat: 'short', // used for morgan (request logging)
},
}
git-server 用途 螺旋标记 用于伐木。 日志级别( O)fatal, (中文(简体) ), error, (中文(简体) ), warn, (中文(简体) ), info, (中文(简体) ), verbose, (中文(简体) ), debug, (中文(简体) ), trace)可以通过 logs.level 属性在配置中(见上文)。 详情请查阅 螺旋标记 项目.
1. 创建本地 Git 仓库
cd ./repos
# create org
mkdir helix && cd helix
# initialize new git repo
mkdir test && cd test && git init
# allow to remotely push to this repo
git config receive.denyCurrentBranch updateInstead
# add a README.md
echo '# test repo'>README.md
git add . && git commit -m '1st commit'
cd ../../..
2. 启动服务器
npm start
3. 通过 http 获取 Git repo 文件的原始内容
curl http://localhost:5000/raw/helix/test/main/README.md
Git 协议和 APIs
1. Git Raw议定书
服务于 git repo 中的文件内容 .
所请求的文件由 :
{owner}: GitHub 组织或用户{repo}: 仓库名称{ref}: 基特参考- 分支名称(例如).
main(中文(简体) ) - 标记名称( 例如 ).
v1.0(中文(简体) ) - (完整或快手) 表示身份(例如.
7aeff3d(中文(简体) )
- 分支名称(例如).
GitHub 網址 :
https://raw.githubusercontent.com/{owner}/{repo}/{ref}/path/to/filehttps://github.com/{owner}/{repo}/raw/{ref}/path/to/file
当地 git-server URL :
http://localhost:{port}/raw/{owner}/{repo}/{ref}/path/to/filehttp://localhost:{port}/{owner}/{repo}/raw/{ref}/path/to/filehttp://raw.localtest.me:{port}/{owner}/{repo}/{ref}/path/to/file(使用通配符 DNS 域解析到127.0.0.1(中文(简体) )
远程示例 :
https://raw.githubusercontent.com/adobe/git-server/main/README.mdhttps://github.com/adobe/git-server/raw/main/README.md
当地实例:
http://raw.localtest.me:5000/adobe/git-server/main/README.mdhttp://localhost:5000/adobe/git-server/raw/main/README.mdhttp://localhost:5000/raw/adobe/git-server/main/README.md
raw.githubusercontent.com 为某些文件类型(例如JavaScript、CSS、HTML)提供不正确的服务 Content-Type: text/plain 头曰. 第三方解决方案,比如 rawgit.com 解决这一问题. git-server 为有正确内容类型的文件服务.
2. Git HTTP 转让协议
支助 git clone, push, fetch
联合国
git push 支助
本地的回购需要要么是 赤线 还原( r)git clone --bare 或者说 git init --bare)或需要设置以下选项:
git config receive.denyCurrentBranch updateInstead
3. GitHub API v3 (英语)
GitHub 终点 : https://api.github.com/
本地端点 : http://localhost:{port}/api 或例如:. http://api.localtest.me:{port} (使用通配符 DNS 域解析到 127.0.0.1(中文(简体) )
只支持 GitHub API 的一个小子集 :
-
说明: GitHub 执行支持最多1兆字节的文件大小.
-
说明: GitHub 执行支持大小可达100兆字节的blobs.
-
说明: 此方法返回 a
302以下载寄存器的 tarball 或 zipball 存档.git-server还支持非官方的https://codeload.github.com不限制速率且不改变方向的终点:https://codeload.github.com/{owner}/{repo}/[zip|tar.gz]/main
相关问题/讨论: #5 支持代码load.github.com
当地实例:
http://api.localtest.me:5000/repos/adobe/git-server/contents/README.md?ref=mainhttp://api.localtest.me:5000/repos/adobe/project-helix/git/blobs/bf13fe66cbee379db6a3e4ebf0300b8bbc0f01b7http://localhost:5000/api/repos/adobe/git-server/contents/README.md?ref=mainhttp://localhost:5000/api/repos/adobe/project-helix/git/blobs/bf13fe66cbee379db6a3e4ebf0300b8bbc0f01b7
4. 类似 GitHub 的网络服务器
(尚未执行)
终点 : https://github.com/
譬如说.
https://github.com/{owner}/{repo}, (中文(简体) ),
https://github.com/{owner}/{repo}/blob/{branch}/path/to/file