Skip to content

Commit d8615ec

Browse files
committed
Add ConfigGet method and upgrade CI/CD actions
- Add ConfigGet method to read Git configuration values - Add English/Chinese comments - Update dependencies in go.mod/go.sum - Upgrade release.yml actions (checkout@v6, setup-go@v6, golangci-lint@v9, codeql@v4) - Update Go version badge link to go.dev in README - Add ConfigGet unit test with core.repositoryformatversion check
1 parent b17ff66 commit d8615ec

File tree

7 files changed

+115
-76
lines changed

7 files changed

+115
-76
lines changed

.github/workflows/release.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212
name: lint
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v4
16-
- uses: actions/setup-go@v5
15+
- uses: actions/checkout@v6
16+
- uses: actions/setup-go@v6
1717
with:
1818
go-version: stable
1919
cache: true
2020
- name: golangci-lint
21-
uses: golangci/golangci-lint-action@v8
21+
uses: golangci/golangci-lint-action@v9
2222
with:
2323
version: latest
2424
args: --timeout=5m
@@ -29,9 +29,9 @@ jobs:
2929
matrix:
3030
go: [ "1.25.x", "stable" ]
3131
steps:
32-
- uses: actions/checkout@v4
32+
- uses: actions/checkout@v6
3333

34-
- uses: actions/setup-go@v5
34+
- uses: actions/setup-go@v6
3535
with:
3636
go-version: ${{ matrix.go }}
3737
cache: true
@@ -82,18 +82,18 @@ jobs:
8282
security-events: write
8383
steps:
8484
- name: Checkout repository
85-
uses: actions/checkout@v4
85+
uses: actions/checkout@v6
8686

8787
- name: Initialize CodeQL
88-
uses: github/codeql-action/init@v3
88+
uses: github/codeql-action/init@v4
8989
with:
9090
languages: go
9191

9292
- name: Auto Build
93-
uses: github/codeql-action/autobuild@v3
93+
uses: github/codeql-action/autobuild@v4
9494

9595
- name: Perform CodeQL Analysis
96-
uses: github/codeql-action/analyze@v3
96+
uses: github/codeql-action/analyze@v4
9797

9898
# 发布 Release
9999
release:
@@ -105,7 +105,7 @@ jobs:
105105
steps:
106106
# 1. 检出代码
107107
- name: Checkout code
108-
uses: actions/checkout@v4
108+
uses: actions/checkout@v6
109109
with:
110110
fetch-depth: 0 # 获取完整历史用于生成更好的 release notes
111111

