Przeglądaj źródła

Improves worktree creation flow

- Honors `createBranch` flag for naming the worktree folder
- Falls back to the qualified remote branch name if the branch name already exists
- Always uses the qualified remote branch name via GHPR command
main
Eric Amodio 1 rok temu
rodzic
commit
4ddb52bc53
5 zmienionych plików z 36 dodań i 19 usunięć
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -1
      package.json
  3. +8
    -9
      src/commands/ghpr/openOrCreateWorktree.ts
  4. +11
    -7
      src/commands/git/worktree.ts
  5. +15
    -2
      src/git/actions/worktree.ts

+ 1
- 0
CHANGELOG.md Wyświetl plik

@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Improves the display of items in the _Commit Graph_
- When showing local branches, we now always display the upstream branches in the minimap, scrollbar markers, and graph rows
- When laying out lanes in the Graph column, we now bias to be left aligned when possible for an easier to read and compact graph visualization
- Improves _Open Worktree for Pull Request via GitLens..._ command to use the qualified remote branch name, e.g. `owner/branch`, when creating the worktree
- Removes Insiders edition in favor of the pre-release edition
### Fixed

+ 1
- 1
package.json Wyświetl plik

@ -11766,7 +11766,7 @@
{
"command": "gitlens.ghpr.views.openOrCreateWorktree",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && view == pr:github && viewItem =~ /pullrequest(:local)?:nonactive|description/",
"group": "pullrequest@2"
"group": "2_gitlens@1"
}
],
"webview/context": [

+ 8
- 9
src/commands/ghpr/openOrCreateWorktree.ts Wyświetl plik

@ -79,8 +79,10 @@ export class OpenOrCreateWorktreeCommand extends Command {
return;
}
const branchName = `${remoteOwner}/${ref}`;
const worktrees = await repo.getWorktrees();
const worktree = worktrees.find(w => w.branch === ref);
const worktree = worktrees.find(w => w.branch === branchName);
if (worktree != null) {
void openWorktree(worktree);
@ -118,27 +120,24 @@ export class OpenOrCreateWorktreeCommand extends Command {
await createWorktree(
repo,
undefined,
createReference(`${remote.name}/${ref}`, repo.path, {
refType: 'branch',
name: `${remote.name}/${ref}`,
remote: true,
}),
createReference(branchName, repo.path, { refType: 'branch', name: branchName, remote: true }),
{ createBranch: branchName },
);
// Ensure that the worktree was created
const worktree = await this.container.git.getWorktree(repo.path, w => w.branch === ref);
const worktree = await this.container.git.getWorktree(repo.path, w => w.branch === branchName);
if (worktree == null) return;
// Save the PR number in the branch config
// https://github.com/Microsoft/vscode-pull-request-github/blob/0c556c48c69a3df2f9cf9a45ed2c40909791b8ab/src/github/pullRequestGitHelper.ts#L18
void this.container.git.setConfig(
repo.path,
`branch.${ref}.github-pr-owner-number`,
`branch.${branchName}.github-pr-owner-number`,
`${rootOwner}#${rootRepository}#${number}`,
);
} catch (ex) {
Logger.error(ex, 'CreateWorktreeCommand', 'Unable to create worktree');
void window.showErrorMessage(`Unable to create worktree for ${ref}`);
void window.showErrorMessage(`Unable to create worktree for ${remoteOwner}:${ref}`);
}
}
}

+ 11
- 7
src/commands/git/worktree.ts Wyświetl plik

@ -367,7 +367,12 @@ export class WorktreeGitCommand extends QuickCommand {
const isRemoteBranch = state.reference?.refType === 'branch' && state.reference?.remote;
if (isRemoteBranch && !state.flags.includes('-b')) {
state.flags.push('-b');
state.createBranch = getNameWithoutRemote(state.reference);
const branch = await state.repo.getBranch(state.createBranch);
if (branch != null) {
state.createBranch = state.reference.name;
}
}
if (state.flags.includes('-b') && state.createBranch == null) {
@ -576,13 +581,12 @@ export class WorktreeGitCommand extends QuickCommand {
canCreateDirectlyInPicked = false;
}
const recommendedUri =
state.reference != null
? Uri.joinPath(
recommendedRootUri,
...getNameWithoutRemote(state.reference).replace(/\\/g, '/').split('/'),
)
: recommendedRootUri;
const branchName =
state.createBranch ?? (state.reference != null ? getNameWithoutRemote(state.reference) : undefined);
const recommendedUri = branchName
? Uri.joinPath(recommendedRootUri, ...branchName.replace(/\\/g, '/').split('/'))
: recommendedRootUri;
const recommendedFriendlyPath = truncateLeft(GitWorktree.getFriendlyPath(recommendedUri), 65);
const recommendedNewBranchFriendlyPath = truncateLeft(

+ 15
- 2
src/git/actions/worktree.ts Wyświetl plik

@ -10,10 +10,23 @@ import type { GitReference } from '../models/reference';
import type { Repository } from '../models/repository';
import type { GitWorktree } from '../models/worktree';
export function create(repo?: string | Repository, uri?: Uri, ref?: GitReference, options?: { reveal?: boolean }) {
export function create(
repo?: string | Repository,
uri?: Uri,
ref?: GitReference,
options?: { createBranch?: string; reveal?: boolean },
) {
return executeGitCommand({
command: 'worktree',
state: { subcommand: 'create', repo: repo, uri: uri, reference: ref, reveal: options?.reveal },
state: {
subcommand: 'create',
repo: repo,
uri: uri,
reference: ref,
createBranch: options?.createBranch,
flags: options?.createBranch ? ['-b'] : undefined,
reveal: options?.reveal,
},
});
}

Ładowanie…
Anuluj
Zapisz