Skip to content

Commit 5222372

Browse files
authored
Git - Add the ability to commit and not execute a post-commit command (microsoft#160527)
Add the ability to commit and not execute a post-commit command
1 parent fcde8c4 commit 5222372

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

extensions/git/src/api/git.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ export interface CommitOptions {
139139
requireUserConfig?: boolean;
140140
useEditor?: boolean;
141141
verbose?: boolean;
142-
postCommitCommand?: string;
142+
/**
143+
* string - execute the specified command after the commit operation
144+
* undefined - execute the command specified in git.postCommitCommand
145+
* after the commit operation
146+
* null - do not execute any command after the commit operation
147+
*/
148+
postCommitCommand?: string | null;
143149
}
144150

145151
export interface FetchOptions {

extensions/git/src/repository.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,9 @@ export class Repository implements Disposable {
12771277
});
12781278

12791279
// Execute post-commit command
1280-
await this.commitCommandCenter.executePostCommitCommand(opts.postCommitCommand);
1280+
if (opts.postCommitCommand !== null) {
1281+
await this.commitCommandCenter.executePostCommitCommand(opts.postCommitCommand);
1282+
}
12811283
}
12821284
}
12831285

extensions/github/src/publish.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)
199199
return;
200200
}
201201

202-
await repository.commit('first commit', { all: true });
202+
await repository.commit('first commit', { all: true, postCommitCommand: null });
203203
}
204204

205205
progress.report({ message: localize('publishing_uploading', "Uploading files"), increment: 25 });

extensions/github/src/typings/git.d.ts

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Uri, Event, Disposable, ProviderResult } from 'vscode';
6+
import { Uri, Event, Disposable, ProviderResult, Command } from 'vscode';
77
export { ProviderResult } from 'vscode';
88

99
export interface Git {
@@ -14,6 +14,11 @@ export interface InputBox {
1414
value: string;
1515
}
1616

17+
export const enum ForcePushMode {
18+
Force,
19+
ForceWithLease
20+
}
21+
1722
export const enum RefType {
1823
Head,
1924
RemoteHead,
@@ -131,6 +136,24 @@ export interface CommitOptions {
131136
signCommit?: boolean;
132137
empty?: boolean;
133138
noVerify?: boolean;
139+
requireUserConfig?: boolean;
140+
useEditor?: boolean;
141+
verbose?: boolean;
142+
/**
143+
* string - execute the specified command after the commit operation
144+
* undefined - execute the command specified in git.postCommitCommand
145+
* after the commit operation
146+
* null - do not execute any command after the commit operation
147+
*/
148+
postCommitCommand?: string | null;
149+
}
150+
151+
export interface FetchOptions {
152+
remote?: string;
153+
ref?: string;
154+
all?: boolean;
155+
prune?: boolean;
156+
depth?: number;
134157
}
135158

136159
export interface BranchQuery {
@@ -158,6 +181,8 @@ export interface Repository {
158181
show(ref: string, path: string): Promise<string>;
159182
getCommit(ref: string): Promise<Commit>;
160183

184+
add(paths: string[]): Promise<void>;
185+
revert(paths: string[]): Promise<void>;
161186
clean(paths: string[]): Promise<void>;
162187

163188
apply(patch: string, reverse?: boolean): Promise<void>;
@@ -184,16 +209,20 @@ export interface Repository {
184209

185210
getMergeBase(ref1: string, ref2: string): Promise<string>;
186211

212+
tag(name: string, upstream: string): Promise<void>;
213+
deleteTag(name: string): Promise<void>;
214+
187215
status(): Promise<void>;
188216
checkout(treeish: string): Promise<void>;
189217

190218
addRemote(name: string, url: string): Promise<void>;
191219
removeRemote(name: string): Promise<void>;
192220
renameRemote(name: string, newName: string): Promise<void>;
193221

222+
fetch(options?: FetchOptions): Promise<void>;
194223
fetch(remote?: string, ref?: string, depth?: number): Promise<void>;
195224
pull(unshallow?: boolean): Promise<void>;
196-
push(remoteName?: string, branchName?: string, setUpstream?: boolean): Promise<void>;
225+
push(remoteName?: string, branchName?: string, setUpstream?: boolean, force?: ForcePushMode): Promise<void>;
197226

198227
blame(path: string): Promise<string>;
199228
log(options?: LogOptions): Promise<Commit[]>;
@@ -231,15 +260,27 @@ export interface CredentialsProvider {
231260
getCredentials(host: Uri): ProviderResult<Credentials>;
232261
}
233262

263+
export type CommitCommand = Command & { description?: string };
264+
265+
export interface PostCommitCommandsProvider {
266+
getCommands(repository: Repository): CommitCommand[];
267+
}
268+
234269
export interface PushErrorHandler {
235270
handlePushError(repository: Repository, remote: Remote, refspec: string, error: Error & { gitErrorCode: GitErrorCodes }): Promise<boolean>;
236271
}
237272

238273
export type APIState = 'uninitialized' | 'initialized';
239274

275+
export interface PublishEvent {
276+
repository: Repository;
277+
branch?: string;
278+
}
279+
240280
export interface API {
241281
readonly state: APIState;
242282
readonly onDidChangeState: Event<APIState>;
283+
readonly onDidPublish: Event<PublishEvent>;
243284
readonly git: Git;
244285
readonly repositories: Repository[];
245286
readonly onDidOpenRepository: Event<Repository>;
@@ -248,10 +289,12 @@ export interface API {
248289
toGitUri(uri: Uri, ref: string): Uri;
249290
getRepository(uri: Uri): Repository | null;
250291
init(root: Uri): Promise<Repository | null>;
292+
openRepository(root: Uri): Promise<Repository | null>
251293

252294
registerRemoteSourcePublisher(publisher: RemoteSourcePublisher): Disposable;
253295
registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable;
254296
registerCredentialsProvider(provider: CredentialsProvider): Disposable;
297+
registerPostCommitCommandsProvider(provider: PostCommitCommandsProvider): Disposable;
255298
registerPushErrorHandler(handler: PushErrorHandler): Disposable;
256299
}
257300

@@ -263,7 +306,7 @@ export interface GitExtension {
263306
/**
264307
* Returns a specific API version.
265308
*
266-
* Throws error if git extension is disabled. You can listed to the
309+
* Throws error if git extension is disabled. You can listen to the
267310
* [GitExtension.onDidChangeEnablement](#GitExtension.onDidChangeEnablement) event
268311
* to know when the extension becomes enabled/disabled.
269312
*
@@ -309,4 +352,5 @@ export const enum GitErrorCodes {
309352
PatchDoesNotApply = 'PatchDoesNotApply',
310353
NoPathFound = 'NoPathFound',
311354
UnknownPath = 'UnknownPath',
355+
EmptyCommitMessage = 'EmptyCommitMessage'
312356
}

0 commit comments

Comments
 (0)