|
7 | 7 |
|
8 | 8 | import { Model } from '../model';
|
9 | 9 | import { Repository as BaseRepository, Resource } from '../repository';
|
10 |
| -import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, ForcePushMode, Ref, Submodule, Commit, Change, RepositoryUIState, Status, LogOptions, APIState, CommitOptions, RefType, CredentialsProvider, BranchQuery, PushErrorHandler, PublishEvent, FetchOptions, RemoteSourceProvider, RemoteSourcePublisher, PostCommitCommandsProvider, RefQuery, BranchProtectionProvider, InitOptions, SourceControlHistoryItemDetailsProvider } from './git'; |
| 10 | +import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, ForcePushMode, Ref, Submodule, Commit, Change, RepositoryUIState, Status, LogOptions, APIState, CommitOptions, RefType, CredentialsProvider, BranchQuery, PushErrorHandler, PublishEvent, FetchOptions, RemoteSourceProvider, RemoteSourcePublisher, PostCommitCommandsProvider, RefQuery, BranchProtectionProvider, InitOptions, SourceControlHistoryItemDetailsProvider, GitErrorCodes } from './git'; |
11 | 11 | import { Event, SourceControlInputBox, Uri, SourceControl, Disposable, commands, CancellationToken } from 'vscode';
|
12 | 12 | import { combinedDisposable, filterEvent, mapEvent } from '../util';
|
13 | 13 | import { toGitUri } from '../uri';
|
@@ -371,6 +371,27 @@ export class ApiImpl implements API {
|
371 | 371 | return result ? new ApiRepository(result) : null;
|
372 | 372 | }
|
373 | 373 |
|
| 374 | + async getRepositoryRoot(uri: Uri): Promise<Uri | null> { |
| 375 | + const repository = this.getRepository(uri); |
| 376 | + if (repository) { |
| 377 | + return repository.rootUri; |
| 378 | + } |
| 379 | + |
| 380 | + try { |
| 381 | + const root = await this.#model.git.getRepositoryRoot(uri.fsPath); |
| 382 | + return Uri.file(root); |
| 383 | + } catch (err) { |
| 384 | + if ( |
| 385 | + err.gitErrorCode === GitErrorCodes.NotAGitRepository || |
| 386 | + err.gitErrorCode === GitErrorCodes.NotASafeGitRepository |
| 387 | + ) { |
| 388 | + return null; |
| 389 | + } |
| 390 | + |
| 391 | + throw err; |
| 392 | + } |
| 393 | + } |
| 394 | + |
374 | 395 | async init(root: Uri, options?: InitOptions): Promise<Repository | null> {
|
375 | 396 | const path = root.fsPath;
|
376 | 397 | await this.#model.git.init(path, options);
|
|
0 commit comments