feat: update commit handling in PublishModal for new projects and uncommitted changes

This commit is contained in:
lanrtop 2026-04-01 02:34:38 +09:00
parent b067c1f348
commit 93617565bf

View File

@ -93,8 +93,8 @@ export function PublishModal({ project, onClose }: Props) {
if (needGitignore) steps.push({ label: "生成 .gitignore", status: "pending" });
steps.push({ label: "在 GitHub 创建远端仓库", status: "pending" });
if (needInit || scan.has_changes) {
steps.push({ label: `提交本地代码(${commitMsg}`, status: "pending" });
if (needInit) {
steps.push({ label: `初始化并提交代码(${commitMsg}`, status: "pending" });
}
steps.push({ label: "配置 origin remote", status: "pending" });
steps.push({ label: `推送到 GitHub (${branch})`, status: "pending" });
@ -133,8 +133,8 @@ export function PublishModal({ project, onClose }: Props) {
cloneUrl = await githubCreateRepo(repoName, repoDesc, isPrivate);
updateLog(logIdx++, "ok", cloneUrl);
// 3. 提交本地代码(需要 init 或有改动)
const needCommit = !scan.has_git || !scan.has_commits || scan.has_changes;
// 3. 全新项目git init + 提交所有文件
const needCommit = !scan.has_git || !scan.has_commits;
if (needCommit) {
updateLog(logIdx, "pending", "git add & commit…");
await gitInitAndCommit(localPath, commitMsg);
@ -304,15 +304,12 @@ export function PublishModal({ project, onClose }: Props) {
</div>
)}
{/* 改动文件预览 */}
{(() => {
const needCommit = !scan.has_git || !scan.has_commits || scan.has_changes;
if (!needCommit) return null;
return (
<div className="border border-gray-200 rounded-lg px-4 py-3 text-xs space-y-2">
{scan.has_changes ? (
<>
<p className="font-semibold text-gray-600">{scan.changed_files.length} </p>
{/* 未提交内容:阻断发布 */}
{scan.has_changes && (
<div className="bg-orange-50 border border-orange-200 rounded-lg px-4 py-3 text-xs space-y-2">
<p className="font-semibold text-orange-700">
{scan.changed_files.length}
</p>
<div className="max-h-28 overflow-y-auto space-y-0.5">
{scan.changed_files.slice(0, 50).map((f, i) => (
<div key={i} className="flex items-center gap-2 font-mono text-gray-500">
@ -327,23 +324,28 @@ export function PublishModal({ project, onClose }: Props) {
<p className="text-gray-400"> {scan.changed_files.length - 50} </p>
)}
</div>
</>
) : (
<p className="font-semibold text-gray-600">
{!scan.has_git ? "全新项目,将执行 git init 并提交所有文件" : "无历史提交,将提交当前所有文件"}
<p className="text-orange-600">
<span className="font-semibold">VSCode</span> <span className="font-semibold">Claude</span>
</p>
</div>
)}
{/* 全新项目提示(无 git / 无提交记录,但工作区干净) */}
{!scan.has_changes && (!scan.has_git || !scan.has_commits) && (
<div className="border border-blue-100 bg-blue-50 rounded-lg px-4 py-3 text-xs space-y-2">
<p className="font-semibold text-blue-700">
{!scan.has_git ? "全新项目:将自动执行 git init 并提交所有文件" : "尚无提交记录:将自动提交当前所有文件"}
</p>
<div>
<label className="block text-gray-500 mb-1">Commit </label>
<label className="block text-blue-600 mb-1"> Commit </label>
<input
className="w-full border border-gray-200 rounded-lg px-3 py-1.5 text-sm outline-none focus:ring-2 focus:ring-blue-200"
className="w-full border border-blue-200 rounded-lg px-3 py-1.5 text-sm outline-none focus:ring-2 focus:ring-blue-200 bg-white"
value={commitMsg}
onChange={(e) => setCommitMsg(e.target.value)}
/>
</div>
</div>
);
})()}
)}
{/* GitHub 仓库配置 */}
<div className="border border-gray-200 rounded-lg px-4 py-3 space-y-3">
@ -430,6 +432,7 @@ export function PublishModal({ project, onClose }: Props) {
onClick={handleExecute}
disabled={
!repoName.trim() ||
scan.has_changes ||
(scan.suspicious_files.length > 0 && !confirmedSensitive)
}
className="px-4 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50"