如何在 github 企业仓库中按分支名称安装仓库?

How do you install a repo by branch name in a github enterprise repo?

我想将 repos 安装到父 repo 并通过分支名称指定。 我尝试了以下方法:

npm install username/repo#branchName --save
npm install username/repo@branchName --save
npm install username/repo#tag --save
npm install username/repo@tag --save

我收到一条错误消息:

Could not install from {theRepoWithBranch} as it does not contain a package.json file.

回购肯定包含一个 package.json 文件。 我想知道这是否是权限问题,因为我使用的是企业 npm 注册表。

npm/npm issue 19788 确实提到:

Currently, npm does not support installation of modules from git services hosted on private domain names.
That includes both Github for Enterprise on custom domains as well as instances of gitlab, gitea, gogs, bitbucket and many others, basically anything hosted on a custom domain name.

附评论:

So, obviously you reference installing via an http(s):// URL directly, but just as an fyi, our GitLab Enterprise instance allows us to install using a slightly different format.
We have 2FA enabled, so it requires SSH to be used.
From the docs.

npm install <git-host>:<git-user>/<repo-name>
npm install <git repo url>

We were able to actually install our repos like this:

npm install git+ssh://git@gitlab.mydomain.com:user/repo.git

所以这更像是一种 URL 格式与许可问题相结合。
关于分支,,你的语法是正确的。

并且:

if I prepend git+ on the HTTPS URL it works (I run gitea which accepts basic auth)

另见 npm/hosted-git-info PR 30