Skip to content

Commit 4048c9b

Browse files
committed
Moves merge conflict check into branch provider
1 parent 246e12e commit 4048c9b

File tree

7 files changed

+51
-66
lines changed

7 files changed

+51
-66
lines changed

src/commands/git/merge.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,9 @@ export class MergeGitCommand extends QuickCommand<State> {
290290
let potentialConflict;
291291
const subscription = await this.container.subscription.getSubscription();
292292
if (isSubscriptionStatePaidOrTrial(subscription?.state)) {
293-
potentialConflict = this.container.git.getPotentialMergeOrRebaseConflict(
294-
state.repo.path,
295-
context.destination.name,
296-
state.reference.ref,
297-
);
293+
potentialConflict = state.repo.git
294+
.branches()
295+
.getPotentialMergeOrRebaseConflict?.(context.destination.name, state.reference.ref);
298296
}
299297

300298
let step: QuickPickStep<DirectiveQuickPickItem | FlagsQuickPickItem<Flags>>;

src/commands/git/rebase.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,9 @@ export class RebaseGitCommand extends QuickCommand<State> {
282282
let potentialConflict;
283283
const subscription = await this.container.subscription.getSubscription();
284284
if (isSubscriptionStatePaidOrTrial(subscription?.state)) {
285-
potentialConflict = this.container.git.getPotentialMergeOrRebaseConflict(
286-
state.repo.path,
287-
context.branch.name,
288-
state.destination.ref,
289-
);
285+
potentialConflict = state.repo.git
286+
.branches()
287+
.getPotentialMergeOrRebaseConflict?.(context.branch.name, state.destination.ref);
290288
}
291289

292290
let step: QuickPickStep<DirectiveQuickPickItem | FlagsQuickPickItem<Flags>>;

src/env/node/git/localGitProvider.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ import type {
7878
GitGraphRowTag,
7979
} from '../../../git/models/graph';
8080
import type { GitLog } from '../../../git/models/log';
81-
import type { MergeConflict } from '../../../git/models/mergeConflict';
8281
import type { GitBranchReference, GitReference } from '../../../git/models/reference';
8382
import { createReference, isBranchReference } from '../../../git/models/reference.utils';
8483
import type { GitReflog } from '../../../git/models/reflog';
@@ -128,7 +127,6 @@ import {
128127
parseGitLogSimpleFormat,
129128
parseGitLogSimpleRenamed,
130129
} from '../../../git/parsers/logParser';
131-
import { parseMergeTreeConflict } from '../../../git/parsers/mergeTreeParser';
132130
import { parseGitRefLog, parseGitRefLogDefaultFormat } from '../../../git/parsers/reflogParser';
133131
import { parseGitLsFiles, parseGitTree } from '../../../git/parsers/treeParser';
134132
import type { GitSearch, GitSearchResultData, GitSearchResults } from '../../../git/search';
@@ -4971,43 +4969,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
49714969
return undefined;
49724970
}
49734971
}
4974-
4975-
@log()
4976-
async getPotentialMergeOrRebaseConflict(
4977-
repoPath: string,
4978-
branch: string,
4979-
targetBranch: string,
4980-
): Promise<MergeConflict | undefined> {
4981-
const scope = getLogScope();
4982-
4983-
try {
4984-
// If we have don't have Git v2.33+, just return
4985-
if (!(await this.git.isAtLeastVersion('2.33'))) {
4986-
return undefined;
4987-
}
4988-
4989-
let data;
4990-
try {
4991-
data = await this.git.merge_tree(repoPath, branch, targetBranch, '-z', '--name-only', '--no-messages');
4992-
} catch (ex) {
4993-
Logger.error(ex, scope);
4994-
}
4995-
if (!data) return undefined;
4996-
4997-
const mergeConflict = parseMergeTreeConflict(data);
4998-
if (!mergeConflict.conflicts.length) return undefined;
4999-
5000-
return {
5001-
repoPath: repoPath,
5002-
branch: branch,
5003-
target: targetBranch,
5004-
files: mergeConflict.conflicts,
5005-
};
5006-
} catch (ex) {
5007-
Logger.error(ex, scope);
5008-
throw ex;
5009-
}
5010-
}
50114972
}
50124973

