Compare commits

..

3 Commits

Author SHA1 Message Date
Jeff
52221ac116 当提交标签失败后,需要删除本地创建的标签 2026-04-27 10:56:53 +08:00
Jeff
c05a8cc0e0 1、无参数时,需要暂停不直接退出。
2、创建标签后,需要上传到远程仓库中。
2026-04-27 10:49:36 +08:00
Jeff
e90f37966f 修正:当当天提交数为0时,以最后一次提交日期重新生成mmdd.id值。 2026-04-24 16:05:57 +08:00
4 changed files with 136 additions and 20 deletions

View File

@@ -818,6 +818,8 @@ int main(int argc, TCHAR* argv[], TCHAR* envp[])
int nCmdRet = HandleCreateTagInteractive(); int nCmdRet = HandleCreateTagInteractive();
LogCommandEnd(_T("interactive"), dwStartTick, nCmdRet); LogCommandEnd(_T("interactive"), dwStartTick, nCmdRet);
PrintCommandFailedWithCode(_T("interactive"), nCmdRet); PrintCommandFailedWithCode(_T("interactive"), nCmdRet);
// 暂停便于查看输出日志Windows 控制台)
system("pause");
return nCmdRet; return nCmdRet;
} }

View File

@@ -230,6 +230,42 @@ int HandleCreateTagInteractive()
return 34; return 34;
} }
// 已验证本地创建成功后,尝试推送到远程 origin
CString strPushCmd;
strPushCmd.Format(_T("cmd /c git push origin %s"), QuoteCmdArg(strNewTag).GetString());
CString strPushResult = StartProcess(NULL, strPushCmd.GetBuffer(), lpRepoPath);
strPushCmd.ReleaseBuffer();
strPushResult.Trim();
if (strPushResult.Left(6).CompareNoCase(_T("fatal:")) == 0 || strPushResult.Left(5).CompareNoCase(_T("error")) == 0)
{
_tprintf(_T("警告: 推送标签到远程失败: %s\n"), strPushResult.GetString());
// 推送失败:尝试删除本地标签,避免残留
CString strDeleteCmd;
strDeleteCmd.Format(_T("cmd /c git tag -d %s"), QuoteCmdArg(strNewTag).GetString());
CString strDeleteResult = StartProcess(NULL, strDeleteCmd.GetBuffer(), lpRepoPath);
strDeleteCmd.ReleaseBuffer();
strDeleteResult.Trim();
if (strDeleteResult.Left(6).CompareNoCase(_T("fatal:")) == 0 || strDeleteResult.Left(5).CompareNoCase(_T("error")) == 0)
{
_tprintf(_T("错误: 推送失败,且删除本地标签失败: %s\n"), strDeleteResult.GetString());
// 返回错误码 36 表示推送失败(删除也失败)
return 36;
}
else
{
_tprintf(_T("已删除本地标签: %s\n"), strNewTag.GetString());
// 返回错误码 36 表示推送失败,但本地标签已清理
return 36;
}
}
else
{
_tprintf(_T("成功: 推送标签到远程 origin: %s\n"), strNewTag.GetString());
}
_tprintf(_T("成功: 创建标签 %s\n"), strNewTag.GetString()); _tprintf(_T("成功: 创建标签 %s\n"), strNewTag.GetString());
return 0; return 0;
} }

View File

