mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 10:08:49 +01:00
Tolerate minor edit session identity differences (#163804)
Also add basic support for partial edit session identity matches
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user