Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions extensions/git/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 13 additions & 4 deletions extensions/git/src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down