@@ -122,16 +122,14 @@ BOOL GetLastMajorMinorTag(LPCTSTR lpRepoPath, const CString& strBranch, CString&
return !strTag.IsEmpty(); return !strTag.IsEmpty();
} }
void GetTodayFileVersionDate(UINT& nYY, UINT& nMMDD) void GetFileVersionDateFromSystemTime(const SYSTEMTIME& stLocal, UINT& nYY, UINT& nMMDD)
{ {
SYSTEMTIME stLocal = { 0 };
::GetLocalTime(&stLocal);
nYY = stLocal.wYear % 100; nYY = stLocal.wYear % 100;
// 为了让版本号对齐4位月份从1-12映射到11-22;
nMMDD = (stLocal.wMonth + 10) * 100 + stLocal.wDay; nMMDD = (stLocal.wMonth + 10) * 100 + stLocal.wDay;
} }
BOOL GetTodayBranchCommitCount(LPCTSTR lpRepoPath, const CString& strBranch, UINT& nId) BOOL TryGetBranchCommitCountByDate(LPCTSTR lpRepoPath, const CString& strBranch, const SYSTEMTIME& stDate, UINT& nId)
{ {
nId = 0; nId = 0;
if (strBranch.IsEmpty()) if (strBranch.IsEmpty())
@@ -139,11 +137,8 @@ BOOL GetTodayBranchCommitCount(LPCTSTR lpRepoPath, const CString& strBranch, UIN
return FALSE; return FALSE;
} }
SYSTEMTIME stLocal = { 0 };
::GetLocalTime(&stLocal);
CString strDate; CString strDate;
strDate.Format(_T("%04u-%02u-%02u"), stLocal.wYear, stLocal.wMonth, stLocal.wDay); strDate.Format(_T("%04u-%02u-%02u"), stDate.wYear, stDate.wMonth, stDate.wDay);
CString strCmd; CString strCmd;
strCmd.Format( strCmd.Format(
@@ -172,6 +167,93 @@ BOOL GetTodayBranchCommitCount(LPCTSTR lpRepoPath, const CString& strBranch, UIN
return TryParseUInt16(strCount, nId); return TryParseUInt16(strCount, nId);
} }
BOOL TryGetLastBranchCommitDate(LPCTSTR lpRepoPath, const CString& strBranch, SYSTEMTIME& stDate)
{
::ZeroMemory(&stDate, sizeof(stDate));
if (strBranch.IsEmpty())
{
return FALSE;
}
CString strCmd;
strCmd.Format(_T("cmd /c git log -1 --date=short --format=%%cd \"%s\""), strBranch.GetString());
CString strDate = StartProcess(NULL, strCmd.GetBuffer(), lpRepoPath);
strCmd.ReleaseBuffer();
if (strDate.IsEmpty())
{
return FALSE;
}
strDate.Replace(_T("\r"), _T(""));
strDate.Replace(_T("\n"), _T(""));
strDate.Trim();
if (strDate.IsEmpty() || strDate.Left(6).CompareNoCase(_T("fatal:")) == 0)
{
return FALSE;
}
unsigned int nYear = 0;
unsigned int nMonth = 0;
unsigned int nDay = 0;
if (_stscanf_s(strDate.GetString(), _T("%u-%u-%u"), &nYear, &nMonth, &nDay) != 3)
{
return FALSE;
}
stDate.wYear = static_cast<WORD>(nYear);
stDate.wMonth = static_cast<WORD>(nMonth);
stDate.wDay = static_cast<WORD>(nDay);
return TRUE;
}
BOOL ResolveFileVersionDateAndCommitCount(LPCTSTR lpRepoPath, const CString& strBranch, UINT& nYY, UINT& nMMDD, UINT& nId)
{
nYY = 0;
nMMDD = 0;
nId = 0;
SYSTEMTIME stTargetDate = { 0 };
::GetLocalTime(&stTargetDate);
UINT nTodayCommitCount = 0;
if (!TryGetBranchCommitCountByDate(lpRepoPath, strBranch, stTargetDate, nTodayCommitCount))
{
_tprintf(_T("错误: 获取当天提交数量失败\n"));
return FALSE;
}
if (nTodayCommitCount == 0)
{
_tprintf(_T("当天提交数量为0将获取最后一次提交日期\n"));
if (!TryGetLastBranchCommitDate(lpRepoPath, strBranch, stTargetDate))
{
_tprintf(_T("错误: 获取最后一次提交日期失败\n"));
return FALSE;
}
if (!TryGetBranchCommitCountByDate(lpRepoPath, strBranch, stTargetDate, nTodayCommitCount))
{
_tprintf(_T("错误: 获取[%s]提交数量失败\n"), strBranch.GetString());
return FALSE;
}
_tprintf(_T("获取到最后一次提交日期: %04u-%02u-%02u, 提交数量: %u\n"),
stTargetDate.wYear, stTargetDate.wMonth, stTargetDate.wDay, nTodayCommitCount);
}
else
{
_tprintf(_T("获取到当天提交数量: %u\n"), nTodayCommitCount);
}
GetFileVersionDateFromSystemTime(stTargetDate, nYY, nMMDD);
nId = nTodayCommitCount;
return TRUE;
}
int BuildVersionsFromRepo( int BuildVersionsFromRepo(
LPCTSTR lpRepoPath, LPCTSTR lpRepoPath,
UINT nPid, UINT nPid,
@@ -200,7 +282,7 @@ int BuildVersionsFromRepo(
if (!TryGetBidFromBranch(strBranch, nBid)) if (!TryGetBidFromBranch(strBranch, nBid))
{ {
_tprintf(_T("错误: 从分支获取 bid 失败\n")); _tprintf(_T("错误: 获取分支 bid 失败\n"));
return errorCodes.nBidErrorCode; return errorCodes.nBidErrorCode;
} }
_tprintf(_T("分支 bid: %u\n"), nBid); _tprintf(_T("分支 bid: %u\n"), nBid);
@@ -212,7 +294,7 @@ int BuildVersionsFromRepo(
{ {
if (!bUseDefaultTagWhenMissing) if (!bUseDefaultTagWhenMissing)
{ {
_tprintf(_T("错误: 获取标签失败\n")); _tprintf(_T("错误: 获取标签失败\n"));
return errorCodes.nTagErrorCode; return errorCodes.nTagErrorCode;
} }
@@ -222,23 +304,21 @@ int BuildVersionsFromRepo(
} }
else else
{ {
_tprintf(_T("命中最新标签: %s (major=%u minor=%u)\n"), strLastTag.GetString(), nMajor, nMinor); _tprintf(_T("获取到的标签: %s (major=%u minor=%u)\n"), strLastTag.GetString(), nMajor, nMinor);
} }
UINT nYY = 0; UINT nYY = 0;
UINT nMMDD = 0; UINT nMMDD = 0;
GetTodayFileVersionDate(nYY, nMMDD);
UINT nId = 0; UINT nId = 0;
if (!GetTodayBranchCommitCount(lpRepoPath, strBranch, nId)) if (!ResolveFileVersionDateAndCommitCount(lpRepoPath, strBranch, nYY, nMMDD, nId))
{ {
_tprintf(_T("错误: 获取今日分支提交计数失败\n")); _tprintf(_T("错误: 获取分支提交信息失败\n"));
return errorCodes.nCommitErrorCode; return errorCodes.nCommitErrorCode;
} }
_tprintf(_T("今日提交计数: %u\n"), nId); _tprintf(_T("分支提交信息: yy=%u mmdd=%u id=%u\n"), nYY, nMMDD, nId);
strProductVersion.Format(_T("%u.%u.%u.%u"), nPid, nBid, nMajor, nMinor); strProductVersion.Format(_T("%u.%u.%u.%u"), nPid, nBid, nMajor, nMinor);
strFileVersion.Format(_T("%u.%u.%u.%u"), nPid, nYY, nMMDD, nId); strFileVersion.Format(_T("%u.%u.%u.%u"), nPid, nYY, nMMDD, nId);
_tprintf(_T("版本构建完成: ProductVersion=%s FileVersion=%s\n"), strProductVersion.GetString(), strFileVersion.GetString()); _tprintf(_T("文件版本信息: ProductVersion=%s FileVersion=%s\n"), strProductVersion.GetString(), strFileVersion.GetString());
return 0; return 0;
} }

View File

@@ -11,8 +11,6 @@ BOOL TryGetCurrentBranch(LPCTSTR lpRepoPath, CString& strBranch);
BOOL TryGetBidFromBranch(const CString& strBranch, UINT& nBid); BOOL TryGetBidFromBranch(const CString& strBranch, UINT& nBid);
BOOL TryParseTagMajorMinor(const CString& strBranch, const CString& strTag, UINT& nMajor, UINT& nMinor); BOOL TryParseTagMajorMinor(const CString& strBranch, const CString& strTag, UINT& nMajor, UINT& nMinor);
BOOL GetLastMajorMinorTag(LPCTSTR lpRepoPath, const CString& strBranch, CString& strTag, UINT& nMajor, UINT& nMinor); BOOL GetLastMajorMinorTag(LPCTSTR lpRepoPath, const CString& strBranch, CString& strTag, UINT& nMajor, UINT& nMinor);
void GetTodayFileVersionDate(UINT& nYY, UINT& nMMDD);
BOOL GetTodayBranchCommitCount(LPCTSTR lpRepoPath, const CString& strBranch, UINT& nId);
int BuildVersionsFromRepo( int BuildVersionsFromRepo(
LPCTSTR lpRepoPath, LPCTSTR lpRepoPath,
UINT nPid, UINT nPid,