Skip to content

Commit

Permalink
Git - add stage/unstage commands to editor title (#237257)
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru authored Jan 4, 2025
1 parent 2bdb3e9 commit aa6a381
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
12 changes: 11 additions & 1 deletion extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2050,9 +2050,19 @@
"group": "navigation",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInNotebookTextDiffEditor && resourceScheme =~ /^git$|^file$/"
},
{
"command": "git.stage",
"group": "navigation@1",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && !isInDiffEditor && !isMergeEditor && resourceScheme == file && git.activeResourceHasUnstagedChanges"
},
{
"command": "git.unstage",
"group": "navigation@1",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && !isInDiffEditor && !isMergeEditor && resourceScheme == file && git.activeResourceHasStagedChanges"
},
{
"command": "git.openChange",
"group": "navigation",
"group": "navigation@2",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && !isInDiffEditor && !isMergeEditor && resourceScheme == file && scmActiveResourceHasChanges"
},
{
Expand Down
28 changes: 28 additions & 0 deletions extensions/git/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi

workspace.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders, this, this.disposables);
window.onDidChangeVisibleTextEditors(this.onDidChangeVisibleTextEditors, this, this.disposables);
window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, this.disposables);
workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, this.disposables);

const fsWatcher = workspace.createFileSystemWatcher('**');
Expand Down Expand Up @@ -519,6 +520,31 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi
}
}

private onDidChangeActiveTextEditor(): void {
const textEditor = window.activeTextEditor;

if (textEditor === undefined) {
commands.executeCommand('setContext', 'git.activeResourceHasUnstagedChanges', false);
commands.executeCommand('setContext', 'git.activeResourceHasStagedChanges', false);
return;
}

const repository = this.getRepository(textEditor.document.uri);
if (!repository) {
commands.executeCommand('setContext', 'git.activeResourceHasUnstagedChanges', false);
commands.executeCommand('setContext', 'git.activeResourceHasStagedChanges', false);
return;
}

const indexResource = repository.indexGroup.resourceStates
.find(resource => pathEquals(resource.resourceUri.fsPath, textEditor.document.uri.fsPath));
const workingTreeResource = repository.workingTreeGroup.resourceStates
.find(resource => pathEquals(resource.resourceUri.fsPath, textEditor.document.uri.fsPath));

commands.executeCommand('setContext', 'git.activeResourceHasStagedChanges', indexResource !== undefined);
commands.executeCommand('setContext', 'git.activeResourceHasUnstagedChanges', workingTreeResource !== undefined);
}

@sequentialize
async openRepository(repoPath: string, openIfClosed = false): Promise<void> {
this.logger.trace(`[Model][openRepository] Repository: ${repoPath}`);
Expand Down Expand Up @@ -727,8 +753,10 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi
const statusListener = repository.onDidRunGitStatus(() => {
checkForSubmodules();
updateMergeChanges();
this.onDidChangeActiveTextEditor();
});
checkForSubmodules();
this.onDidChangeActiveTextEditor();

const updateOperationInProgressContext = () => {
let operationInProgress = false;
Expand Down

0 comments on commit aa6a381

Please sign in to comment.