当前位置: > > > > Hugo 不使用本地 git 配置
Hugo 不使用本地 git 配置
来源:stackoverflow
2024-04-24 14:36:39
0浏览
收藏
偷偷努力,悄无声息地变强,然后惊艳所有人!哈哈,小伙伴们又来学习啦~今天我将给大家介绍《Hugo 不使用本地 git 配置》,这篇文章主要会讲到等等知识点,不知道大家对其都有多少了解,下面我们就一起来看一吧!当然,非常希望大家能多多评论,给出合理的建议,我们一起学习,一起进步!
问题内容
我正在尝试使用带有个人访问令牌的私有主题/模块。我可以通过将以下内容添加到我的全局 git config 中来实现此功能。
git config --global url."https://{user}:{token}@github.com".而不是"https://github.com"
然后运行 hugo mod get -u 它将按预期提取更改。 我不希望在全局配置中设置此设置,如果我在本地设置它,则会收到错误,因为 go 似乎没有使用本地配置。
在站点/存储库的根目录中本地设置我的配置:
git config --local url."https://{user}:{token}@github.com".而不是"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 配置而不是全局配置?
正确答案
我通过向站点配置添加目录替换映射来解决这个问题,而不是修改 git url。这指向我本地克隆的主题,并在我修改主题时更新所提供的站点。
module:
imports:
path: 'github.com/[user]/[repo-name]'
replacements: 'github.com/[user]/[repo-name] -> ../../[repo-name]/'
从 开始,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 存储库/子模块的 .git 文件夹,这将忽略您的初始 git config --local 命令
似乎表明 go mod 不会考虑本地存储库:
仅引用全局配置.gitconfig。
好了,本文到此结束,带大家了解了《Hugo 不使用本地 git 配置》,希望本文对你有所帮助!关注米云公众号,给大家分享更多Golang知识!
