MCPcopy Create free account
hub / github.com/Kong/insomnia / pullWithConflictSupport

Method pullWithConflictSupport

packages/insomnia/src/sync/git/git-vcs.ts:1292–1398  ·  view source on GitHub ↗
(credentialsId?: string | null)

Source from the content-addressed store, hash-verified

1290 }
1291
1292 async pullWithConflictSupport(credentialsId?: string | null) {
1293 const hasUncommittedChanges = await this.hasUncommittedChanges();
1294
1295 if (hasUncommittedChanges) {
1296 throw new Error(GitVCSOperationErrors.UncommittedChangesError);
1297 }
1298
1299 const writeFileMap = {};
1300 // Collects paths refused by the containment guard during checkout (see
1301 // fs-client.ts). Shared across the CheckoutConflictError retry below, so
1302 // dedupe by relPath before returning.
1303 const blockedWrites: BlockedWrite[] = [];
1304 const dedupedBlockedWrites = () => Array.from(new Map(blockedWrites.map(b => [b.relPath, b])).values());
1305
1306 try {
1307 if (
1308 'startCollectWriteAction' in this._baseOpts.fs &&
1309 typeof this._baseOpts.fs.startCollectWriteAction === 'function'
1310 ) {
1311 this._baseOpts.fs.startCollectWriteAction(writeFileMap);
1312 }
1313 if (
1314 'startCollectBlockedWrites' in this._baseOpts.fs &&
1315 typeof this._baseOpts.fs.startCollectBlockedWrites === 'function'
1316 ) {
1317 this._baseOpts.fs.startCollectBlockedWrites(blockedWrites);
1318 }
1319 // Try to pull changes from the remote repository
1320 await git.pull({
1321 ...this._baseOpts,
1322 ...gitCallbacks(credentialsId),
1323 remote: 'origin',
1324 singleBranch: true,
1325 });
1326
1327 if (blockedWrites.length > 0) {
1328 return { success: false, blockedWrites: dedupedBlockedWrites() };
1329 }
1330
1331 return { success: true };
1332 } catch (err) {
1333 if (err instanceof git.Errors.CheckoutConflictError) {
1334 console.log('[git] CheckoutConflictError detected, resetting working directory and retrying pull');
1335
1336 try {
1337 const currentBranch = await this.getCurrentBranch();
1338
1339 // Reset working directory to HEAD to resolve checkout conflicts
1340 await git.checkout({
1341 ...this._baseOpts,
1342 ref: currentBranch,
1343 force: true,
1344 });
1345
1346 // Retry the pull operation
1347 await git.pull({
1348 ...this._baseOpts,
1349 ...gitCallbacks(credentialsId),

Callers 1

pullFromGitRemoteFunction · 0.80

Calls 7

hasUncommittedChangesMethod · 0.95
getCurrentBranchMethod · 0.95
handleGitPullErrorsMethod · 0.95
gitCallbacksFunction · 0.90
pullMethod · 0.45
logMethod · 0.45
checkoutMethod · 0.45

Tested by

no test coverage detected