Hugo 没有使用本地 git 配置
Hugo not using local git config
我正在尝试使用带有个人访问令牌的私有 theme/module。我可以通过将以下内容添加到我的全局 git config
.
git config --global url."https://{USER}:{TOKEN}@github.com".insteadOf "https://github.com"
然后 运行 hugo mod get -u
它将按预期提取更改。
我不想在我的全局配置中设置这个,如果我在本地设置它,我会得到一个错误,因为 Go 似乎没有使用本地配置。
在 site/repository:
的根目录中本地设置我的配置
git config --local url."https://{USER}:{TOKEN}@github.com".insteadOf "https://github.com"
然后 运行 hugo mod get -u
我得到以下错误:
go get: module github.com/USER/REPOSITORY: git ls-remote -q origin in /var/folders/26/gqnv01_55p964v8yz39d51fw0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/cache/vcs/b410fc7b91fbc1121b5f6ec2bb2711c27cd172b4084c213e1430a33cde552597: exit status 128:
remote: Repository not found.
fatal: repository 'https://github.com/USER/REPOSITORY/' not found
如何让 Go/Hugo 使用本地 git 配置而不是全局配置?
从 hugo mod
source code 中,hugo
将在您的项目中查找 go.mod
:
filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
if info.Name() == "go.mod" {
// Found a module.
dir := filepath.Dir(path)
fmt.Println("Update module in", dir)
检查您的 go.mod 在哪里,然后执行(在那个 go.mod
父文件夹中):
git config -l --show-origin --show-scope
这将告诉您您期望的本地配置是否确实存在。
寻找任何表明嵌套 git repository/submodule 的 .git
文件夹,这将忽略您的初始 git config --local
命令
issue like 34513 似乎暗示 go mod
不会考虑本地存储库:
The git configuration only affects operations on the underlying git repo.
The error that you're seeing is coming from before that, when the go
command is attempting to resolve the repo for the requested package path.
official documentation 仅引用全局配置 .gitconfig
。
我通过向站点配置添加目录替换映射来解决这个问题,而不是修改 git url。这指向我在本地克隆的主题,并在我修改主题时更新服务站点。
module:
imports:
path: 'github.com/[USER]/[REPO-NAME]'
replacements: 'github.com/[USER]/[REPO-NAME] -> ../../[REPO-NAME]/'
我正在尝试使用带有个人访问令牌的私有 theme/module。我可以通过将以下内容添加到我的全局 git config
.
git config --global url."https://{USER}:{TOKEN}@github.com".insteadOf "https://github.com"
然后 运行 hugo mod get -u
它将按预期提取更改。
我不想在我的全局配置中设置这个,如果我在本地设置它,我会得到一个错误,因为 Go 似乎没有使用本地配置。
在 site/repository:
的根目录中本地设置我的配置git config --local url."https://{USER}:{TOKEN}@github.com".insteadOf "https://github.com"
然后 运行 hugo mod get -u
我得到以下错误:
go get: module github.com/USER/REPOSITORY: git ls-remote -q origin in /var/folders/26/gqnv01_55p964v8yz39d51fw0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/cache/vcs/b410fc7b91fbc1121b5f6ec2bb2711c27cd172b4084c213e1430a33cde552597: exit status 128:
remote: Repository not found.
fatal: repository 'https://github.com/USER/REPOSITORY/' not found
如何让 Go/Hugo 使用本地 git 配置而不是全局配置?
从 hugo mod
source code 中,hugo
将在您的项目中查找 go.mod
:
filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
if info.Name() == "go.mod" {
// Found a module.
dir := filepath.Dir(path)
fmt.Println("Update module in", dir)
检查您的 go.mod 在哪里,然后执行(在那个 go.mod
父文件夹中):
git config -l --show-origin --show-scope
这将告诉您您期望的本地配置是否确实存在。
寻找任何表明嵌套 git repository/submodule 的 .git
文件夹,这将忽略您的初始 git config --local
命令
issue like 34513 似乎暗示 go mod
不会考虑本地存储库:
The git configuration only affects operations on the underlying git repo.
The error that you're seeing is coming from before that, when the
go
command is attempting to resolve the repo for the requested package path.
official documentation 仅引用全局配置 .gitconfig
。
我通过向站点配置添加目录替换映射来解决这个问题,而不是修改 git url。这指向我在本地克隆的主题,并在我修改主题时更新服务站点。
module:
imports:
path: 'github.com/[USER]/[REPO-NAME]'
replacements: 'github.com/[USER]/[REPO-NAME] -> ../../[REPO-NAME]/'