You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

  1. 'use strict';
  2. import { Disposable, Terminal, window } from 'vscode';
  3. import { Container } from './container';
  4. let _terminal: Terminal | undefined;
  5. let _terminalCwd: string | undefined;
  6. let _disposable: Disposable | undefined;
  7. const extensionTerminalName = 'GitLens';
  8. function ensureTerminal(cwd: string): Terminal {
  9. if (_terminal === undefined) {
  10. _terminal = window.createTerminal(extensionTerminalName);
  11. _disposable = window.onDidCloseTerminal((e: Terminal) => {
  12. if (e.name === extensionTerminalName) {
  13. _terminal = undefined;
  14. _disposable!.dispose();
  15. _disposable = undefined;
  16. }
  17. });
  18. Container.context.subscriptions.push(_disposable);
  19. _terminalCwd = undefined;
  20. }
  21. if (_terminalCwd !== cwd) {
  22. _terminal.sendText(`cd "${cwd}"`, true);
  23. _terminalCwd = cwd;
  24. }
  25. return _terminal;
  26. }
  27. export function runGitCommandInTerminal(command: string, args: string, cwd: string, execute: boolean = false) {
  28. // let git = Git.getGitPath();
  29. // if (git.includes(' ')) {
  30. // git = `"${git}"`;
  31. // }
  32. const terminal = ensureTerminal(cwd);
  33. terminal.show(false);
  34. terminal.sendText(`git ${command} ${args}`, execute);
  35. }