1、修复TryGetDetectedBranch问题

2、修复TryGetBranchCommitCountByDate在游离状态下获取分支失败的问题,应当获取远程分支,如:origin/master
但当浅克隆仓库,本地从未拉取过 origin/master,需要先执行:git fetch origin/master
3、更新md文件
This commit is contained in:
2026-06-24 09:24:27 +08:00
parent 71f99a55b4
commit 5679433f7c
2 changed files with 5 additions and 2 deletions

View File

@@ -38,7 +38,9 @@ BOOL TryGetCurrentBranch(LPCTSTR lpRepoPath, CString& strBranch)
BOOL TryGetDetectedBranch(LPCTSTR lpRepoPath, CString& strBranch)
{
// 远程仓库名必须以 origin 开头;
strBranch = StartProcess(NULL, _T("cmd /c git branch -r --contains HEAD | head -n1 | sed 's/.*origin\\///'"), lpRepoPath);
// "C:\Program Files\Git\bin\bash.exe" -c "git branch -r --contains HEAD | head -n1 | sed 's/.*origin\///'"
strBranch = StartProcess(NULL, _T("\"C:\\Program Files\\Git\\bin\\bash.exe\" -c \"git branch -r --contains HEAD | head -n1 | sed 's/.*origin\\///'\""), lpRepoPath);
//strBranch = StartProcess("C:\\Program Files\\Git\\bin\\bash.exe", _T("git branch -r --contains HEAD | head -n1 | sed 's/.*origin\\///'"), lpRepoPath);
strBranch.Replace(_T("\r"), _T(""));
strBranch.Replace(_T("\n"), _T(""));
strBranch.Trim();
@@ -202,7 +204,7 @@ BOOL TryGetBranchCommitCountByDate(LPCTSTR lpRepoPath, const CString& strBranch,
CString strCmd;
strCmd.Format(
_T("cmd /c git rev-list --count --since=\"%s 00:00:00\" --until=\"%s 23:59:59\" \"%s\""),
_T("cmd /c git rev-list --count --since=\"%s 00:00:00\" --until=\"%s 23:59:59\" \"origin/%s\""),
strDate.GetString(),
strDate.GetString(),
strBranch.GetString());

View File

@@ -1,6 +1,7 @@
# GitVer
命令行版本管理工具,从 Git 仓库读取 tag 自动生成并回写版本号。
必须安装Git for Windows且安装目录默认在C盘C:\Program Files\Git
---