我如何在本地使用git命名空间?

Rub*_*ONO 7 git collaboration version-control namespaces gitlab

我有一个有趣的用例,我希望通过GitLab共享存储库- 但是我们公司的每个用户的回购数量有限,所以我必须通过隐私来配置这些(即代替项目1的回购1,我有团队1的项目1和2→回购1,团队2的项目3和4→回购2).

起初,我打算在分支名称创建伪命名空间,例如project1-branch1,project2-branch1,project2-branch2-但是我后来了解到,git的包括名称空间是应该区分不同的命名空间的参考,同时共享一个对象存储功能.我试图通过承诺不同的分支,以不同的命名空间本地测试这一点,但是我仍然看到任何所有分支(或没有!)命名空间:

$ git init .
Initialized empty Git repository in ~/tmp/test/.git/

$ git --namespace test1 checkout --orphan test1
Switched to a new branch 'test1'

$ touch test1

$ git --namespace test1 add -- test1

$ git --namespace test1 commit -m test1
[test1 (root-commit) 27f9d70] test1
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test1

$ git --namespace test2 checkout --orphan test2
Switched to a new branch 'test2'

$ touch test2

$ git --namespace test2 add -- test2

$ git --namespace test2 commit -m test2
[test2 (root-commit) 4f0f7c5] test2
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test1
 create mode 100644 test2

$ git log --graph
* commit 4f0f7c555d3c607d97829263a30170cc431c1d01
  Author: RubyTuesdayDONO
  Date:   Thu Jul 3 16:06:39 2014 -0500
      test2

$ git log --all --graph
* commit 4f0f7c555d3c607d97829263a30170cc431c1d01
  Author: RubyTuesdayDONO
  Date:   Thu Jul 3 16:06:39 2014 -0500
      test2

* commit 27f9d703758ae401eb77e7e15d75ac863f296291
  Author: RubyTuesdayDONO
  Date:   Thu Jul 3 16:06:17 2014 -0500
      test1

$ git --namespace test1 log --all --graph
* commit 4f0f7c555d3c607d97829263a30170cc431c1d01
  Author: RubyTuesdayDONO
  Date:   Thu Jul 3 16:06:39 2014 -0500
      test2

* commit 27f9d703758ae401eb77e7e15d75ac863f296291
  Author: RubyTuesdayDONO
  Date:   Thu Jul 3 16:06:17 2014 -0500
      test1

$ git --namespace test2 log --all --graph
* commit 4f0f7c555d3c607d97829263a30170cc431c1d01
  Author: RubyTuesdayDONO
  Date:   Thu Jul 3 16:06:39 2014 -0500

      test2

* commit 27f9d703758ae401eb77e7e15d75ac863f296291
  Author: RubyTuesdayDONO
  Date:   Thu Jul 3 16:06:17 2014 -0500
      test1

# separate namespace should prevent conflict (but doesn't)
$ git --namespace test3 checkout --orphan test1 
fatal: A branch named 'test1' already exists.

# should include refs/namespaces (but doesn't)
$ tree -a
.
??? .git
?   ??? COMMIT_EDITMSG
?   ??? config
?   ??? description
?   ??? HEAD
?   ??? hooks
?   ??? index
?   ??? info
?   ?   ??? exclude
?   ??? logs
?   ?   ??? HEAD
?   ?   ??? refs
?   ?       ??? heads
?   ?           ??? test1
?   ?           ??? test2
?   ??? objects
?   ?   ??? 18
?   ?   ?   ??? c152442134ca652c83b111b6063c9b75f9157c
?   ?   ??? 27
?   ?   ?   ??? f9d703758ae401eb77e7e15d75ac863f296291
?   ?   ??? 4f
?   ?   ?   ??? 0f7c555d3c607d97829263a30170cc431c1d01
?   ?   ??? e0
?   ?   ?   ??? f402da78bd414bdd926713d2b54c246432adc5
?   ?   ??? e6
?   ?   ?   ??? 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
?   ?   ??? info
?   ?   ??? pack
?   ??? refs
?       ??? heads
?       ?   ??? test1
?       ?   ??? test2
?       ??? tags
??? test1
??? test2

17 directories, 27 files
Run Code Online (Sandbox Code Playgroud)

在推送到远程仓库之前,是否无法在本地查看命名空间?或者如果它与git-remote-ext magick 本地工作git clone ext::'git --namespace=foo %s /tmp/prefixed.git',那为什么不简单地用git --namespace ordinary-git-command

如果我误解了git命名空间的用途,请提前抱歉 - 我只是想确保在与同事共享之前这会有用,否则我只会使用分支名称作为一种伪命名空间(不太优雅) ,但它会工作).我已经审查了以下帖子,但没有真正理解git名称空间如何运作:

Mix*_*gic 5

Git 命名空间仅适用于远程存储库,不适用于本地存储库 ( https://github.com/git/git/commit/6b01ecfe22f0b6ccb9665cd8d85d78a381fecffc )。大多数使用 git 命名空间的操作似乎都适用于通过 git-upload-pack 和 git-receive-pack 函数的操作。这就是为什么文档建议您是否想在本地测试它以假装它认为您是从远程计算机拉取的,例如:git clone ext::'git --namespace=foo %s /tmp/prefixed.git'

所以命令就像

git --namespace foo add
git --namespace foo commit
git --namespace foo branch
Run Code Online (Sandbox Code Playgroud)

一切基本上什么都不做。唯一有效的操作是克隆/获取/拉取和推送。

为了按照您希望的方式利用名称空间,您必须设置自己的 git 后端,该后端能够将 URL 参数转换为 GIT_NAMESPACE 变量并将其传递给 git-http-backend 或类似的东西。该文档建议您在 apache 配置中进行以下配置:

要在单个存储库中提供来自不同git 命名空间的多个存储库:

SetEnvIf Request_URI "^/git/([^/]*)" GIT_NAMESPACE=$1
ScriptAliasMatch ^/git/[^/]*(.*) /usr/libexec/git-core/git-http-backend/storage.git$1
Run Code Online (Sandbox Code Playgroud)

另请注意,本文档没有说明的是,这里发生的是从 URL 中提取 GIT_NAMESPACE 变量并设置 git-http-backend 期望的环境变量。IE http://myserver.com/git/namespace/repository.git。“storage.git”部分是一个拼写错误,不应该出现在那里。我应该提交一个文档补丁。

以下是创建此功能的大部分提交。 https://github.com/git/git/commits/398dd4bd039680ba98497fbedffa415a43583c16?author=joshtriplett