Repository: TabbyML/tabby
File: clients/vscode/src/commands/index.ts (TypeScript)

Code before:
          );
          selectedRepo = selected?.value;
        }
      }
      if (!selectedRepo) {
        return;
      }
      window.withProgress(
        {
          location: ProgressLocation.Notification,
          title: "Generating commit message...",
          cancellable: true,
        },
        async (_, token) => {
          // Focus on scm view
          commands.executeCommand("workbench.view.scm");
          const result = await this.client.chat.generateCommitMessage(
            { repository: selectedRepo.rootUri.toString() },
            token,
          );

          if (result && selectedRepo.inputBox) {
            selectedRepo.inputBox.value = result.commitMessage;

            if (this.gitProvider.isApiAvailable()) {
              const repo = this.gitProvider.getRepository(selectedRepo.rootUri);
              if (repo && repo.state && repo.state.HEAD) {
                const currentBranch = repo.state.HEAD.name;
                // FIXME(Sma1lboy): let LLM model decide should we create a new branch or not
                if (currentBranch === "main" || currentBranch === "master") {
                  commands.executeCommand("tabby.chat.generateBranchName", selectedRepo);
                }
              }
            }
          }
        },
      );
    },
    "chat.generateBranchName": async (repository?: Repository) => {
      let selectedRepo = repository;
      if (!selectedRepo) {
        const repos = this.gitProvider.getRepositories() ?? [];
        if (repos.length < 1) {
          window.showInformationMessage("No Git repositories found.");
          return;
        }
        if (repos.length == 1) {
          selectedRepo = repos[0];
        } else {
          const selected = await window.showQuickPick(
            repos

Review comment (suggestion):
`this.gitProvider.isApiAvailable()` is not necessary here, `selectedRepo` is already of type Repository, so there is no need to get it again.

Code after:
          );
          selectedRepo = selected?.value;
        }
      }
      if (!selectedRepo) {
        return;
      }
      window.withProgress(
        {
          location: ProgressLocation.Notification,
          title: "Generating commit message...",
          cancellable: true,
        },
        async (_, token) => {
          // Focus on scm view
          commands.executeCommand("workbench.view.scm");
          const result = await this.client.chat.generateCommitMessage(
            { repository: selectedRepo.rootUri.toString() },
            token,
          );

          if (result && selectedRepo.inputBox) {
            selectedRepo.inputBox.value = result.commitMessage;

            const repo = this.gitProvider.getRepository(selectedRepo.rootUri);
            if (repo && repo.state && repo.state.HEAD) {
              const currentBranch = repo.state.HEAD.name;
              // FIXME(Sma1lboy): let LLM model decide should we create a new branch or not
              if (currentBranch === "main" || currentBranch === "master") {
                commands.executeCommand("tabby.chat.generateBranchName", selectedRepo);
              }
            }
          }
        },
      );
    },
    "chat.generateBranchName": async (repository?: Repository) => {
      let selectedRepo = repository;
      if (!selectedRepo) {
        const repos = this.gitProvider.getRepositories() ?? [];
        if (repos.length < 1) {
          window.showInformationMessage("No Git repositories found.");
          return;
        }
        if (repos.length == 1) {
          selectedRepo = repos[0];
        } else {
          const selected = await window.showQuickPick(
            repos
              .map((repo) => {
                const repoRoot = repo.rootUri.fsPath;