feat: update commit handling in PublishModal for new projects and uncommitted changes
This commit is contained in:
parent
b067c1f348
commit
93617565bf
@ -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,46 +304,48 @@ 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>
|
||||
<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">
|
||||
<span className={`w-4 font-bold ${
|
||||
f.status === "?" ? "text-green-500" :
|
||||
f.status === "D" ? "text-red-500" : "text-yellow-500"
|
||||
}`}>{f.status}</span>
|
||||
<span className="truncate">{f.path}</span>
|
||||
</div>
|
||||
))}
|
||||
{scan.changed_files.length > 50 && (
|
||||
<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>
|
||||
{/* 未提交内容:阻断发布 */}
|
||||
{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">
|
||||
<span className={`w-4 font-bold ${
|
||||
f.status === "?" ? "text-green-500" :
|
||||
f.status === "D" ? "text-red-500" : "text-yellow-500"
|
||||
}`}>{f.status}</span>
|
||||
<span className="truncate">{f.path}</span>
|
||||
</div>
|
||||
))}
|
||||
{scan.changed_files.length > 50 && (
|
||||
<p className="text-gray-400">…还有 {scan.changed_files.length - 50} 个文件</p>
|
||||
)}
|
||||
<div>
|
||||
<label className="block text-gray-500 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"
|
||||
value={commitMsg}
|
||||
onChange={(e) => setCommitMsg(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
<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-blue-600 mb-1">初始 Commit 信息</label>
|
||||
<input
|
||||
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"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user