Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/layout/state/appStateShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const DEFAULT_SETTINGS: AppSettingsDto = {
export type RunGitCommandOptions = {
skipDirtyGuard?: boolean;
skipSecretScan?: boolean;
skipAutoSetUpstreamOnPushFailure?: boolean;
};

export const GUARDED_COMMANDS = new Set(['checkout', 'merge', 'reset']);
Expand Down Expand Up @@ -57,4 +58,3 @@ export const DEFAULT_SIDEBAR_COLLAPSE_STATE: SidebarCollapseState = {
export const DEFAULT_SIDEBAR_GENERAL_COLLAPSE_STATE: SidebarGeneralCollapseState = {
repoPanelCollapsed: false,
};

31 changes: 30 additions & 1 deletion src/components/layout/useAppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ export const useAppState = () => {
if (!window.electronAPI || !workspace.activeRepo || args.length === 0) return false;

const command = args[0];
const normalizedError = (value: unknown) => String(value || '').toLowerCase();
const isMissingUpstreamError = (value: unknown) => {
const message = normalizedError(value);
return (
message.includes('has no upstream branch')
|| message.includes('no upstream branch')
|| message.includes('--set-upstream')
|| message.includes('set-upstream')
);
};
const tryAutoSetUpstreamPush = async (failureMessage: unknown): Promise<boolean> => {
if (command !== 'push' || options?.skipAutoSetUpstreamOnPushFailure || !isMissingUpstreamError(failureMessage)) {
return false;
}

const fallbackArgs = ['push', ...args.slice(1), '-u', 'origin', 'HEAD'];
const fallbackSuccess = await runGitCommand(
fallbackArgs,
tr('Branch gepusht und Upstream gesetzt.', 'Pushed branch and set upstream.'),
tr('Push mit Upstream wird ausgefuehrt...', 'Running push with upstream...'),
{ ...options, skipAutoSetUpstreamOnPushFailure: true },
);
return fallbackSuccess;
};
const shouldGuard = settings.confirmDangerousOps && !options?.skipDirtyGuard && GUARDED_COMMANDS.has(command);
const shouldScanPushSecrets =
command === 'push'
Expand Down Expand Up @@ -305,6 +329,9 @@ export const useAppState = () => {
triggerRefresh();
return true;
}
if (await tryAutoSetUpstreamPush(r.error)) {
return true;
}
const mergeInProgress = isMergeInProgressError(r.error);
triggerRefresh();
try {
Expand Down Expand Up @@ -345,6 +372,9 @@ export const useAppState = () => {
setGitActionToast({ msg: r.error || tr('Fehler beim Ausführen von git.', 'Error while running git.'), isError: true });
return false;
} catch (e: any) {
if (await tryAutoSetUpstreamPush(e?.message)) {
return true;
}
const mergeInProgress = isMergeInProgressError(e?.message);
triggerRefresh();
try {
Expand Down Expand Up @@ -1068,4 +1098,3 @@ export const useAppState = () => {




Loading