Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change branch create and branch rename into normal commands #3596

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Changed

- Changes how GitLens handles creating and renaming branches to avoid using the terminal — refs [#3528](https://github.com/gitkraken/vscode-gitlens/issues/3528)

### Fixed

- Fixes [#3592](https://github.com/gitkraken/vscode-gitlens/issues/3592) - Connecting to an integration via Remotes view (but likely others) doesn't work
Expand Down
18 changes: 16 additions & 2 deletions src/commands/git/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { getNameWithoutRemote, getReferenceLabel, isRevisionReference } from '..
import { Repository } from '../../git/models/repository';
import type { GitWorktree } from '../../git/models/worktree';
import { getWorktreesByBranch } from '../../git/models/worktree';
import { showGenericErrorMessage } from '../../messages';
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
import { createQuickPickSeparator } from '../../quickpicks/items/common';
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
import { createFlagsQuickPickItem } from '../../quickpicks/items/flags';
import { ensureArray } from '../../system/array';
import { Logger } from '../../system/logger';
import { pluralize } from '../../system/string';
import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
import type {
Expand Down Expand Up @@ -393,7 +395,13 @@ export class BranchGitCommand extends QuickCommand {
if (state.flags.includes('--switch')) {
await state.repo.switch(state.reference.ref, { createBranch: state.name });
} else {
state.repo.branch(...state.flags, state.name, state.reference.ref);
try {
await state.repo.git.createBranch(state.name, state.reference.ref);
} catch (ex) {
Logger.error(ex);
// TODO likely need some better error handling here
return showGenericErrorMessage('Unable to create branch');
}
}
}
}
Expand Down Expand Up @@ -614,7 +622,13 @@ export class BranchGitCommand extends QuickCommand {
state.flags = result;

endSteps(state);
state.repo.branch(...state.flags, state.reference.ref, state.name);
try {
await state.repo.git.renameBranch(state.reference.ref, state.name);
} catch (ex) {
Logger.error(ex);
// TODO likely need some better error handling here
return showGenericErrorMessage('Unable to rename branch');
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/env/node/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ export class Git {
}
}

branch(repoPath: string, ...args: string[]) {
return this.git<string>({ cwd: repoPath }, 'branch', ...args);
}

branch__set_upstream(repoPath: string, branch: string, remote: string, remoteBranch: string) {
return this.git<string>({ cwd: repoPath }, 'branch', '--set-upstream-to', `${remote}/${remoteBranch}`, branch);
}
Expand Down
10 changes: 10 additions & 0 deletions src/env/node/git/localGitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,16 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
}

@log()
async createBranch(repoPath: string, name: string, ref: string): Promise<void> {
await this.git.branch(repoPath, name, ref);
}

@log()
async renameBranch(repoPath: string, oldName: string, newName: string): Promise<void> {
await this.git.branch(repoPath, '-m', oldName, newName);
}

@log()
async checkout(
repoPath: string,
Expand Down
4 changes: 4 additions & 0 deletions src/git/gitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@ export interface RepositoryVisibilityInfo {
}

export interface GitProviderRepository {
createBranch?(repoPath: string, name: string, ref: string): Promise<void>;
renameBranch?(repoPath: string, oldName: string, newName: string): Promise<void>;

addRemote?(repoPath: string, name: string, url: string, options?: { fetch?: boolean }): Promise<void>;
pruneRemote?(repoPath: string, name: string): Promise<void>;
removeRemote?(repoPath: string, name: string): Promise<void>;

applyUnreachableCommitForPatch?(
repoPath: string,
ref: string,
Expand Down
16 changes: 16 additions & 0 deletions src/git/gitProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,22 @@ export class GitProviderService implements Disposable {
return provider.applyUnreachableCommitForPatch(path, ref, options);
}

@log()
createBranch(repoPath: string | Uri, name: string, ref: string): Promise<void> {
const { provider, path } = this.getProvider(repoPath);
if (provider.createBranch == null) throw new ProviderNotSupportedError(provider.descriptor.name);

return provider.createBranch(path, name, ref);
}

@log()
renameBranch(repoPath: string | Uri, oldName: string, newName: string): Promise<void> {
const { provider, path } = this.getProvider(repoPath);
if (provider.renameBranch == null) throw new ProviderNotSupportedError(provider.descriptor.name);

return provider.renameBranch(path, oldName, newName);
}

@log()
checkout(
repoPath: string | Uri,
Expand Down
5 changes: 0 additions & 5 deletions src/git/models/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,6 @@ export class Repository implements Disposable {
return remote;
}

@log()
branch(...args: string[]) {
void this.runTerminalCommand('branch', ...args);
}

@log()
branchDelete(branches: GitBranchReference | GitBranchReference[], options?: { force?: boolean; remote?: boolean }) {
if (!Array.isArray(branches)) {
Expand Down
Loading