Skip to content

Commit

Permalink
Add support for --force-if-includes to force push
Browse files Browse the repository at this point in the history
  • Loading branch information
tats-u committed Jul 14, 2023
1 parent 406618d commit 2e3fce1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions extensions/git/package.json
Expand Up @@ -2567,6 +2567,11 @@
"default": true,
"description": "%config.useForcePushWithLease%"
},
"git.useForcePushIfIncludes": {
"type": "boolean",
"default": true,
"description": "%config.useForcePushIfIncludes%"
},
"git.confirmForcePush": {
"type": "boolean",
"default": true,
Expand Down
1 change: 1 addition & 0 deletions extensions/git/package.nls.json
Expand Up @@ -217,6 +217,7 @@
"config.autoStash": "Stash any changes before pulling and restore them after successful pull.",
"config.allowForcePush": "Controls whether force push (with or without lease) is enabled.",
"config.useForcePushWithLease": "Controls whether force pushing uses the safer force-with-lease variant.",
"config.useForcePushIfIncludes": "Controls whether force pushing uses the safer force-if-includes variant.",
"config.confirmForcePush": "Controls whether to ask for confirmation before force-pushing.",
"config.allowNoVerifyCommit": "Controls whether commits without running pre-commit and commit-msg hooks are allowed.",
"config.confirmNoVerifyCommit": "Controls whether to ask for confirmation before committing without verification.",
Expand Down
3 changes: 2 additions & 1 deletion extensions/git/src/api/git.d.ts
Expand Up @@ -16,7 +16,8 @@ export interface InputBox {

export const enum ForcePushMode {
Force,
ForceWithLease
ForceWithLease,
ForceWithLeaseIfIncludes,
}

export const enum RefType {
Expand Down
9 changes: 8 additions & 1 deletion extensions/git/src/commands.ts
Expand Up @@ -2751,6 +2751,13 @@ export class CommandCenter {
await repository.pullWithRebase(repository.HEAD);
}

private _getForcePushMode(withLease: boolean | undefined, ifIncludes: boolean | undefined): ForcePushMode {
if (!withLease) {
return ForcePushMode.Force;
}
return ifIncludes ? ForcePushMode.ForceWithLeaseIfIncludes : ForcePushMode.ForceWithLease;
}

private async _push(repository: Repository, pushOptions: PushOptions) {
const remotes = repository.remotes;

Expand Down Expand Up @@ -2778,7 +2785,7 @@ export class CommandCenter {
return;
}

forcePushMode = config.get<boolean>('useForcePushWithLease') === true ? ForcePushMode.ForceWithLease : ForcePushMode.Force;
forcePushMode = this._getForcePushMode(config.get<boolean>('useForcePushWithLease'), config.get<boolean>('useForcePushIfIncludes'));

if (config.get<boolean>('confirmForcePush')) {
const message = l10n.t('You are about to force push your changes, this can be destructive and could inadvertently overwrite changes made by others.\n\nAre you sure to continue?');
Expand Down
5 changes: 4 additions & 1 deletion extensions/git/src/git.ts
Expand Up @@ -1872,8 +1872,11 @@ export class Repository {
async push(remote?: string, name?: string, setUpstream: boolean = false, followTags = false, forcePushMode?: ForcePushMode, tags = false): Promise<void> {
const args = ['push'];

if (forcePushMode === ForcePushMode.ForceWithLease) {
if (forcePushMode === ForcePushMode.ForceWithLease || forcePushMode === ForcePushMode.ForceWithLeaseIfIncludes) {
args.push('--force-with-lease');
if (forcePushMode === ForcePushMode.ForceWithLeaseIfIncludes) {
args.push('--force-if-includes');
}
} else if (forcePushMode === ForcePushMode.Force) {
args.push('--force');
}
Expand Down

0 comments on commit 2e3fce1

Please sign in to comment.