Skip to content

Commit 1c74bee

Browse files
committed
feat: git diff/status mention
1 parent ae1df32 commit 1c74bee

File tree

10 files changed

+915
-18
lines changed

10 files changed

+915
-18
lines changed

src/@types/vscode.git.ts

Lines changed: 395 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,395 @@
1+
import { Uri, Event, Disposable, ProviderResult, Command, CancellationToken } from 'vscode';
2+
3+
export interface Git {
4+
readonly path: string;
5+
}
6+
7+
export interface InputBox {
8+
value: string;
9+
}
10+
11+
export const enum ForcePushMode {
12+
Force,
13+
ForceWithLease,
14+
ForceWithLeaseIfIncludes,
15+
}
16+
17+
export const enum RefType {
18+
Head,
19+
RemoteHead,
20+
Tag
21+
}
22+
23+
export interface Ref {
24+
readonly type: RefType;
25+
readonly name?: string;
26+
readonly commit?: string;
27+
readonly remote?: string;
28+
}
29+
30+
export interface UpstreamRef {
31+
readonly remote: string;
32+
readonly name: string;
33+
readonly commit?: string;
34+
}
35+
36+
export interface Branch extends Ref {
37+
readonly upstream?: UpstreamRef;
38+
readonly ahead?: number;
39+
readonly behind?: number;
40+
}
41+
42+
export interface CommitShortStat {
43+
readonly files: number;
44+
readonly insertions: number;
45+
readonly deletions: number;
46+
}
47+
48+
export interface Commit {
49+
readonly hash: string;
50+
readonly message: string;
51+
readonly parents: string[];
52+
readonly authorDate?: Date;
53+
readonly authorName?: string;
54+
readonly authorEmail?: string;
55+
readonly commitDate?: Date;
56+
readonly shortStat?: CommitShortStat;
57+
}
58+
59+
export interface Submodule {
60+
readonly name: string;
61+
readonly path: string;
62+
readonly url: string;
63+
}
64+
65+
export interface Remote {
66+
readonly name: string;
67+
readonly fetchUrl?: string;
68+
readonly pushUrl?: string;
69+
readonly isReadOnly: boolean;
70+
}
71+
72+
export enum Status {
73+
INDEX_MODIFIED,
74+
INDEX_ADDED,
75+
INDEX_DELETED,
76+
INDEX_RENAMED,
77+
INDEX_COPIED,
78+
79+
MODIFIED,
80+
DELETED,
81+
UNTRACKED,
82+
IGNORED,
83+
INTENT_TO_ADD,
84+
INTENT_TO_RENAME,
85+
TYPE_CHANGED,
86+
87+
ADDED_BY_US,
88+
ADDED_BY_THEM,
89+
DELETED_BY_US,
90+
DELETED_BY_THEM,
91+
BOTH_ADDED,
92+
BOTH_DELETED,
93+
BOTH_MODIFIED
94+
}
95+
96+
export interface Change {
97+
/**
98+
* Returns either `originalUri` or `renameUri`, depending
99+
* on whether this change is a rename change. When
100+
* in doubt always use `uri` over the other two alternatives.
101+
*/
102+
readonly uri: Uri;
103+
readonly originalUri: Uri;
104+
readonly renameUri: Uri | undefined;
105+
readonly status: Status;
106+
}
107+
108+
export interface RepositoryState {
109+
readonly HEAD: Branch | undefined;
110+
readonly refs: Ref[];
111+
readonly remotes: Remote[];
112+
readonly submodules: Submodule[];
113+
readonly rebaseCommit: Commit | undefined;
114+
115+
readonly mergeChanges: Change[];
116+
readonly indexChanges: Change[];
117+
readonly workingTreeChanges: Change[];
118+
readonly untrackedChanges: Change[];
119+
120+
readonly onDidChange: Event<void>;
121+
}
122+
123+
export interface RepositoryUIState {
124+
readonly selected: boolean;
125+
readonly onDidChange: Event<void>;
126+
}
127+
128+
export interface LogOptions {
129+
readonly maxEntries?: number;
130+
readonly path?: string;
131+
readonly range?: string;
132+
readonly reverse?: boolean;
133+
readonly sortByAuthorDate?: boolean;
134+
readonly shortStats?: boolean;
135+
readonly author?: string;
136+
readonly refNames?: string[];
137+
readonly maxParents?: number;
138+
readonly skip?: number;
139+
}
140+
141+
export interface CommitOptions {
142+
all?: boolean | 'tracked';
143+
amend?: boolean;
144+
signoff?: boolean;
145+
signCommit?: boolean;
146+
empty?: boolean;
147+
noVerify?: boolean;
148+
requireUserConfig?: boolean;
149+
useEditor?: boolean;
150+
verbose?: boolean;
151+
postCommitCommand?: string | null;
152+
}
153+
154+
export interface FetchOptions {
155+
remote?: string;
156+
ref?: string;
157+
all?: boolean;
158+
prune?: boolean;
159+
depth?: number;
160+
}
161+
162+
export interface InitOptions {
163+
defaultBranch?: string;
164+
}
165+
166+
export interface RefQuery {
167+
readonly contains?: string;
168+
readonly count?: number;
169+
readonly pattern?: string | string[];
170+
readonly sort?: 'alphabetically' | 'committerdate';
171+
}
172+
173+
export interface BranchQuery extends RefQuery {
174+
readonly remote?: boolean;
175+
}
176+
177+
export interface Repository {
178+
readonly rootUri: Uri;
179+
readonly inputBox: InputBox;
180+
readonly state: RepositoryState;
181+
readonly ui: RepositoryUIState;
182+
183+
readonly onDidCommit: Event<void>;
184+
185+
getConfigs(): Promise<{ key: string; value: string; }[]>;
186+
getConfig(key: string): Promise<string>;
187+
setConfig(key: string, value: string): Promise<string>;
188+
getGlobalConfig(key: string): Promise<string>;
189+
190+
getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>;
191+
detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }>;
192+
buffer(ref: string, path: string): Promise<Buffer>;
193+
show(ref: string, path: string): Promise<string>;
194+
getCommit(ref: string): Promise<Commit>;
195+
196+
add(paths: string[]): Promise<void>;
197+
revert(paths: string[]): Promise<void>;
198+
clean(paths: string[]): Promise<void>;
199+
200+
apply(patch: string, reverse?: boolean): Promise<void>;
201+
diff(cached?: boolean): Promise<string>;
202+
diffWithHEAD(): Promise<Change[]>;
203+
diffWithHEAD(path: string): Promise<string>;
204+
diffWith(ref: string): Promise<Change[]>;
205+
diffWith(ref: string, path: string): Promise<string>;
206+
diffIndexWithHEAD(): Promise<Change[]>;
207+
diffIndexWithHEAD(path: string): Promise<string>;
208+
diffIndexWith(ref: string): Promise<Change[]>;
209+
diffIndexWith(ref: string, path: string): Promise<string>;
210+
diffBlobs(object1: string, object2: string): Promise<string>;
211+
diffBetween(ref1: string, ref2: string): Promise<Change[]>;
212+
diffBetween(ref1: string, ref2: string, path: string): Promise<string>;
213+
214+
hashObject(data: string): Promise<string>;
215+
216+
createBranch(name: string, checkout: boolean, ref?: string): Promise<void>;
217+
deleteBranch(name: string, force?: boolean): Promise<void>;
218+
getBranch(name: string): Promise<Branch>;
219+
getBranches(query: BranchQuery, cancellationToken?: CancellationToken): Promise<Ref[]>;
220+
getBranchBase(name: string): Promise<Branch | undefined>;
221+
setBranchUpstream(name: string, upstream: string): Promise<void>;
222+
223+
getMergeBase(ref1: string, ref2: string): Promise<string | undefined>;
224+
225+
tag(name: string, upstream: string): Promise<void>;
226+
deleteTag(name: string): Promise<void>;
227+
228+
status(): Promise<void>;
229+
checkout(treeish: string): Promise<void>;
230+
231+
addRemote(name: string, url: string): Promise<void>;
232+
removeRemote(name: string): Promise<void>;
233+
renameRemote(name: string, newName: string): Promise<void>;
234+
235+
fetch(options?: FetchOptions): Promise<void>;
236+
fetch(remote?: string, ref?: string, depth?: number): Promise<void>;
237+
pull(unshallow?: boolean): Promise<void>;
238+
push(remoteName?: string, branchName?: string, setUpstream?: boolean, force?: ForcePushMode): Promise<void>;
239+
240+
blame(path: string): Promise<string>;
241+
log(options?: LogOptions): Promise<Commit[]>;
242+
243+
commit(message: string, opts?: CommitOptions): Promise<void>;
244+
merge(ref: string): Promise<void>;
245+
mergeAbort(): Promise<void>;
246+
247+
applyStash(index?: number): Promise<void>;
248+
popStash(index?: number): Promise<void>;
249+
dropStash(index?: number): Promise<void>;
250+
}
251+
252+
export interface RemoteSource {
253+
readonly name: string;
254+
readonly description?: string;
255+
readonly url: string | string[];
256+
}
257+
258+
export interface RemoteSourceProvider {
259+
readonly name: string;
260+
readonly icon?: string;
261+
readonly supportsQuery?: boolean;
262+
getRemoteSources(query?: string): ProviderResult<RemoteSource[]>;
263+
getBranches?(url: string): ProviderResult<string[]>;
264+
publishRepository?(repository: Repository): Promise<void>;
265+
}
266+
267+
export interface RemoteSourcePublisher {
268+
readonly name: string;
269+
readonly icon?: string;
270+
publishRepository(repository: Repository): Promise<void>;
271+
}
272+
273+
export interface Credentials {
274+
readonly username: string;
275+
readonly password: string;
276+
}
277+
278+
export interface CredentialsProvider {
279+
getCredentials(host: Uri): ProviderResult<Credentials>;
280+
}
281+
282+
export interface PostCommitCommandsProvider {
283+
getCommands(repository: Repository): Command[];
284+
}
285+
286+
export interface PushErrorHandler {
287+
handlePushError(repository: Repository, remote: Remote, refspec: string, error: Error & { gitErrorCode: GitErrorCodes }): Promise<boolean>;
288+
}
289+
290+
export interface BranchProtection {
291+
readonly remote: string;
292+
readonly rules: BranchProtectionRule[];
293+
}
294+
295+
export interface BranchProtectionRule {
296+
readonly include?: string[];
297+
readonly exclude?: string[];
298+
}
299+
300+
export interface BranchProtectionProvider {
301+
onDidChangeBranchProtection: Event<Uri>;
302+
provideBranchProtection(): BranchProtection[];
303+
}
304+
305+
export type APIState = 'uninitialized' | 'initialized';
306+
307+
export interface PublishEvent {
308+
repository: Repository;
309+
branch?: string;
310+
}
311+
312+
export interface API {
313+
readonly state: APIState;
314+
readonly onDidChangeState: Event<APIState>;
315+
readonly onDidPublish: Event<PublishEvent>;
316+
readonly git: Git;
317+
readonly repositories: Repository[];
318+
readonly onDidOpenRepository: Event<Repository>;
319+
readonly onDidCloseRepository: Event<Repository>;
320+
321+
toGitUri(uri: Uri, ref: string): Uri;
322+
getRepository(uri: Uri): Repository | null;
323+
init(root: Uri, options?: InitOptions): Promise<Repository | null>;
324+
openRepository(root: Uri): Promise<Repository | null>
325+
326+
registerRemoteSourcePublisher(publisher: RemoteSourcePublisher): Disposable;
327+
registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable;
328+
registerCredentialsProvider(provider: CredentialsProvider): Disposable;
329+
registerPostCommitCommandsProvider(provider: PostCommitCommandsProvider): Disposable;
330+
registerPushErrorHandler(handler: PushErrorHandler): Disposable;
331+
registerBranchProtectionProvider(root: Uri, provider: BranchProtectionProvider): Disposable;
332+
}
333+
334+
export interface GitExtension {
335+
readonly enabled: boolean;
336+
readonly onDidChangeEnablement: Event<boolean>;
337+
338+
/**
339+
* Returns a specific API version.
340+
*
341+
* Throws error if git extension is disabled. You can listen to the
342+
* [GitExtension.onDidChangeEnablement](#GitExtension.onDidChangeEnablement) event
343+
* to know when the extension becomes enabled/disabled.
344+
*
345+
* @param version Version number.
346+
* @returns API instance
347+
*/
348+
getAPI(version: 1): API;
349+
}
350+
351+
export const enum GitErrorCodes {
352+
BadConfigFile = 'BadConfigFile',
353+
AuthenticationFailed = 'AuthenticationFailed',
354+
NoUserNameConfigured = 'NoUserNameConfigured',
355+
NoUserEmailConfigured = 'NoUserEmailConfigured',
356+
NoRemoteRepositorySpecified = 'NoRemoteRepositorySpecified',
357+
NotAGitRepository = 'NotAGitRepository',
358+
NotAtRepositoryRoot = 'NotAtRepositoryRoot',
359+
Conflict = 'Conflict',
360+
StashConflict = 'StashConflict',
361+
UnmergedChanges = 'UnmergedChanges',
362+
PushRejected = 'PushRejected',
363+
ForcePushWithLeaseRejected = 'ForcePushWithLeaseRejected',
364+
ForcePushWithLeaseIfIncludesRejected = 'ForcePushWithLeaseIfIncludesRejected',
365+
RemoteConnectionError = 'RemoteConnectionError',
366+
DirtyWorkTree = 'DirtyWorkTree',
367+
CantOpenResource = 'CantOpenResource',
368+
GitNotFound = 'GitNotFound',
369+
CantCreatePipe = 'CantCreatePipe',
370+
PermissionDenied = 'PermissionDenied',
371+
CantAccessRemote = 'CantAccessRemote',
372+
RepositoryNotFound = 'RepositoryNotFound',
373+
RepositoryIsLocked = 'RepositoryIsLocked',
374+
BranchNotFullyMerged = 'BranchNotFullyMerged',
375+
NoRemoteReference = 'NoRemoteReference',
376+
InvalidBranchName = 'InvalidBranchName',
377+
BranchAlreadyExists = 'BranchAlreadyExists',
378+
NoLocalChanges = 'NoLocalChanges',
379+
NoStashFound = 'NoStashFound',
380+
LocalChangesOverwritten = 'LocalChangesOverwritten',
381+
NoUpstreamBranch = 'NoUpstreamBranch',
382+
IsInSubmodule = 'IsInSubmodule',
383+
WrongCase = 'WrongCase',
384+
CantLockRef = 'CantLockRef',
385+
CantRebaseMultipleBranches = 'CantRebaseMultipleBranches',
386+
PatchDoesNotApply = 'PatchDoesNotApply',
387+
NoPathFound = 'NoPathFound',
388+
UnknownPath = 'UnknownPath',
389+
EmptyCommitMessage = 'EmptyCommitMessage',
390+
BranchFastForwardRejected = 'BranchFastForwardRejected',
391+
BranchNotYetBorn = 'BranchNotYetBorn',
392+
TagConflict = 'TagConflict',
393+
CherryPickEmpty = 'CherryPickEmpty',
394+
CherryPickConflict = 'CherryPickConflict'
395+
}

0 commit comments

Comments
 (0)