fix: clarify sync button and result toasts
Show sync label when no remote changes are known Report pulled file counts in sync success toasts Count pulled files correctly in VS Code sync
This commit is contained in:
@@ -948,6 +948,8 @@ export const GitView: React.FC = () => {
|
||||
if (!remote) {
|
||||
throw new Error('No remote available for sync');
|
||||
}
|
||||
let pulledFileCount = 0;
|
||||
let pushedChanges = false;
|
||||
await git.gitFetch(currentDirectory, { remote: remote.name });
|
||||
const afterFetch = await git.getGitStatus(currentDirectory);
|
||||
|
||||
@@ -956,14 +958,32 @@ export const GitView: React.FC = () => {
|
||||
toast.error(t('gitView.toast.commitOrStashBeforeSync'));
|
||||
return;
|
||||
}
|
||||
await git.gitPull(currentDirectory, getPullOptions(remote));
|
||||
const pullResult = await git.gitPull(currentDirectory, getPullOptions(remote));
|
||||
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: remote.name })
|
||||
: t('gitView.toast.syncedPulledPluralAndPushed', { count: pulledFileCount, name: remote.name })
|
||||
);
|
||||
} else if (pulledFileCount > 0) {
|
||||
toast.success(
|
||||
pulledFileCount === 1
|
||||
? t('gitView.toast.pulledFilesSingle', { count: pulledFileCount, name: remote.name })
|
||||
: t('gitView.toast.pulledFilesPlural', { count: pulledFileCount, name: remote.name })
|
||||
);
|
||||
} else if (pushedChanges) {
|
||||
toast.success(t('gitView.toast.pushedToUpstream'));
|
||||
} else {
|
||||
toast.success(t('gitView.toast.syncedChanges'));
|
||||
}
|
||||
toast.success(t('gitView.toast.syncedChanges'));
|
||||
}
|
||||
|
||||
await refreshStatusAndBranches(false);
|
||||
|
||||
@@ -54,11 +54,16 @@ export const SyncActions: React.FC<SyncActionsProps> = ({
|
||||
const blocksRebaseSync = behindCount > 0 && hasUncommittedChanges;
|
||||
const isPrimaryDisabled = disabled || syncAction !== null || isRemovingRemote || !trackingRemote || blocksRebaseSync;
|
||||
const isDropdownDisabled = disabled || syncAction !== null || isRemovingRemote || remotes.length === 0;
|
||||
const countsLabel = t('gitView.sync.syncCounts', { ahead: aheadCount, behind: behindCount });
|
||||
const hasKnownSyncWork = aheadCount > 0 || behindCount > 0;
|
||||
const primaryLabel = hasKnownSyncWork
|
||||
? t('gitView.sync.syncCounts', { ahead: aheadCount, behind: behindCount })
|
||||
: t('gitView.sync.sync');
|
||||
const tooltipLabel = blocksRebaseSync
|
||||
? t('gitView.sync.commitOrStashTooltip')
|
||||
: trackingRemote
|
||||
? t('gitView.sync.syncChangesTooltip', { ahead: aheadCount, behind: behindCount })
|
||||
? hasKnownSyncWork
|
||||
? t('gitView.sync.syncChangesTooltip', { ahead: aheadCount, behind: behindCount })
|
||||
: t('gitView.sync.syncChanges')
|
||||
: t('gitView.sync.noRemoteTooltip');
|
||||
|
||||
const handleSync = () => {
|
||||
@@ -87,7 +92,7 @@ export const SyncActions: React.FC<SyncActionsProps> = ({
|
||||
) : (
|
||||
<RiRefreshLine className="size-4" />
|
||||
)}
|
||||
<span className="whitespace-nowrap tabular-nums">{countsLabel}</span>
|
||||
<span className="whitespace-nowrap tabular-nums">{primaryLabel}</span>
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent sideOffset={8}>{tooltipLabel}</TooltipContent>
|
||||
|
||||
Reference in New Issue
Block a user