Tolerate minor edit session identity differences (#163804)

Also add basic support for partial edit session identity matches
This commit is contained in:
Joyce Er
2022-10-16 23:51:51 -07:00
committed by GitHub
parent a0a7cc4b5f
commit f9a0fdeff2
10 changed files with 152 additions and 8 deletions

View File

@@ -35,4 +35,39 @@ export class GitEditSessionIdentityProvider implements vscode.EditSessionIdentit
sha: repository.HEAD?.commit ?? null,
});
}
provideEditSessionIdentityMatch(identity1: string, identity2: string): vscode.EditSessionIdentityMatch {
try {
const normalizedIdentity1 = normalizeEditSessionIdentity(identity1);
const normalizedIdentity2 = normalizeEditSessionIdentity(identity2);
if (normalizedIdentity1.remote === normalizedIdentity2.remote &&
normalizedIdentity1.ref === normalizedIdentity2.ref &&
normalizedIdentity1.sha === normalizedIdentity2.sha) {
// This is a perfect match
return vscode.EditSessionIdentityMatch.Complete;
} else if (normalizedIdentity1.sha !== normalizedIdentity2.sha) {
// Same branch and remote but different SHA
return vscode.EditSessionIdentityMatch.Partial;
} else {
return vscode.EditSessionIdentityMatch.None;
}
} catch (ex) {
return vscode.EditSessionIdentityMatch.Partial;
}
}
}
function normalizeEditSessionIdentity(identity: string) {
let { remote, ref, sha } = JSON.parse(identity);
if (typeof remote === 'string' && remote.endsWith('.git')) {
remote = remote.slice(0, remote.length - 4);
}
return {
remote,
ref,
sha
};
}