fix: make commit sync use safe sync flow
Rename commit push action to Commit & sync Use fetch and rebase before pushing committed changes Keep sync result toasts consistent
This commit is contained in:
@@ -1057,8 +1057,55 @@ export const GitView: React.FC = () => {
|
||||
await refreshStatusAndBranches();
|
||||
|
||||
if (options.pushAfter) {
|
||||
await git.gitPush(currentDirectory);
|
||||
toast.success(t('gitView.toast.pushedToUpstream'));
|
||||
const trackingRemoteName = status?.tracking?.split('/')[0];
|
||||
const syncRemote = effectiveRemotes.find((remote) => remote.name === trackingRemoteName) ?? effectiveRemotes[0];
|
||||
if (!syncRemote) {
|
||||
throw new Error('No remote available for sync');
|
||||
}
|
||||
|
||||
const trackingPrefix = `${syncRemote.name}/`;
|
||||
const trackedBranch = status?.tracking?.startsWith(trackingPrefix)
|
||||
? status.tracking.slice(trackingPrefix.length)
|
||||
: undefined;
|
||||
let pulledFileCount = 0;
|
||||
let pushedChanges = false;
|
||||
|
||||
await git.gitFetch(currentDirectory, { remote: syncRemote.name });
|
||||
const afterFetch = await git.getGitStatus(currentDirectory);
|
||||
|
||||
if ((afterFetch.behind ?? 0) > 0) {
|
||||
const pullResult = await git.gitPull(currentDirectory, {
|
||||
remote: syncRemote.name,
|
||||
branch: trackedBranch,
|
||||
rebase: true,
|
||||
});
|
||||
pulledFileCount = pullResult.files.length;
|
||||
}
|
||||
|
||||
const afterPull = await git.getGitStatus(currentDirectory);
|
||||
if ((afterPull.ahead ?? 0) > 0) {
|
||||
await git.gitPush(currentDirectory);
|
||||
pushedChanges = true;
|
||||
}
|
||||
|
||||
if (pulledFileCount > 0 && pushedChanges) {
|
||||
toast.success(
|
||||
pulledFileCount === 1
|
||||
? t('gitView.toast.syncedPulledSingleAndPushed', { count: pulledFileCount, name: syncRemote.name })
|
||||
: t('gitView.toast.syncedPulledPluralAndPushed', { count: pulledFileCount, name: syncRemote.name })
|
||||
);
|
||||
} else if (pulledFileCount > 0) {
|
||||
toast.success(
|
||||
pulledFileCount === 1
|
||||
? t('gitView.toast.pulledFilesSingle', { count: pulledFileCount, name: syncRemote.name })
|
||||
: t('gitView.toast.pulledFilesPlural', { count: pulledFileCount, name: syncRemote.name })
|
||||
);
|
||||
} else if (pushedChanges) {
|
||||
toast.success(t('gitView.toast.pushedToUpstream'));
|
||||
} else {
|
||||
toast.success(t('gitView.toast.syncedChanges'));
|
||||
}
|
||||
|
||||
triggerFireworks();
|
||||
await refreshStatusAndBranches(false);
|
||||
} else {
|
||||
|
||||
@@ -424,9 +424,9 @@ export const dict = {
|
||||
'gitView.commit.generate': 'Generate',
|
||||
'gitView.commit.generateAria': 'Generate commit message',
|
||||
'gitView.commit.messagePlaceholder': 'Commit message',
|
||||
'gitView.commit.push': 'Push',
|
||||
'gitView.commit.pushAria': 'Push',
|
||||
'gitView.commit.pushing': 'Pushing...',
|
||||
'gitView.commit.push': 'Commit & sync',
|
||||
'gitView.commit.pushAria': 'Commit and sync',
|
||||
'gitView.commit.pushing': 'Syncing...',
|
||||
'gitView.commit.selectFilesHint': 'Select files in Changes to enable commit.',
|
||||
'gitView.commit.title': 'Commit',
|
||||
'gitView.common.cancel': 'Cancel',
|
||||
|
||||
@@ -425,9 +425,9 @@ export const dict: Record<I18nKey, string> = {
|
||||
"gitView.commit.generate": "Generar",
|
||||
"gitView.commit.generateAria": "Generar mensaje de commit",
|
||||
"gitView.commit.messagePlaceholder": "Mensaje de commit",
|
||||
"gitView.commit.push": "Push",
|
||||
"gitView.commit.pushAria": "Push",
|
||||
"gitView.commit.pushing": "Enviando...",
|
||||
"gitView.commit.push": "Commit & sync",
|
||||
"gitView.commit.pushAria": "Commit and sync",
|
||||
"gitView.commit.pushing": "Sincronizando...",
|
||||
"gitView.commit.selectFilesHint": "Selecciona archivos en Cambios para habilitar el commit.",
|
||||
"gitView.commit.title": "Commit",
|
||||
"gitView.common.cancel": "Cancelar",
|
||||
|
||||
@@ -425,9 +425,9 @@ export const dict: Record<I18nKey, string> = {
|
||||
'gitView.commit.generate': '생성',
|
||||
'gitView.commit.generateAria': '커밋 메시지 생성',
|
||||
'gitView.commit.messagePlaceholder': '커밋 메시지',
|
||||
'gitView.commit.push': '푸시',
|
||||
'gitView.commit.pushAria': '푸시',
|
||||
'gitView.commit.pushing': '푸시 중…',
|
||||
'gitView.commit.push': 'Commit & sync',
|
||||
'gitView.commit.pushAria': 'Commit and sync',
|
||||
'gitView.commit.pushing': 'sync 중…',
|
||||
'gitView.commit.selectFilesHint': '커밋하려면 변경 사항에서 파일을 선택하세요.',
|
||||
'gitView.commit.title': '커밋',
|
||||
'gitView.common.cancel': '취소',
|
||||
|
||||
@@ -425,9 +425,9 @@ export const dict: Record<I18nKey, string> = {
|
||||
"gitView.commit.generate": "Generar",
|
||||
"gitView.commit.generateAria": "Generar mensagem de commit",
|
||||
"gitView.commit.messagePlaceholder": "Mensagem de commit",
|
||||
"gitView.commit.push": "Push",
|
||||
"gitView.commit.pushAria": "Push",
|
||||
"gitView.commit.pushing": "Enviando...",
|
||||
"gitView.commit.push": "Commit & sync",
|
||||
"gitView.commit.pushAria": "Commit and sync",
|
||||
"gitView.commit.pushing": "Sincronizando...",
|
||||
"gitView.commit.selectFilesHint": "Selecione arquivos em Alterações para habilitar o commit.",
|
||||
"gitView.commit.title": "Commit",
|
||||
"gitView.common.cancel": "Cancelar",
|
||||
|
||||
@@ -425,9 +425,9 @@ export const dict: Record<I18nKey, string> = {
|
||||
"gitView.commit.generate": "Генерувати",
|
||||
"gitView.commit.generateAria": "Згенерувати повідомлення коміту",
|
||||
"gitView.commit.messagePlaceholder": "Повідомлення коміту",
|
||||
"gitView.commit.push": "Push",
|
||||
"gitView.commit.pushAria": "Push",
|
||||
"gitView.commit.pushing": "Push...",
|
||||
"gitView.commit.push": "Commit & sync",
|
||||
"gitView.commit.pushAria": "Commit and sync",
|
||||
"gitView.commit.pushing": "Sync...",
|
||||
"gitView.commit.selectFilesHint": "Виберіть файли в розділі «Зміни», щоб увімкнути коміт.",
|
||||
"gitView.commit.title": "Коміт",
|
||||
"gitView.common.cancel": "Скасувати",
|
||||
|
||||
@@ -425,9 +425,9 @@ export const dict: Record<I18nKey, string> = {
|
||||
'gitView.commit.generate': '生成',
|
||||
'gitView.commit.generateAria': '生成提交信息',
|
||||
'gitView.commit.messagePlaceholder': '提交信息',
|
||||
'gitView.commit.push': '推送',
|
||||
'gitView.commit.pushAria': '推送',
|
||||
'gitView.commit.pushing': '推送中...',
|
||||
'gitView.commit.push': 'Commit & sync',
|
||||
'gitView.commit.pushAria': 'Commit and sync',
|
||||
'gitView.commit.pushing': 'sync 中...',
|
||||
'gitView.commit.selectFilesHint': '在“更改”中选择文件以启用提交。',
|
||||
'gitView.commit.title': '提交',
|
||||
'gitView.common.cancel': '取消',
|
||||
|
||||
Reference in New Issue
Block a user