我无法通过 HTTPS 克隆 URL 中包含换行符的 Git 存储库:
/tmp/x $ git clone 'https://forge.lindenii.runxiyu.org/lindenii/forge/:/repos/name%0Ahas%0Anewlines/'
Cloning into 'name%0Ahas%0Anewlines'...
warning: url contains a newline in its path component: https://forge.lindenii.runxiyu.org/lindenii/forge/:/repos/name%0Ahas%0Anewlines/
fatal: credential url cannot be parsed: https://forge.lindenii.runxiyu.org/lindenii/forge/:/repos/name%0Ahas%0Anewlines/
fatal: remote helper 'https' aborted session
/tmp/x $ git clone $'https://forge.lindenii.runxiyu.org/lindenii/forge/:/repos/name\nhas\nnewlines/'
Cloning into 'name has newlines'...
warning: url contains a newline in its path component: https://forge.lindenii.runxiyu.org/lindenii/forge/:/repos/name
has
newlines/
fatal: credential url cannot be parsed: https://forge.lindenii.runxiyu.org/lindenii/forge/:/repos/name
has
newlines/
fatal: remote helper 'https' aborted session
但我可以通过 SSH 来完成:
/tmp/x $ git clone $'ssh://forge.lindenii.runxiyu.org/lindenii/forge/:/repos/name\nhas\nnewlines/'
Cloning into 'name has newlines'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
Receiving objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
/tmp/x $ git clone 'ssh://forge.lindenii.runxiyu.org/lindenii/forge/:/repos/name%0Ahas%0Anewlines/'
Cloning into 'name%0Ahas%0Anewlines'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (3/3), done.
我怎样才能让它通过路径包含换行符的 HTTPS 正确克隆?
我认为你不能。
在 credentials.c 中有一个明确的检查。提交消息解释了这一点...
通过 HTTP 或 HTTPS 访问存储库可能需要用户名和密码。为了避免您每次都输入这些内容,Git 将为您存储您的凭据。Git 还为“凭据助手”定义了一个协议,以便 Git 可以使用现有的钥匙串、凭据管理器或机密管理器。
由于凭证协议设计为通用的,因此他们选择保持其简单性并避免使用可能破坏凭证存储的有问题的字符(例如换行符)。
Git 不存储 ssh 凭证,它让ssh-agent来处理这个问题,所以 ssh 中的换行符没有问题。
您必须更改路径或使用 SSH 或设置删除换行符的代理。我建议更改路径,因为路径中的换行符往往会造成严重破坏。