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:
Bohdan Triapitsyn
2026-05-06 00:12:39 +03:00
parent 16c349417f
commit 8540f51395
7 changed files with 67 additions and 20 deletions
+49 -2
View File
@@ -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 {