Browse Source

Closes #1550 - allow force-push for non-HEAD commits and from commit widget (#2132)

* update vscode git api
* force-push for non-HEAD commit & commit widget
main
Nafiur Rahman Khadem 2 years ago
committed by GitHub
parent
commit
957e76df2d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 8 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +2
    -1
      package.json
  3. +42
    -4
      src/@types/vscode.git.d.ts
  4. +6
    -0
      src/@types/vscode.git.enums.ts
  5. +2
    -1
      src/git/gitProvider.ts
  6. +3
    -2
      src/git/models/repository.ts

+ 1
- 0
CHANGELOG.md View File

@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed
- Fixes [#1550](https://github.com/gitkraken/vscode-gitlens/issues/1550) - Push button in commit widget does not trigger "Push force" when ALT is pressed.
- Fixes [#1991](https://github.com/gitkraken/vscode-gitlens/issues/1991) - Git lens status bar entry has an incomprehensible accessibility label
- Fixes [#2125](https://github.com/gitkraken/vscode-gitlens/issues/2125) - "git log" command in version 12.x is very slow
- Fixes [#2121](https://github.com/gitkraken/vscode-gitlens/issues/2121) - Typo in GitLens header — thanks to [PR #2122](https://github.com/gitkraken/vscode-gitlens/pull/2122) by Chase Knowlden ([@ChaseKnowlden](https://github.com/ChaseKnowlden))

+ 2
- 1
package.json View File

@ -8806,7 +8806,8 @@
{
"command": "gitlens.views.push",
"when": "gitlens:hasRemotes && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:commit\b(?=.*?\b\+current\b)(?=.*?\b\+unpublished\b)(?=.*?\b\+HEAD\b)/",
"group": "inline@96"
"group": "inline@96",
"alt": "gitlens.views.pushWithForce"
},
{
"command": "gitlens.views.pushToCommit",

+ 42
- 4
src/@types/vscode.git.d.ts View File

@ -3,9 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Disposable, Event, ProviderResult, Uri } from 'vscode';
import { Disposable, Event, ProviderResult, Uri, Command } from 'vscode';
import { GitErrorCodes, RefType, Status } from '../@types/vscode.git.enums';
import { GitErrorCodes, RefType, Status, ForcePushMode } from '../@types/vscode.git.enums';
export interface Git {
readonly path: string;
@ -102,6 +102,19 @@ export interface CommitOptions {
signoff?: boolean;
signCommit?: boolean;
empty?: boolean;
noVerify?: boolean;
requireUserConfig?: boolean;
useEditor?: boolean;
verbose?: boolean;
postCommitCommand?: string;
}
export interface FetchOptions {
remote?: string;
ref?: string;
all?: boolean;
prune?: boolean;
depth?: number;
}
export interface BranchQuery {
@ -128,6 +141,8 @@ export interface Repository {
show(ref: string, path: string): Promise<string>;
getCommit(ref: string): Promise<Commit>;
add(paths: string[]): Promise<void>;
revert(paths: string[]): Promise<void>;
clean(paths: string[]): Promise<void>;
apply(patch: string, reverse?: boolean): Promise<void>;
@ -154,6 +169,9 @@ export interface Repository {
getMergeBase(ref1: string, ref2: string): Promise<string>;
tag(name: string, upstream: string): Promise<void>;
deleteTag(name: string): Promise<void>;
status(): Promise<void>;
checkout(treeish: string): Promise<void>;
@ -161,9 +179,10 @@ export interface Repository {
removeRemote(name: string): Promise<void>;
renameRemote(name: string, newName: string): Promise<void>;
fetch(options?: FetchOptions): Promise<void>;
fetch(remote?: string, ref?: string, depth?: number): Promise<void>;
pull(unshallow?: boolean): Promise<void>;
push(remoteName?: string, branchName?: string, setUpstream?: boolean): Promise<void>;
push(remoteName?: string, branchName?: string, setUpstream?: boolean, force?: ForcePushMode): Promise<void>;
blame(path: string): Promise<string>;
log(options?: LogOptions): Promise<Commit[]>;
@ -182,9 +201,16 @@ export interface RemoteSourceProvider {
readonly icon?: string; // codicon name
readonly supportsQuery?: boolean;
getRemoteSources(query?: string): ProviderResult<RemoteSource[]>;
getBranches?(url: string): ProviderResult<string[]>;
publishRepository?(repository: Repository): Promise<void>;
}
export interface RemoteSourcePublisher {
readonly name: string;
readonly icon?: string; // codicon name
publishRepository(repository: Repository): Promise<void>;
}
export interface Credentials {
readonly username: string;
readonly password: string;
@ -194,6 +220,10 @@ export interface CredentialsProvider {
getCredentials(host: Uri): ProviderResult<Credentials>;
}
export interface PostCommitCommandsProvider {
getCommands(repository: Repository): Command[];
}
export interface PushErrorHandler {
handlePushError(
repository: Repository,
@ -205,9 +235,15 @@ export interface PushErrorHandler {
export type APIState = 'uninitialized' | 'initialized';
export interface PublishEvent {
repository: Repository;
branch?: string;
}
export interface API {
readonly state: APIState;
readonly onDidChangeState: Event<APIState>;
readonly onDidPublish: Event<PublishEvent>;
readonly git: Git;
readonly repositories: Repository[];
readonly onDidOpenRepository: Event<Repository>;
@ -218,8 +254,10 @@ export interface API {
init(root: Uri): Promise<Repository | null>;
openRepository?(root: Uri): Promise<Repository | null>;
registerRemoteSourcePublisher(publisher: RemoteSourcePublisher): Disposable;
registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable;
registerCredentialsProvider(provider: CredentialsProvider): Disposable;
registerPostCommitCommandsProvider(provider: PostCommitCommandsProvider): Disposable;
registerPushErrorHandler(handler: PushErrorHandler): Disposable;
}
@ -230,7 +268,7 @@ export interface GitExtension {
/**
* Returns a specific API version.
*
* Throws error if git extension is disabled. You can listed to the
* Throws error if git extension is disabled. You can listen to the
* [GitExtension.onDidChangeEnablement](#GitExtension.onDidChangeEnablement) event
* to know when the extension becomes enabled/disabled.
*

+ 6
- 0
src/@types/vscode.git.enums.ts View File

@ -3,6 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export const enum ForcePushMode {
Force,
ForceWithLease
}
export const enum RefType {
Head,
RemoteHead,
@ -67,4 +72,5 @@ export const enum GitErrorCodes {
PatchDoesNotApply = 'PatchDoesNotApply',
NoPathFound = 'NoPathFound',
UnknownPath = 'UnknownPath',
EmptyCommitMessage = 'EmptyCommitMessage'
}

+ 2
- 1
src/git/gitProvider.ts View File

@ -1,5 +1,6 @@
import { Disposable, Event, Range, TextDocument, Uri, WorkspaceFolder } from 'vscode';
import type { Commit, InputBox } from '../@types/vscode.git';
import { ForcePushMode } from '../@types/vscode.git.enums';
import { Features } from '../features';
import type { GitUri } from './gitUri';
import type {
@ -56,7 +57,7 @@ export interface ScmRepository {
readonly inputBox: InputBox;
getCommit(ref: string): Promise<Commit>;
push(remoteName?: string, branchName?: string, setUpstream?: boolean): Promise<void>;
push(remoteName?: string, branchName?: string, setUpstream?: boolean, force?: ForcePushMode): Promise<void>;
}
export interface PagedResult<T> {

+ 3
- 2
src/git/models/repository.ts View File

@ -10,6 +10,7 @@ import {
workspace,
WorkspaceFolder,
} from 'vscode';
import { ForcePushMode } from '../../@types/vscode.git.enums';
import type { CreatePullRequestActionContext } from '../../api/gitlens';
import { configuration } from '../../configuration';
import { CoreGitCommands, CoreGitConfiguration, Schemes } from '../../constants';
@ -772,7 +773,7 @@ export class Repository implements Disposable {
this.path,
));
} else {
await repo?.push(branch.getRemoteName(), branch.name);
await repo?.push(branch.getRemoteName(), branch.name, undefined, options?.force ? ForcePushMode.ForceWithLease : undefined);
}
}
} else if (options?.reference != null) {
@ -782,7 +783,7 @@ export class Repository implements Disposable {
const branch = await this.getBranch();
if (branch == null) return;
await repo?.push(branch.getRemoteName(), `${options.reference.ref}:${branch.getNameWithoutRemote()}`);
await repo?.push(branch.getRemoteName(), `${options.reference.ref}:${branch.getNameWithoutRemote()}`, undefined, options?.force ? ForcePushMode.ForceWithLease : undefined);
} else {
void (await executeCoreGitCommand(
options?.force ? CoreGitCommands.PushForce : CoreGitCommands.Push,

||||||
x
 
000:0
Loading…
Cancel
Save