diff --git a/GitVer/GitVer_upload.cpp b/GitVer/GitVer_upload.cpp index 1cde4ad..011c3ee 100644 --- a/GitVer/GitVer_upload.cpp +++ b/GitVer/GitVer_upload.cpp @@ -870,7 +870,7 @@ static void PrintUploadUsage() _tprintf(_T("用法:gitver upload username=<用户名> [file=<上传的文件>] [info=<配置.txt>] [url=] [-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() /// 0 表示通过;54 表示 HEAD 游离或未指向 Tag。 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; +} + +/// +/// 强制上传模式下的 Tag 校验:要求当前 commit 指向 Tag(允许游离 HEAD)。 +/// +/// 仓库根目录。 +/// 0 表示通过;54 表示当前 commit 未指向 Tag。 +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)) { diff --git a/README.md b/README.md index 32ec2ae..aad759e 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ gitver setup=1 pid=5 repodir=E:\Code\MyProj ``` gitver upload username=<鐢ㄦ埛鍚> [file=<涓婁紶鏂囦欢>] [info=<閰嶇疆.txt>] [url=] gitver upload username=<鐢ㄦ埛鍚> # 闇鍦ㄥ垎鏀笂涓 HEAD 鎸囧悜 Tag -gitver upload username=<鐢ㄦ埛鍚> -f # 寮哄埗涓婁紶锛屽拷鐣 Tag 鏍¢獙 +gitver upload username=<鐢ㄦ埛鍚> -f # 娓哥 HEAD 鎸囧悜 Tag 鏃跺己鍒朵笂浼 gitver upload -f username=<鐢ㄦ埛鍚> [file=<涓婁紶鏂囦欢>] # -f 浣嶇疆浠绘剰 ```