Git - fix stage/unstage selected ranges in nested git repositories (#191987)

* Git - fix stage/unstage selected ranges in nested git repositories

* Remove the submodule check as it is being covered by the repository check

* Pull request feedback
This commit is contained in:
Ladislau Szomoru 2023-09-06 14:35:55 +02:00 committed by GitHub
parent 1f40d64450
commit a4e1870896
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View file

@ -5,7 +5,7 @@
import { workspace, WorkspaceFoldersChangeEvent, Uri, window, Event, EventEmitter, QuickPickItem, Disposable, SourceControl, SourceControlResourceGroup, TextEditor, Memento, commands, LogOutputChannel, l10n, ProgressLocation, WorkspaceFolder } from 'vscode';
import TelemetryReporter from '@vscode/extension-telemetry';
import { Repository, RepositoryState } from './repository';
import { IRepositoryResolver, Repository, RepositoryState } from './repository';
import { memoize, sequentialize, debounce } from './decorators';
import { dispose, anyEvent, filterEvent, isDescendant, pathEquals, toDisposable, eventToPromise } from './util';
import { Git } from './git';
@ -170,7 +170,7 @@ class UnsafeRepositoriesManager {
}
}
export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePublisherRegistry, IPostCommitCommandsProviderRegistry, IPushErrorHandlerRegistry {
export class Model implements IRepositoryResolver, IBranchProtectionProviderRegistry, IRemoteSourcePublisherRegistry, IPostCommitCommandsProviderRegistry, IPushErrorHandlerRegistry {
private _onDidOpenRepository = new EventEmitter<Repository>();
readonly onDidOpenRepository: Event<Repository> = this._onDidOpenRepository.event;
@ -578,7 +578,7 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
// Open repository
const [dotGit, repositoryRootRealPath] = await Promise.all([this.git.getRepositoryDotGit(repositoryRoot), this.getRepositoryRootRealPath(repositoryRoot)]);
const repository = new Repository(this.git.open(repositoryRoot, repositoryRootRealPath, dotGit, this.logger), this, this, this, this, this.globalState, this.logger, this.telemetryReporter);
const repository = new Repository(this.git.open(repositoryRoot, repositoryRootRealPath, dotGit, this.logger), this, this, this, this, this, this.globalState, this.logger, this.telemetryReporter);
this.open(repository);
this._closedRepositoriesManager.deleteRepository(repository.root);

View file

@ -633,6 +633,14 @@ interface BranchProtectionMatcher {
exclude?: picomatch.Matcher;
}
export interface IRepositoryResolver {
getRepository(sourceControl: SourceControl): Repository | undefined;
getRepository(resourceGroup: SourceControlResourceGroup): Repository | undefined;
getRepository(path: string): Repository | undefined;
getRepository(resource: Uri): Repository | undefined;
getRepository(hint: any): Repository | undefined;
}
export class Repository implements Disposable {
private _onDidChangeRepository = new EventEmitter<Uri>();
@ -784,6 +792,7 @@ export class Repository implements Disposable {
constructor(
private readonly repository: BaseRepository,
private readonly repositoryResolver: IRepositoryResolver,
private pushErrorHandlerRegistry: IPushErrorHandlerRegistry,
remoteSourcePublisherRegistry: IRemoteSourcePublisherRegistry,
postCommitCommandsProviderRegistry: IPostCommitCommandsProviderRegistry,
@ -1010,13 +1019,13 @@ export class Repository implements Disposable {
return;
}
// Ignore path that is inside a merge group
if (this.mergeGroup.resourceStates.some(r => r.resourceUri.path === uri.path)) {
// Ignore path that is not inside the current repository
if (this.repositoryResolver.getRepository(uri) !== this) {
return undefined;
}
// Ignore path that is inside a submodule
if (this.submodules.some(s => isDescendant(path.join(this.repository.root, s.path), uri.path))) {
// Ignore path that is inside a merge group
if (this.mergeGroup.resourceStates.some(r => r.resourceUri.path === uri.path)) {
return undefined;
}