Skip to content

Commit 38c17a6

Browse files
authored
Merge pull request #86 from bendera/fix/incorrect-recent-commit-list
fix: incorrect recent commit list
2 parents c391ab1 + 17115a5 commit 38c17a6

File tree

3 files changed

+81
-21
lines changed

3 files changed

+81
-21
lines changed

src/@types/git.d.ts

Lines changed: 35 additions & 9 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, Command } from 'vscode';
6+
import { Uri, Event, Disposable, ProviderResult, Command, CancellationToken } from 'vscode';
77
export { ProviderResult } from 'vscode';
88

99
export interface Git {
@@ -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 {
@@ -150,11 +156,15 @@ export interface FetchOptions {
150156
depth?: number;
151157
}
152158

153-
export interface BranchQuery {
154-
readonly remote?: boolean;
155-
readonly pattern?: string;
156-
readonly count?: number;
159+
export interface RefQuery {
157160
readonly contains?: string;
161+
readonly count?: number;
162+
readonly pattern?: string;
163+
readonly sort?: 'alphabetically' | 'committerdate';
164+
}
165+
166+
export interface BranchQuery extends RefQuery {
167+
readonly remote?: boolean;
158168
}
159169

160170
export interface Repository {
@@ -198,9 +208,11 @@ export interface Repository {
198208
createBranch(name: string, checkout: boolean, ref?: string): Promise<void>;
199209
deleteBranch(name: string, force?: boolean): Promise<void>;
200210
getBranch(name: string): Promise<Branch>;
201-
getBranches(query: BranchQuery): Promise<Ref[]>;
211+
getBranches(query: BranchQuery, cancellationToken?: CancellationToken): Promise<Ref[]>;
202212
setBranchUpstream(name: string, upstream: string): Promise<void>;
203213

214+
getRefs(query: RefQuery, cancellationToken?: CancellationToken): Promise<Ref[]>;
215+
204216
getMergeBase(ref1: string, ref2: string): Promise<string>;
205217

206218
tag(name: string, upstream: string): Promise<void>;
@@ -262,6 +274,16 @@ export interface PushErrorHandler {
262274
handlePushError(repository: Repository, remote: Remote, refspec: string, error: Error & { gitErrorCode: GitErrorCodes }): Promise<boolean>;
263275
}
264276

277+
export interface BranchProtection {
278+
readonly remote: string;
279+
readonly branches: string[];
280+
}
281+
282+
export interface BranchProtectionProvider {
283+
onDidChangeBranchProtection: Event<Uri>;
284+
provideBranchProtection(): BranchProtection[];
285+
}
286+
265287
export type APIState = 'uninitialized' | 'initialized';
266288

267289
export interface PublishEvent {
@@ -288,6 +310,7 @@ export interface API {
288310
registerCredentialsProvider(provider: CredentialsProvider): Disposable;
289311
registerPostCommitCommandsProvider(provider: PostCommitCommandsProvider): Disposable;
290312
registerPushErrorHandler(handler: PushErrorHandler): Disposable;
313+
registerBranchProtectionProvider(root: Uri, provider: BranchProtectionProvider): Disposable;
291314
}
292315

293316
export interface GitExtension {
@@ -344,5 +367,8 @@ export const enum GitErrorCodes {
344367
PatchDoesNotApply = 'PatchDoesNotApply',
345368
NoPathFound = 'NoPathFound',
346369
UnknownPath = 'UnknownPath',
347-
EmptyCommitMessage = 'EmptyCommitMessage'
348-
}
370+
EmptyCommitMessage = 'EmptyCommitMessage',
371+
BranchFastForwardRejected = 'BranchFastForwardRejected',
372+
BranchNotYetBorn = 'BranchNotYetBorn',
373+
TagConflict = 'TagConflict'
374+
}

src/commands/EditorController.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@ export default class EditorController {
5959
return this._primaryEditorPanel;
6060
}
6161

62-
private _handleRepositoryDidChange(repositoryInfo: RepositoryInfo) {
62+
private async _handleRepositoryDidChange(repositoryInfo: RepositoryInfo) {
6363
this._ui?.sendRepositoryInfo(repositoryInfo);
64-
this._populateCommitList();
64+
65+
const { selectedRepositoryPath } = repositoryInfo;
66+
const commits = await this._git.getRecentCommitMessagesByPath(
67+
selectedRepositoryPath
68+
);
69+
70+
this._ui?.sendRecentCommits(commits);
6571
}
6672

6773
private _handleRepositoryDidChangeBound =

src/utils/GitService.ts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ class GitService {
4040
return this.api?.repositories[0];
4141
}
4242

43+
private getRepositoryByPath(path: string): Repository | undefined {
44+
const repository = this.api?.repositories.find(
45+
(r: Repository) => r.rootUri.path === path
46+
);
47+
48+
if (repository) {
49+
return repository;
50+
}
51+
}
52+
4353
public onRepositoryDidChange(handler: RepositoryChangeCallback) {
4454
this.disposables.forEach((d) => d.dispose());
4555
this.disposables = [];
@@ -90,25 +100,43 @@ class GitService {
90100
}
91101
}
92102

93-
public async getRecentCommitMessages(limit: number = 32) {
94-
const repo = this.getSelectedRepository();
103+
public async getRepositoryRecentCommitMessages(
104+
repository: Repository,
105+
limit: number = 32
106+
) {
95107
let log;
96108

97-
if (!repo) {
98-
return Promise.resolve([]);
99-
}
100-
101109
try {
102-
log = await repo.log({ maxEntries: limit });
110+
log = await repository.log({ maxEntries: limit });
103111
} catch (er) {
104-
Promise.reject(er);
112+
throw er;
105113
}
106114

107115
if (!log) {
108-
return Promise.resolve([]);
116+
return [];
117+
}
118+
119+
return log;
120+
}
121+
122+
public async getRecentCommitMessages(limit: number = 32) {
123+
const repo = this.getSelectedRepository();
124+
125+
if (!repo) {
126+
return [];
127+
}
128+
129+
return this.getRepositoryRecentCommitMessages(repo, limit);
130+
}
131+
132+
public async getRecentCommitMessagesByPath(path: string, limit = 32) {
133+
const repo = this.getRepositoryByPath(path);
134+
135+
if (!repo) {
136+
return [];
109137
}
110138

111-
return Promise.resolve(log);
139+
return this.getRepositoryRecentCommitMessages(repo, limit);
112140
}
113141
}
114142

0 commit comments

Comments
 (0)