修复本地新创建的分支无法推送到远程

This commit is contained in:
xintaofei
2026-03-23 16:09:18 +08:00
parent c8af3e07ac
commit b010ef071d
15 changed files with 114 additions and 32 deletions

View File

@@ -782,10 +782,12 @@ export function GitLogTab() {
}
setError(null)
try {
const log = await gitLog(folder.path, 100, branch ?? undefined)
setEntries(log)
const result = await gitLog(folder.path, 100, branch ?? undefined)
setEntries(result.entries)
if (inline) {
const commitHashes = new Set(log.map((entry) => entry.full_hash))
const commitHashes = new Set(
result.entries.map((entry) => entry.full_hash)
)
setOpenByCommit((prev) =>
filterRecordByCommitHashes(prev, commitHashes)
)

View File

@@ -279,6 +279,7 @@ export function PushWorkspace({
const { withCredentialRetry } = useGitCredential()
const [commits, setCommits] = useState<GitLogEntry[]>([])
const [hasUpstream, setHasUpstream] = useState(true)
const [listLoading, setListLoading] = useState(false)
const [openByCommit, setOpenByCommit] = useState<Record<string, boolean>>({})
const [pushing, setPushing] = useState(false)
@@ -297,8 +298,9 @@ export function PushWorkspace({
const loadCommits = useCallback(async () => {
setListLoading(true)
try {
const entries = await gitLog(folderPath, 100)
setCommits(entries)
const result = await gitLog(folderPath, 100)
setCommits(result.entries)
setHasUpstream(result.has_upstream)
} catch (err) {
toast.error(toErrorMessage(err))
} finally {
@@ -358,7 +360,9 @@ export function PushWorkspace({
</div>
) : unpushedCommits.length === 0 ? (
<div className="flex items-center justify-center py-12 text-sm text-muted-foreground">
{t("noUnpushedCommits")}
{!hasUpstream
? t("newBranchNoPushedCommits")
: t("noUnpushedCommits")}
</div>
) : (
<div className="flex flex-col gap-2 p-2">
@@ -433,7 +437,9 @@ export function PushWorkspace({
<div className="border-t p-2">
<Button
className="w-full"
disabled={pushing || unpushedCommits.length === 0}
disabled={
pushing || (hasUpstream && unpushedCommits.length === 0)
}
onClick={handlePush}
>
{pushing ? (

View File

@@ -1039,6 +1039,7 @@
"pushWindow": {
"title": "دفع الكود",
"noUnpushedCommits": "لا توجد التزامات غير مدفوعة",
"newBranchNoPushedCommits": "فرع جديد — ادفع لإنشاء فرع تتبع عن بُعد",
"unpushed": "غير مدفوع",
"selectFileToViewDiff": "اختر ملفًا لعرض الفرق",
"before": "قبل",

View File

@@ -1039,6 +1039,7 @@
"pushWindow": {
"title": "Code pushen",
"noUnpushedCommits": "Keine ungepushten Commits",
"newBranchNoPushedCommits": "Neuer Branch — pushen, um Remote-Tracking-Branch zu erstellen",
"unpushed": "Nicht gepusht",
"selectFileToViewDiff": "Datei auswählen, um Unterschiede anzuzeigen",
"before": "Vorher",

View File

@@ -1039,6 +1039,7 @@
"pushWindow": {
"title": "Push Code",
"noUnpushedCommits": "No unpushed commits",
"newBranchNoPushedCommits": "New branch — push to create remote tracking branch",
"unpushed": "Unpushed",
"selectFileToViewDiff": "Select a file to view diff",
"before": "Before",

View File

@@ -1039,6 +1039,7 @@
"pushWindow": {
"title": "Enviar código",
"noUnpushedCommits": "No hay commits sin enviar",
"newBranchNoPushedCommits": "Nueva rama — enviar para crear rama de seguimiento remota",
"unpushed": "Sin enviar",
"selectFileToViewDiff": "Selecciona un archivo para ver las diferencias",
"before": "Antes",

View File

@@ -1039,6 +1039,7 @@
"pushWindow": {
"title": "Pousser le code",
"noUnpushedCommits": "Aucun commit non poussé",
"newBranchNoPushedCommits": "Nouvelle branche — pousser pour créer la branche de suivi distante",
"unpushed": "Non poussé",
"selectFileToViewDiff": "Sélectionnez un fichier pour voir les différences",
"before": "Avant",

View File

@@ -1039,6 +1039,7 @@
"pushWindow": {
"title": "コードをプッシュ",
"noUnpushedCommits": "未プッシュのコミットはありません",
"newBranchNoPushedCommits": "新しいブランチ — プッシュしてリモート追跡ブランチを作成",
"unpushed": "未プッシュ",
"selectFileToViewDiff": "ファイルを選択して差分を表示",
"before": "変更前",

View File

@@ -1039,6 +1039,7 @@
"pushWindow": {
"title": "코드 푸시",
"noUnpushedCommits": "푸시되지 않은 커밋이 없습니다",
"newBranchNoPushedCommits": "새 브랜치 — 푸시하여 원격 추적 브랜치 생성",
"unpushed": "미푸시",
"selectFileToViewDiff": "파일을 선택하여 차이 보기",
"before": "변경 전",

View File

@@ -1039,6 +1039,7 @@
"pushWindow": {
"title": "Enviar código",
"noUnpushedCommits": "Nenhum commit não enviado",
"newBranchNoPushedCommits": "Nova branch — enviar para criar branch de rastreamento remota",
"unpushed": "Não enviado",
"selectFileToViewDiff": "Selecione um arquivo para ver as diferenças",
"before": "Antes",

View File

@@ -1039,6 +1039,7 @@
"pushWindow": {
"title": "推送代码",
"noUnpushedCommits": "没有未推送的提交",
"newBranchNoPushedCommits": "新分支 — 推送以创建远程跟踪分支",
"unpushed": "未推送",
"selectFileToViewDiff": "选择文件查看差异",
"before": "修改前",

View File

@@ -1039,6 +1039,7 @@
"pushWindow": {
"title": "推送程式碼",
"noUnpushedCommits": "沒有未推送的提交",
"newBranchNoPushedCommits": "新分支 — 推送以建立遠端追蹤分支",
"unpushed": "未推送",
"selectFileToViewDiff": "選擇檔案查看差異",
"before": "修改前",

View File

@@ -38,7 +38,7 @@ import type {
FilePreviewContent,
FileEditContent,
FileSaveResult,
GitLogEntry,
GitLogResult,
SystemLanguageSettings,
SystemProxySettings,
GitCredentials,
@@ -1048,7 +1048,7 @@ export async function gitLog(
path: string,
limit?: number,
branch?: string
): Promise<GitLogEntry[]> {
): Promise<GitLogResult> {
return invoke("git_log", {
path,
limit: limit ?? null,

View File

@@ -743,6 +743,11 @@ export interface FileTreeChangedEvent {
refresh_git_status: boolean
}
export interface GitLogResult {
entries: GitLogEntry[]
has_upstream: boolean
}
export interface GitLogEntry {
hash: string
full_hash: string