非强制上传模式下,要求HEAD游离且指向Tag
This commit is contained in:
@@ -870,7 +870,7 @@ static void PrintUploadUsage()
|
||||
_tprintf(_T("用法:gitver upload username=<用户名> [file=<上传的文件>] [info=<配置.txt>] [url=<PMC基址>] [-f]\n"));
|
||||
_tprintf(_T("说明:info= 缺省为 upload_info.txt;file= 可省略,从 info 的 file 字段读取\n"));
|
||||
_tprintf(_T("说明:登录密码从与 username 同名的环境变量读取\n"));
|
||||
_tprintf(_T("说明:默认要求当前在分支上且 HEAD 指向 Tag;加 -f 可忽略 Tag 校验\n"));
|
||||
_tprintf(_T("说明:默认要求当前在分支上且 HEAD 指向 Tag;加 -f 允许游离 HEAD 指向 Tag 时上传\n"));
|
||||
_tprintf(_T("示例:gitver upload username=admin\n"));
|
||||
}
|
||||
|
||||
@@ -881,27 +881,35 @@ static void PrintUploadUsage()
|
||||
/// <returns>0 表示通过;54 表示 HEAD 游离或未指向 Tag。</returns>
|
||||
static int ValidateUploadGitTagState(LPCTSTR lpRepoPath)
|
||||
{
|
||||
CString strStatus;
|
||||
if (!TryGetGitStatus(lpRepoPath, strStatus))
|
||||
{
|
||||
CString strTag;
|
||||
if (TryGetDetectedTag(lpRepoPath, strTag))
|
||||
{
|
||||
_tprintf(_T("错误: 当前处于 HEAD 游离状态(Tag: %s),不允许上传\n"), strTag.GetString());
|
||||
}
|
||||
else
|
||||
{
|
||||
_tprintf(_T("错误: 当前处于 HEAD 游离状态,不允许上传\n"));
|
||||
}
|
||||
_tprintf(_T("提示: 使用 upload ... -f 可强制上传\n"));
|
||||
return 54;
|
||||
}
|
||||
|
||||
CString strTag;
|
||||
if (!TryGetDetectedTag(lpRepoPath, strTag))
|
||||
{
|
||||
_tprintf(_T("错误: 当前 commit 未指向 Tag 标签,不允许上传\n"));
|
||||
_tprintf(_T("提示: 使用 upload ... -f 可强制上传\n"));
|
||||
return 54;
|
||||
}
|
||||
|
||||
// 并且要处于游离状态;
|
||||
CString strStatus;
|
||||
if(TryGetGitStatus(lpRepoPath, strStatus))
|
||||
{
|
||||
_tprintf(_T("错误: 当前 HEAD 非游离,不允许上传\n"));
|
||||
return 54;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制上传模式下的 Tag 校验:要求当前 commit 指向 Tag(允许游离 HEAD)。
|
||||
/// </summary>
|
||||
/// <param name="lpRepoPath">仓库根目录。</param>
|
||||
/// <returns>0 表示通过;54 表示当前 commit 未指向 Tag。</returns>
|
||||
static int ValidateUploadGitTagStateForce(LPCTSTR lpRepoPath)
|
||||
{
|
||||
CString strTag;
|
||||
if (!TryGetDetectedTag(lpRepoPath, strTag))
|
||||
{
|
||||
_tprintf(_T("错误: 当前 commit 未指向 Tag 标签,不允许上传\n"));
|
||||
return 54;
|
||||
}
|
||||
|
||||
@@ -1136,6 +1144,12 @@ int HandleUploadCommand(int argc, TCHAR* argv[])
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (!bForceUpload && (0 != ValidateUploadGitTagState(g_szCurModuleDir)))
|
||||
{
|
||||
_tprintf(_T("警告: 非强制上传模式下要求当前 commit 必须指向 Tag\n"));
|
||||
return 54;
|
||||
}
|
||||
|
||||
if (strUsername.IsEmpty())
|
||||
{
|
||||
_tprintf(_T("错误: upload 缺少必填参数 username=\n"));
|
||||
@@ -1194,15 +1208,6 @@ int HandleUploadCommand(int argc, TCHAR* argv[])
|
||||
return 49;
|
||||
}
|
||||
|
||||
if (!bForceUpload)
|
||||
{
|
||||
int nTagRet = ValidateUploadGitTagState(g_szCurModuleDir);
|
||||
if (nTagRet != 0)
|
||||
{
|
||||
return nTagRet;
|
||||
}
|
||||
}
|
||||
|
||||
CString strPassword;
|
||||
if (!ResolvePasswordFromEnv(strUsername, strPassword))
|
||||
{
|
||||
|
||||
@@ -299,7 +299,7 @@ gitver setup=1 pid=5 repodir=E:\Code\MyProj
|
||||
```
|
||||
gitver upload username=<用户名> [file=<上传文件>] [info=<配置.txt>] [url=<PMC基址>]
|
||||
gitver upload username=<用户名> # 需在分支上且 HEAD 指向 Tag
|
||||
gitver upload username=<用户名> -f # 强制上传,忽略 Tag 校验
|
||||
gitver upload username=<用户名> -f # 游离 HEAD 指向 Tag 时强制上传
|
||||
gitver upload -f username=<用户名> [file=<上传文件>] # -f 位置任意
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user