50134974
async function getEncoding(uri: Uri): Promise<string> {

src/env/node/git/operations/branches.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import type {
99
} from '../../../../git/gitProvider';
1010
import { GitBranch } from '../../../../git/models/branch';
1111
import { isDetachedHead } from '../../../../git/models/branch.utils';
12+
import type { MergeConflict } from '../../../../git/models/mergeConflict';
1213
import { createRevisionRange } from '../../../../git/models/revision.utils';
1314
import { parseGitBranches } from '../../../../git/parsers/branchParser';
15+
import { parseMergeTreeConflict } from '../../../../git/parsers/mergeTreeParser';
1416
import type { BranchSortOptions } from '../../../../git/utils/vscode/sorting';
1517
import { sortBranches, sortContributors } from '../../../../git/utils/vscode/sorting';
1618
import { filterMap } from '../../../../system/array';
@@ -306,6 +308,43 @@ export class BranchesGitProvider implements GitProviderBranches {
306308
await this.git.branch(repoPath, name, ref);
307309
}
308310

311+
@log()
312+
async getPotentialMergeOrRebaseConflict(
313+
repoPath: string,
314+
branch: string,
315+
targetBranch: string,
316+
): Promise<MergeConflict | undefined> {
317+
const scope = getLogScope();
318+
319+
try {
320+
// If we have don't have Git v2.33+, just return
321+
if (!(await this.git.isAtLeastVersion('2.33'))) {
322+
return undefined;
323+
}
324+
325+
let data;
326+
try {
327+
data = await this.git.merge_tree(repoPath, branch, targetBranch, '-z', '--name-only', '--no-messages');
328+
} catch (ex) {
329+
Logger.error(ex, scope);
330+
}
331+
if (!data) return undefined;
332+
333+
const mergeConflict = parseMergeTreeConflict(data);
334+
if (!mergeConflict.conflicts.length) return undefined;
335+
336+
return {
337+
repoPath: repoPath,
338+
branch: branch,
339+
target: targetBranch,
340+
files: mergeConflict.conflicts,
341+
};
342+
} catch (ex) {
343+
Logger.error(ex, scope);
344+
throw ex;
345+
}
346+
}
347+
309348
@log({ exit: true })
310349
async getBaseBranchName(repoPath: string, ref: string): Promise<string | undefined> {
311350
try {

src/git/gitProvider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,6 @@ export interface GitProviderRepository {
309309
skip?: number | undefined;
310310
},
311311
): Promise<GitReflog | undefined>;
312-
getPotentialMergeOrRebaseConflict?(
313-
repoPath: string,
314-
branch: string,
315-
targetBranch: string,
316-
): Promise<MergeConflict | undefined>;
317312
getRevisionContent(repoPath: string, path: string, ref: string): Promise<Uint8Array | undefined>;
318313
getTreeEntryForRevision(repoPath: string, path: string, ref: string): Promise<GitTreeEntry | undefined>;
319314
getTreeForRevision(repoPath: string, ref: string): Promise<GitTreeEntry[]>;
@@ -415,6 +410,11 @@ export interface GitProviderBranches {
415410
): Promise<string | undefined>;
416411

417412
createBranch?(repoPath: string, name: string, ref: string): Promise<void>;
413+
getPotentialMergeOrRebaseConflict?(
414+
repoPath: string,
415+
branch: string,
416+
targetBranch: string,
417+
): Promise<MergeConflict | undefined>;
418418
getBaseBranchName?(repoPath: string, ref: string): Promise<string | undefined>;
419419
setBaseBranchName?(repoPath: string, ref: string, base: string): Promise<void>;
420420
getTargetBranchName?(repoPath: string, ref: string): Promise<string | undefined>;

src/git/gitProviderService.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ import type { GitDiff, GitDiffFile, GitDiffFiles, GitDiffFilter, GitDiffLine, Gi
7474
import type { GitFile, GitFileChange } from './models/file';
7575
import type { GitGraph } from './models/graph';
7676
import type { GitLog } from './models/log';
77-
import type { MergeConflict } from './models/mergeConflict';
7877
import type { GitBranchReference, GitReference } from './models/reference';
7978
import type { GitReflog } from './models/reflog';
8079
import type { GitRemote } from './models/remote';
@@ -2018,16 +2017,6 @@ export class GitProviderService implements Disposable {
20182017
return provider.getIncomingActivity(path, options);
20192018
}
20202019

2021-
@log()
2022-
async getPotentialMergeOrRebaseConflict(
2023-
repoPath: string | Uri,
2024-
branch: string,
2025-
targetBranch: string,
2026-
): Promise<MergeConflict | undefined> {
2027-
const { provider, path } = this.getProvider(repoPath);
2028-
return provider.getPotentialMergeOrRebaseConflict?.(path, branch, targetBranch);
2029-
}
2030-
20312020
getBestRepository(): Repository | undefined;
20322021
// eslint-disable-next-line @typescript-eslint/unified-signatures
20332022
getBestRepository(uri?: Uri, editor?: TextEditor): Repository | undefined;

src/webviews/home/homeWebview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ async function getBranchMergeTargetStatusInfo(
13991399
container.git.getLeftRightCommitCount(branch.repoPath, createRevisionRange(target, branch.ref, '...'), {
14001400
excludeMerges: true,
14011401
}),
1402-
container.git.getPotentialMergeOrRebaseConflict(branch.repoPath, branch.name, target),
1402+
container.git.branches(branch.repoPath).getPotentialMergeOrRebaseConflict?.(branch.name, target),
14031403
]);
14041404

14051405
const counts = getSettledValue(countsResult);

0 commit comments

Comments
 (0)