Skip to content

Commit 45710f8

Browse files
authored
Comment error on submodule repository (Creating comment failed: Error: File has been deleted.) (#5966)
Fixes #5784
1 parent 82778bd commit 45710f8

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/test/view/reviewCommentController.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe('ReviewCommentController', function () {
5959
let githubRepo: MockGitHubRepository;
6060
let reviewManager: ReviewManager;
6161
let reposManager: RepositoriesManager;
62+
let gitApiImpl: GitApiImpl;
6263

6364
beforeEach(async function () {
6465
sinon = createSandbox();
@@ -75,7 +76,7 @@ describe('ReviewCommentController', function () {
7576
const activePrViewCoordinator = new WebviewViewCoordinator(context);
7677
const createPrHelper = new CreatePullRequestHelper();
7778
Resource.initialize(context);
78-
const gitApiImpl = new GitApiImpl();
79+
gitApiImpl = new GitApiImpl();
7980
manager = new FolderRepositoryManager(0, context, repository, telemetry, gitApiImpl, credentialStore);
8081
reposManager.insertFolderManager(manager);
8182
const tree = new PullRequestChangesTreeDataProvider(context, gitApiImpl, reposManager);
@@ -169,7 +170,7 @@ describe('ReviewCommentController', function () {
169170
const localFileChanges = [createLocalFileChange(uri, fileName, repository.rootUri)];
170171
const reviewModel = new ReviewModel();
171172
reviewModel.localFileChanges = localFileChanges;
172-
const reviewCommentController = new TestReviewCommentController(reviewManager, manager, repository, reviewModel);
173+
const reviewCommentController = new TestReviewCommentController(reviewManager, manager, repository, reviewModel, gitApiImpl);
173174

174175
sinon.stub(activePullRequest, 'validateDraftMode').returns(Promise.resolve(false));
175176
sinon.stub(activePullRequest, 'getReviewThreads').returns(
@@ -234,6 +235,7 @@ describe('ReviewCommentController', function () {
234235
manager,
235236
repository,
236237
reviewModel,
238+
gitApiImpl
237239
);
238240
const thread = createGHPRCommentThread('review-1.1', uri);
239241

src/view/reviewCommentController.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as nodePath from 'path';
77
import { v4 as uuid } from 'uuid';
88
import * as vscode from 'vscode';
99
import { Repository } from '../api/api';
10+
import { GitApiImpl } from '../api/api1';
1011
import { CommentHandler, registerCommentHandler, unregisterCommentHandler } from '../commentHandlerResolver';
1112
import { DiffSide, IReviewThread, SubjectType } from '../common/comment';
1213
import { getCommentingRanges } from '../common/commentingRanges';
@@ -22,6 +23,7 @@ import { PullRequestOverviewPanel } from '../github/pullRequestOverview';
2223
import {
2324
CommentReactionHandler,
2425
createVSCodeCommentThreadForReviewThread,
26+
getRepositoryForFile,
2527
isFileInRepo,
2628
threadRange,
2729
updateCommentReviewState,
@@ -57,6 +59,7 @@ export class ReviewCommentController extends CommentControllerBase
5759
folderRepoManager: FolderRepositoryManager,
5860
private _repository: Repository,
5961
private _reviewModel: ReviewModel,
62+
private _gitApi: GitApiImpl
6063
) {
6164
super(folderRepoManager);
6265
this._context = this._folderRepoManager.context;
@@ -443,7 +446,8 @@ export class ReviewCommentController extends CommentControllerBase
443446
}
444447
}
445448

446-
if (!isFileInRepo(this._repository, document.uri)) {
449+
const bestRepoForFile = getRepositoryForFile(this._gitApi, document.uri);
450+
if (bestRepoForFile?.rootUri.toString() !== this._repository.rootUri.toString()) {
447451
if (document.uri.scheme !== 'output') {
448452
Logger.debug('No commenting ranges: File is not in the current repository.', ReviewCommentController.ID);
449453
}

src/view/reviewManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class ReviewManager {
103103
private _showPullRequest: ShowPullRequest,
104104
private readonly _activePrViewCoordinator: WebviewViewCoordinator,
105105
private _createPullRequestHelper: CreatePullRequestHelper,
106-
gitApi: GitApiImpl
106+
private _gitApi: GitApiImpl
107107
) {
108108
this._switchingToReviewMode = false;
109109
this._disposables = [];
@@ -115,7 +115,7 @@ export class ReviewManager {
115115

116116
this.registerListeners();
117117

118-
if (gitApi.state === 'initialized') {
118+
if (_gitApi.state === 'initialized') {
119119
this.updateState(true);
120120
}
121121
this.pollForStatusChange();
@@ -906,6 +906,7 @@ export class ReviewManager {
906906
this._folderRepoManager,
907907
this._repository,
908908
this._reviewModel,
909+
this._gitApi
909910
);
910911

911912
await this._reviewCommentController.initialize();

0 commit comments

Comments
 (0)