Browse Source

Adds force-if-includes to our force push messaging

main
Eric Amodio 1 year ago
parent
commit
8853cf844b
3 changed files with 59 additions and 13 deletions
  1. +54
    -13
      src/commands/git/push.ts
  2. +4
    -0
      src/env/node/git/localGitProvider.ts
  3. +1
    -0
      src/features.ts

+ 54
- 13
src/commands/git/push.ts View File

@ -1,6 +1,7 @@
import type { CoreGitConfiguration } from '../../constants';
import { GlyphChars } from '../../constants';
import type { Container } from '../../container';
import { Features } from '../../features';
import { getRemoteNameFromBranchName } from '../../git/models/branch';
import type { GitBranchReference, GitReference } from '../../git/models/reference';
import { getReferenceLabel, isBranchReference } from '../../git/models/reference';
@ -158,6 +159,10 @@ export class PushGitCommand extends QuickCommand {
private async *confirmStep(state: PushStepState, context: Context): AsyncStepResultGenerator<Flags[]> {
const useForceWithLease =
configuration.getAny<CoreGitConfiguration, boolean>('git.useForcePushWithLease') ?? true;
const useForceIfIncludes =
useForceWithLease &&
(configuration.getAny<CoreGitConfiguration, boolean>('git.useForcePushIfIncludes') ?? true) &&
(await this.container.git.supports(state.repos[0].uri, Features.ForceIfIncludes));
let step: QuickPickStep<FlagsQuickPickItem<Flags>>;
@ -168,11 +173,15 @@ export class PushGitCommand extends QuickCommand {
detail: `Will push ${state.repos.length} repositories`,
}),
createFlagsQuickPickItem<Flags>(state.flags, ['--force'], {
label: `Force ${this.title}${useForceWithLease ? ' (with lease)' : ''}`,
description: `--force${useForceWithLease ? '-with-lease' : ''}`,
detail: `Will force push${useForceWithLease ? ' (with lease)' : ''} ${
state.repos.length
} repositories`,
label: `Force ${this.title}${
useForceIfIncludes ? ' (with lease and if includes)' : useForceWithLease ? ' (with lease)' : ''
}`,
description: `--force${
useForceWithLease ? `-with-lease${useForceIfIncludes ? ' --force-if-includes' : ''}` : ''
}`,
detail: `Will force push${
useForceIfIncludes ? ' (with lease and if includes)' : useForceWithLease ? ' (with lease)' : ''
} ${state.repos.length} repositories`,
}),
]);
} else {
@ -230,11 +239,27 @@ export class PushGitCommand extends QuickCommand {
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
createFlagsQuickPickItem<Flags>(state.flags, ['--force'], {
label: `Force ${this.title}${useForceWithLease ? ' (with lease)' : ''}`,
description: `--force${useForceWithLease ? '-with-lease' : ''}`,
detail: `Will force push${useForceWithLease ? ' (with lease)' : ''} ${
branch?.state.ahead ? ` ${pluralize('commit', branch.state.ahead)}` : ''
}${branch.getRemoteName() ? ` to ${branch.getRemoteName()}` : ''}${
label: `Force ${this.title}${
useForceIfIncludes
? ' (with lease and if includes)'
: useForceWithLease
? ' (with lease)'
: ''
}`,
description: `--force${
useForceWithLease
? `-with-lease${useForceIfIncludes ? ' --force-if-includes' : ''}`
: ''
}`,
detail: `Will force push${
useForceIfIncludes
? ' (with lease and if includes)'
: useForceWithLease
? ' (with lease)'
: ''
} ${branch?.state.ahead ? ` ${pluralize('commit', branch.state.ahead)}` : ''}${
branch.getRemoteName() ? ` to ${branch.getRemoteName()}` : ''
}${
branch != null && branch.state.behind > 0
? `, overwriting ${pluralize('commit', branch.state.behind)}${
branch?.getRemoteName() ? ` on ${branch.getRemoteName()}` : ''
@ -363,9 +388,25 @@ export class PushGitCommand extends QuickCommand {
}),
]),
createFlagsQuickPickItem<Flags>(state.flags, ['--force'], {
label: `Force ${this.title}${useForceWithLease ? ' (with lease)' : ''}`,
description: `--force${useForceWithLease ? '-with-lease' : ''}`,
detail: `Will force push${useForceWithLease ? ' (with lease)' : ''} ${pushDetails}${
label: `Force ${this.title}${
useForceIfIncludes
? ' (with lease and if includes)'
: useForceWithLease
? ' (with lease)'
: ''
}`,
description: `--force${
useForceWithLease
? `-with-lease${useForceIfIncludes ? ' --force-if-includes' : ''}`
: ''
}`,
detail: `Will force push${
useForceIfIncludes
? ' (with lease and if includes)'
: useForceWithLease
? ' (with lease)'
: ''
} ${pushDetails}${
status != null && status.state.behind > 0
? `, overwriting ${pluralize('commit', status.state.behind)}${
status?.upstream

+ 4
- 0
src/env/node/git/localGitProvider.ts View File

@ -567,6 +567,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
supported = await this.git.isAtLeastVersion('2.35.0');
this._supportedFeatures.set(feature, supported);
return supported;
case Features.ForceIfIncludes:
supported = await this.git.isAtLeastVersion('2.30.0');
this._supportedFeatures.set(feature, supported);
return supported;
default:
return true;
}

+ 1
- 0
src/features.ts View File

@ -6,6 +6,7 @@ export const enum Features {
Timeline = 'timeline',
Worktrees = 'worktrees',
StashOnlyStaged = 'stashOnlyStaged',
ForceIfIncludes = 'forceIfIncludes',
}
export type FeatureAccess =

Loading…
Cancel
Save