Git - Add button/setting to always replace local tags in case of a conflict during the pull operation (#205148)

This commit is contained in:
Ladislau Szomoru 2024-02-13 22:04:29 +01:00 committed by GitHub
parent 71bd033d63
commit 9576c1a7c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 6 deletions

View file

@ -2645,6 +2645,12 @@
"default": false,
"description": "%config.followTagsWhenSync%"
},
"git.replaceTagsWhenPull": {
"type": "boolean",
"scope": "resource",
"default": false,
"description": "%config.replaceTagsWhenPull%"
},
"git.promptToSaveFilesBeforeStash": {
"type": "string",
"enum": [

View file

@ -176,6 +176,7 @@
"config.decorations.enabled": "Controls whether Git contributes colors and badges to the Explorer and the Open Editors view.",
"config.enableStatusBarSync": "Controls whether the Git Sync command appears in the status bar.",
"config.followTagsWhenSync": "Push all annotated tags when running the sync command.",
"config.replaceTagsWhenPull": "Automatically replace the local tags with the remote tags in case of a conflict when running the pull command.",
"config.promptToSaveFilesBeforeStash": "Controls whether Git should check for unsaved files before stashing changes.",
"config.promptToSaveFilesBeforeStash.always": "Check for any unsaved files.",
"config.promptToSaveFilesBeforeStash.staged": "Check only for unsaved staged files.",

View file

@ -2630,13 +2630,23 @@ export class Repository implements Disposable {
throw new Error(`Unable to extract tag names from error message: ${raw}`);
}
// Notification
const replaceLocalTags = l10n.t('Replace Local Tag(s)');
const message = l10n.t('Unable to pull from remote repository due to conflicting tag(s): {0}. Would you like to resolve the conflict by replacing the local tag(s)?', tags.join(', '));
const choice = await window.showErrorMessage(message, { modal: true }, replaceLocalTags);
const config = workspace.getConfiguration('git', Uri.file(this.repository.root));
const replaceTagsWhenPull = config.get<boolean>('replaceTagsWhenPull', false) === true;
if (choice !== replaceLocalTags) {
return false;
if (!replaceTagsWhenPull) {
// Notification
const replaceLocalTags = l10n.t('Replace Local Tag(s)');
const replaceLocalTagsAlways = l10n.t('Always Replace Local Tag(s)');
const message = l10n.t('Unable to pull from remote repository due to conflicting tag(s): {0}. Would you like to resolve the conflict by replacing the local tag(s)?', tags.join(', '));
const choice = await window.showErrorMessage(message, { modal: true }, replaceLocalTags, replaceLocalTagsAlways);
if (choice !== replaceLocalTags && choice !== replaceLocalTagsAlways) {
return false;
}
if (choice === replaceLocalTagsAlways) {
await config.update('replaceTagsWhenPull', true, true);
}
}
// Force fetch tags