Skip to content

Commit 7722c2b

Browse files
authored
Git - adjust command when clauses (microsoft#236392)
* Add telemetry for troubleshooting * Adjust command when clause
1 parent 6baeecd commit 7722c2b

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

extensions/git/package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -943,19 +943,19 @@
943943
"command": "git.stageSelectedRanges",
944944
"key": "ctrl+k ctrl+alt+s",
945945
"mac": "cmd+k cmd+alt+s",
946-
"when": "editorTextFocus && resourceScheme =~ /^git$|^file$/"
946+
"when": "editorTextFocus && resourceScheme == file"
947947
},
948948
{
949949
"command": "git.unstageSelectedRanges",
950950
"key": "ctrl+k ctrl+n",
951951
"mac": "cmd+k cmd+n",
952-
"when": "isInDiffEditor && resourceScheme =~ /^git$|^file$/"
952+
"when": "editorTextFocus && isInDiffEditor && isInDiffRightEditor && resourceScheme == git"
953953
},
954954
{
955955
"command": "git.revertSelectedRanges",
956956
"key": "ctrl+k ctrl+r",
957957
"mac": "cmd+k cmd+r",
958-
"when": "editorTextFocus && resourceScheme =~ /^git$|^file$/"
958+
"when": "editorTextFocus && resourceScheme == file"
959959
}
960960
],
961961
"menus": {
@@ -1026,15 +1026,15 @@
10261026
},
10271027
{
10281028
"command": "git.stageSelectedRanges",
1029-
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && resourceScheme =~ /^git$|^file$/"
1029+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && resourceScheme == file"
10301030
},
10311031
{
10321032
"command": "git.stageChange",
10331033
"when": "false"
10341034
},
10351035
{
10361036
"command": "git.revertSelectedRanges",
1037-
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && resourceScheme =~ /^git$|^file$/"
1037+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && resourceScheme == file"
10381038
},
10391039
{
10401040
"command": "git.revertChange",
@@ -1054,7 +1054,7 @@
10541054
},
10551055
{
10561056
"command": "git.unstageSelectedRanges",
1057-
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme =~ /^git$|^file$/"
1057+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && isInDiffRightEditor && resourceScheme == git"
10581058
},
10591059
{
10601060
"command": "git.clean",
@@ -2068,17 +2068,17 @@
20682068
{
20692069
"command": "git.stageSelectedRanges",
20702070
"group": "2_git@1",
2071-
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme =~ /^git$|^file$/"
2071+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && isInDiffRightEditor && !isEmbeddedDiffEditor && resourceScheme == file"
20722072
},
20732073
{
20742074
"command": "git.unstageSelectedRanges",
20752075
"group": "2_git@2",
2076-
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme =~ /^git$|^file$/"
2076+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && isInDiffRightEditor && !isEmbeddedDiffEditor && resourceScheme == git"
20772077
},
20782078
{
20792079
"command": "git.revertSelectedRanges",
20802080
"group": "2_git@3",
2081-
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme =~ /^git$|^file$/"
2081+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && isInDiffRightEditor && !isEmbeddedDiffEditor && resourceScheme == file"
20822082
},
20832083
{
20842084
"command": "git.stashApplyEditor",
@@ -2096,17 +2096,17 @@
20962096
{
20972097
"command": "git.stageSelectedRanges",
20982098
"group": "2_git@1",
2099-
"when": "isInDiffRightEditor && !isEmbeddedDiffEditor && config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme =~ /^git$|^file$/"
2099+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && isInDiffRightEditor && !isEmbeddedDiffEditor && resourceScheme == file"
21002100
},
21012101
{
21022102
"command": "git.unstageSelectedRanges",
21032103
"group": "2_git@2",
2104-
"when": "isInDiffRightEditor && !isEmbeddedDiffEditor && config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme =~ /^git$|^file$/"
2104+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && isInDiffRightEditor && !isEmbeddedDiffEditor && resourceScheme == git"
21052105
},
21062106
{
21072107
"command": "git.revertSelectedRanges",
21082108
"group": "2_git@3",
2109-
"when": "isInDiffRightEditor && !isEmbeddedDiffEditor && config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme =~ /^git$|^file$/"
2109+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInDiffEditor && isInDiffRightEditor && !isEmbeddedDiffEditor && resourceScheme == file"
21102110
}
21112111
],
21122112
"editor/content": [

extensions/git/src/commands.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1563,12 +1563,16 @@ export class CommandCenter {
15631563
return;
15641564
}
15651565

1566+
this.logger.trace(`[CommandCenter][stageSelectedChanges] changes: ${JSON.stringify(changes)}`);
1567+
15661568
const modifiedDocument = textEditor.document;
15671569
const selectedLines = toLineRanges(textEditor.selections, modifiedDocument);
15681570
const selectedChanges = changes
15691571
.map(change => selectedLines.reduce<LineChange | null>((result, range) => result || intersectDiffWithRange(modifiedDocument, change, range), null))
15701572
.filter(d => !!d) as LineChange[];
15711573

1574+
this.logger.trace(`[CommandCenter][stageSelectedChanges] selectedChanges: ${JSON.stringify(selectedChanges)}`);
1575+
15721576
if (!selectedChanges.length) {
15731577
window.showInformationMessage(l10n.t('The selection range does not contain any changes.'));
15741578
return;
@@ -1745,6 +1749,8 @@ export class CommandCenter {
17451749
return;
17461750
}
17471751

1752+
this.logger.trace(`[CommandCenter][revertSelectedRanges] changes: ${JSON.stringify(changes)}`);
1753+
17481754
const modifiedDocument = textEditor.document;
17491755
const selections = textEditor.selections;
17501756
const selectedChanges = changes.filter(change => {
@@ -1757,6 +1763,8 @@ export class CommandCenter {
17571763
return;
17581764
}
17591765

1766+
this.logger.trace(`[CommandCenter][revertSelectedRanges] selectedChanges: ${JSON.stringify(selectedChanges)}`);
1767+
17601768
const selectionsBeforeRevert = textEditor.selections;
17611769
await this._revertChanges(textEditor, selectedChanges);
17621770
textEditor.selections = selectionsBeforeRevert;
@@ -1835,6 +1843,8 @@ export class CommandCenter {
18351843
return;
18361844
}
18371845

1846+
this.logger.trace(`[CommandCenter][unstageSelectedRanges] changes: ${JSON.stringify(changes)}`);
1847+
18381848
const originalUri = toGitUri(modifiedUri, 'HEAD');
18391849
const originalDocument = await workspace.openTextDocument(originalUri);
18401850
const selectedLines = toLineRanges(textEditor.selections, modifiedDocument);
@@ -1848,8 +1858,11 @@ export class CommandCenter {
18481858
}
18491859

18501860
const invertedDiffs = selectedDiffs.map(invertLineChange);
1851-
const result = applyLineChanges(modifiedDocument, originalDocument, invertedDiffs);
18521861

1862+
this.logger.trace(`[CommandCenter][unstageSelectedRanges] selectedDiffs: ${JSON.stringify(selectedDiffs)}`);
1863+
this.logger.trace(`[CommandCenter][unstageSelectedRanges] invertedDiffs: ${JSON.stringify(invertedDiffs)}`);
1864+
1865+
const result = applyLineChanges(modifiedDocument, originalDocument, invertedDiffs);
18531866
await this.runByRepository(modifiedUri, async (repository, resource) => await repository.stage(resource, result));
18541867
}
18551868

0 commit comments

Comments
 (0)