README.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/go-xlan/gitgo/release.yml?branch=main&label=BUILD)](https://github.com/go-xlan/gitgo/actions/workflows/release.yml?query=branch%3Amain)
22
[![GoDoc](https://pkg.go.dev/badge/github.com/go-xlan/gitgo)](https://pkg.go.dev/github.com/go-xlan/gitgo)
33
[![Coverage Status](https://img.shields.io/coveralls/github/go-xlan/gitgo/main.svg)](https://coveralls.io/github/go-xlan/gitgo?branch=main)
4-
[![Supported Go Versions](https://img.shields.io/badge/Go-1.25+-lightgrey.svg)](https://github.com/go-xlan/gitgo)
4+
[![Supported Go Versions](https://img.shields.io/badge/Go-1.25%2B-lightgrey.svg)](https://go.dev/)
55
[![GitHub Release](https://img.shields.io/github/release/go-xlan/gitgo.svg)](https://github.com/go-xlan/gitgo/releases)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/go-xlan/gitgo)](https://goreportcard.com/report/github.com/go-xlan/gitgo)
77

@@ -12,9 +12,11 @@ Streamlined Git command execution engine with fluent chaining interface and comp
1212
---
1313

1414
<!-- TEMPLATE (EN) BEGIN: LANGUAGE NAVIGATION -->
15+
1516
## CHINESE README
1617

1718
[中文说明](README.zh.md)
19+
1820
<!-- TEMPLATE (EN) END: LANGUAGE NAVIGATION -->
1921

2022
## Main Features
@@ -199,6 +201,7 @@ func main() {
199201
- `GetCommitHash(ref) (string, error)` - Get commit hash with reference
200202
- `GetRemoteURL(remote) (string, error)` - Get remote repo URL
201203
- `GetIgnoredFiles() ([]string, error)` - Get files ignored in gitignore
204+
- `ConfigGet(key) (string, error)` - Get Git configuration value
202205

203206
### Tag Operations
204207

@@ -210,67 +213,67 @@ func main() {
210213
- `MustDone() *Gcm` - Panic when issues happen
211214

212215
<!-- TEMPLATE (EN) BEGIN: STANDARD PROJECT FOOTER -->
213-
<!-- VERSION 2025-09-06 04:53:24.895249 +0000 UTC -->
216+
<!-- VERSION 2025-11-25 03:52:28.131064 +0000 UTC -->
214217

215218
## 📄 License
216219

217-
MIT License. See [LICENSE](LICENSE).
220+
MIT License - see [LICENSE](LICENSE).
218221

219222
---
220223

221-
## 🤝 Contributing
224+
## 💬 Contact & Feedback
222225

223226
Contributions are welcome! Report bugs, suggest features, and contribute code:
224227

225-
- 🐛 **Found a bug?** Open an issue on GitHub with reproduction steps
226-
- 💡 **Have a feature idea?** Create an issue to discuss the concept
227-
- 📖 **Documentation confusing?** Report it and we can enhance
228-
- 🚀 **Need new features?** Share the use cases to help us understand needs
228+
- 🐛 **Mistake reports?** Open an issue on GitHub with reproduction steps
229+
- 💡 **Fresh ideas?** Create an issue to discuss
230+
- 📖 **Documentation confusing?** Report it so we can improve
231+
- 🚀 **Need new features?** Share the use cases to help us understand requirements
229232
-**Performance issue?** Help us optimize through reporting slow operations
230233
- 🔧 **Configuration problem?** Ask questions about complex setups
231234
- 📢 **Follow project progress?** Watch the repo to get new releases and features
232-
- 🌟 **Success stories?** Share how this package helped the workflow
233-
- 💬 **Feedback?** We welcome input and comments
235+
- 🌟 **Success stories?** Share how this package improved the workflow
236+
- 💬 **Feedback?** We welcome suggestions and comments
234237

235238
---
236239

237240
## 🔧 Development
238241

239-
When contributing new code, follow this process:
242+
New code contributions, follow this process:
240243

241-
1. **Fork**: Fork the repo on GitHub (using the webpage UI)
242-
2. **Clone**: Clone the forked project (`git clone https://github.com/yourname/repo-name.git`)
244+
1. **Fork**: Fork the repo on GitHub (using the webpage UI).
245+
2. **Clone**: Clone the forked project (`git clone https://github.com/yourname/repo-name.git`).
243246
3. **Navigate**: Navigate to the cloned project (`cd repo-name`)
244-
4. **Branch**: Create a feature branch (`git checkout -b feature/xxx`)
247+
4. **Branch**: Create a feature branch (`git checkout -b feature/xxx`).
245248
5. **Code**: Implement the changes with comprehensive tests
246-
6. **Testing**: (Golang project) Make sure tests pass (`go test ./...`) and follow Go code conventions
247-
7. **Documentation**: Update documentation to support changes and write commit messages with substance
249+
6. **Testing**: (Golang project) Ensure tests pass (`go test ./...`) and follow Go code style conventions
250+
7. **Documentation**: Update documentation to support client-facing changes
248251
8. **Stage**: Stage changes (`git add .`)
249-
9. **Commit**: Commit changes (`git commit -m "Add feature xxx"`) with backward compatible code
250-
10. **Push**: Push to the branch (`git push origin feature/xxx`)
251-
11. **PR**: Open a PR on GitHub (on the GitHub webpage) with detailed description
252+
9. **Commit**: Commit changes (`git commit -m "Add feature xxx"`) ensuring backward compatible code
253+
10. **Push**: Push to the branch (`git push origin feature/xxx`).
254+
11. **PR**: Open a merge request on GitHub (on the GitHub webpage) with detailed description.
252255

253-
Make sure tests pass and include documentation updates as needed.
256+
Please ensure tests pass and include relevant documentation updates.
254257

255258
---
256259

257260
## 🌟 Support
258261

259-
Welcome to contribute to this project through submitting PRs and reporting issues.
262+
Welcome to contribute to this project via submitting merge requests and reporting issues.
260263

261264
**Project Support:**
262265

263-
-**Give GitHub stars** when this project helps you
266+
-**Give GitHub stars** if this project helps you
264267
- 🤝 **Share with teammates** and (golang) programming friends
265268
- 📝 **Write tech blogs** about development tools and workflows - we provide content writing support
266269
- 🌟 **Join the ecosystem** - committed to supporting open source and the (golang) development scene
267270

268-
**Have Fun Coding with this package!** 🎉
271+
**Have Fun Coding with this package!** 🎉🎉🎉
269272

270273
<!-- TEMPLATE (EN) END: STANDARD PROJECT FOOTER -->
271274

272275
---
273276

274277
## GitHub Stars
275278

276-
[![Stargazers](https://starchart.cc/go-xlan/gitgo.svg?variant=adaptive)](https://starchart.cc/go-xlan/gitgo)
279+
[![Stargazers](https://starchart.cc/go-xlan/gitgo.svg?variant=adaptive)](https://starchart.cc/go-xlan/gitgo)

README.zh.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/go-xlan/gitgo/release.yml?branch=main&label=BUILD)](https://github.com/go-xlan/gitgo/actions/workflows/release.yml?query=branch%3Amain)
22
[![GoDoc](https://pkg.go.dev/badge/github.com/go-xlan/gitgo)](https://pkg.go.dev/github.com/go-xlan/gitgo)
33
[![Coverage Status](https://img.shields.io/coveralls/github/go-xlan/gitgo/main.svg)](https://coveralls.io/github/go-xlan/gitgo?branch=main)
4-
[![Supported Go Versions](https://img.shields.io/badge/Go-1.25+-lightgrey.svg)](https://github.com/go-xlan/gitgo)
4+
[![Supported Go Versions](https://img.shields.io/badge/Go-1.25%2B-lightgrey.svg)](https://go.dev/)
55
[![GitHub Release](https://img.shields.io/github/release/go-xlan/gitgo.svg)](https://github.com/go-xlan/gitgo/releases)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/go-xlan/gitgo)](https://goreportcard.com/report/github.com/go-xlan/gitgo)
77

@@ -12,9 +12,11 @@
1212
---
1313

1414
<!-- TEMPLATE (ZH) BEGIN: LANGUAGE NAVIGATION -->
15+
1516
## 英文文档
1617

1718
[ENGLISH README](README.md)
19+
1820
<!-- TEMPLATE (ZH) END: LANGUAGE NAVIGATION -->
1921

2022
## 核心特性
@@ -199,6 +201,7 @@ func main() {
199201
- `GetCommitHash(ref) (string, error)` - 使用引用获取提交哈希
200202
- `GetRemoteURL(remote) (string, error)` - 获取远程仓库 URL
201203
- `GetIgnoredFiles() ([]string, error)` - 获取 gitignore 忽略的文件
204+
- `ConfigGet(key) (string, error)` - 获取 Git 配置值
202205

203206
### 标签操作
204207

@@ -210,23 +213,23 @@ func main() {
210213
- `MustDone() *Gcm` - 当问题发生时触发 panic
211214

212215
<!-- TEMPLATE (ZH) BEGIN: STANDARD PROJECT FOOTER -->
213-
<!-- VERSION 2025-09-06 04:53:24.895249 +0000 UTC -->
216+
<!-- VERSION 2025-11-25 03:52:28.131064 +0000 UTC -->
214217

215218
## 📄 许可证类型
216219

217-
MIT 许可证详见 [LICENSE](LICENSE)
220+
MIT 许可证 - 详见 [LICENSE](LICENSE)
218221

219222
---
220223

221-
## 🤝 项目贡献
224+
## 💬 联系与反馈
222225

223226
非常欢迎贡献代码!报告 BUG、建议功能、贡献代码:
224227

225-
- 🐛 **发现问题** 在 GitHub 上提交问题并附上重现步骤
226-
- 💡 **功能建议** 创建 issue 讨论您的想法
227-
- 📖 **文档疑惑?** 报告问题,帮助我们改进文档
228+
- 🐛 **问题报告** 在 GitHub 上提交问题并附上重现步骤
229+
- 💡 **新颖思路** 创建 issue 讨论
230+
- 📖 **文档疑惑?** 报告问题,帮助我们完善文档
228231
- 🚀 **需要功能?** 分享使用场景,帮助理解需求
229-
-**性能瓶颈?** 报告慢操作,帮助我们优化性能
232+
-**性能瓶颈?** 报告慢操作,协助解决性能问题
230233
- 🔧 **配置困扰?** 询问复杂设置的相关问题
231234
- 📢 **关注进展?** 关注仓库以获取新版本和功能
232235
- 🌟 **成功案例?** 分享这个包如何改善工作流程
@@ -244,19 +247,19 @@ MIT 许可证。详见 [LICENSE](LICENSE)。
244247
4. **分支**:创建功能分支(`git checkout -b feature/xxx`
245248
5. **编码**:实现您的更改并编写全面的测试
246249
6. **测试**:(Golang 项目)确保测试通过(`go test ./...`)并遵循 Go 代码风格约定
247-
7. **文档**为面向用户的更改更新文档,并编写有内容的提交消息
250+
7. **文档**面向用户的更改需要更新文档
248251
8. **暂存**:暂存更改(`git add .`
249252
9. **提交**:提交更改(`git commit -m "Add feature xxx"`)确保向后兼容的代码
250253
10. **推送**:推送到分支(`git push origin feature/xxx`
251-
11. **PR**:在 GitHub 上打开 Pull Request(在 GitHub 网页上)并提供详细描述
254+
11. **PR**:在 GitHub 上打开 Merge Request(在 GitHub 网页上)并提供详细描述
252255

253256
请确保测试通过并包含相关的文档更新。
254257

255258
---
256259

257260
## 🌟 项目支持
258261

259-
非常欢迎通过提交 Pull Request 和报告问题来为此项目做出贡献
262+
非常欢迎通过提交 Merge Request 和报告问题来贡献此项目
260263

261264
**项目支持:**
262265

@@ -265,12 +268,12 @@ MIT 许可证。详见 [LICENSE](LICENSE)。
265268
- 📝 **撰写博客**关于开发工具和工作流程 - 我们提供写作支持
266269
- 🌟 **加入生态** - 致力于支持开源和(golang)开发场景
267270

268-
**使用这个包编程快乐** 🎉
271+
**祝你用这个包编程愉快** 🎉🎉🎉
269272

270273
<!-- TEMPLATE (ZH) END: STANDARD PROJECT FOOTER -->
271274

272275
---
273276

274277
## GitHub 标星点赞
275278

276-
[![Stargazers](https://starchart.cc/go-xlan/gitgo.svg?variant=adaptive)](https://starchart.cc/go-xlan/gitgo)
279+
[![Stargazers](https://starchart.cc/go-xlan/gitgo.svg?variant=adaptive)](https://starchart.cc/go-xlan/gitgo)

git_up.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,18 @@ func (G *Gcm) GetIgnoredFiles() ([]string, error) {
606606
}
607607
return paths, nil
608608
}
609+
610+
// ConfigGet retrieves a configuration value from Git config
611+
// Executes 'git config <key>' to get specified setting
612+
// Use case: read user.name, user.email, and custom configuration values
613+
//
614+
// ConfigGet 从 Git 配置获取配置值
615+
// 执行 'git config <key>' 获取指定设置
616+
// 使用场景:读取 user.name、user.email 和自定义配置值
617+
func (G *Gcm) ConfigGet(key string) (string, error) {
618+
output, err := G.execConfig.Exec("git", "config", key)
619+
if err != nil {
620+
return "", erero.Wro(err)
621+
}
622+
return strings.TrimSpace(string(output)), nil
623+
}

git_up_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,3 +858,21 @@ func TestGcm_GetUpstreamBranch(t *testing.T) {
858858
// OK if fails (no upstream set) // 出错也可以(未设置上游)
859859
t.Log("tracking branch error (expected if no upstream):", err)
860860
}
861+
862+
// TestGcm_ConfigGet tests retrieving Git config values
863+
// Verifies that config values can be read from Git config
864+
// Uses core.repositoryformatversion which exists in all Git repos
865+
//
866+
// TestGcm_ConfigGet 测试获取 Git 配置值
867+
// 验证可以从 Git 配置中读取配置值
868+
// 使用 core.repositoryformatversion 因为它在所有 Git 仓库中都存在
869+
func TestGcm_ConfigGet(t *testing.T) {
870+
gcm := gitgo.New(runpath.PARENT.Path())
871+
872+
// Test with a config that always exists in any git repo
873+
// 测试一个在任何 git 仓库中都存在的配置
874+
repoVersion, err := gcm.ConfigGet("core.repositoryformatversion")
875+
require.NoError(t, err)
876+
require.NotEmpty(t, repoVersion)
877+
t.Log("core.repositoryformatversion:", repoVersion)
878+
}

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ require (
66
github.com/pkg/errors v0.9.1
77
github.com/stretchr/testify v1.11.1
88
github.com/yyle88/erero v1.0.24
9-
github.com/yyle88/eroticgo v0.0.5
10-
github.com/yyle88/must v0.0.28
11-
github.com/yyle88/osexec v0.0.34
12-
github.com/yyle88/osexistpath v0.0.18
9+
github.com/yyle88/eroticgo v0.0.6
10+
github.com/yyle88/must v0.0.29
11+
github.com/yyle88/osexec v0.0.38
12+
github.com/yyle88/osexistpath v0.0.19
1313
github.com/yyle88/rese v0.0.12
1414
github.com/yyle88/runpath v1.0.25
15-
github.com/yyle88/zaplog v0.0.27
15+
github.com/yyle88/zaplog v0.0.28
1616
)
1717

1818
require (
1919
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2020
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
2121
github.com/yyle88/done v1.0.28 // indirect
2222
github.com/yyle88/mutexmap v1.0.15 // indirect
23-
github.com/yyle88/printgo v1.0.6 // indirect
23+
github.com/yyle88/printgo v1.0.7 // indirect
2424
github.com/yyle88/sure v0.0.42 // indirect
2525
github.com/yyle88/syntaxgo v0.0.54 // indirect
26-
github.com/yyle88/tern v0.0.9 // indirect
26+
github.com/yyle88/tern v0.0.10 // indirect
2727
go.uber.org/multierr v1.11.0 // indirect
2828
go.uber.org/zap v1.27.1 // indirect
2929
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)