Browse Source

Adds fetch of a specific branch

Changes fetch/pull/push on roots to affect the whole repo
main
Eric Amodio 4 years ago
parent
commit
db0eeef651
6 changed files with 70 additions and 41 deletions
  1. +7
    -2
      package.json
  2. +51
    -29
      src/commands/git/fetch.ts
  3. +2
    -2
      src/commands/gitCommands.actions.ts
  4. +2
    -2
      src/views/nodes/branchNode.ts
  5. +2
    -2
      src/views/nodes/branchTrackingStatusNode.ts
  6. +6
    -4
      src/views/viewCommands.ts

+ 7
- 2
package.json View File

@ -6616,8 +6616,13 @@
},
{
"command": "gitlens.views.pull",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+tracking\\b)/",
"group": "inline@9"
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+behind\\b)/",
"group": "inline@8"
},
{
"command": "gitlens.views.fetch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+ahead\\b)(?!.*?\\b\\+behind\\b)/",
"group": "inline@8"
},
{
"command": "gitlens.views.undoCommit",

+ 51
- 29
src/commands/git/fetch.ts View File

@ -1,7 +1,7 @@
'use strict';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { Repository } from '../../git/git';
import { GitBranchReference, GitReference, Repository } from '../../git/git';
import {
appendReposToTitle,
PartialStepState,
@ -26,6 +26,7 @@ type Flags = '--all' | '--prune';
interface State {
repos: string | string[] | Repository | Repository[];
reference?: GitBranchReference;
flags: Flags[];
}
@ -54,6 +55,10 @@ export class FetchGitCommand extends QuickCommand {
}
execute(state: FetchStepState) {
if (GitReference.isBranch(state.reference)) {
return state.repos[0].fetch({ branch: state.reference });
}
return Container.git.fetchAll(state.repos, {
all: state.flags.includes('--all'),
prune: state.flags.includes('--prune'),
@ -136,34 +141,51 @@ export class FetchGitCommand extends QuickCommand {
}
}
const reposToFetch =
state.repos.length === 1 ? `$(repo) ${state.repos[0].formattedName}` : `${state.repos.length} repositories`;
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = QuickCommand.createConfirmStep(
appendReposToTitle(`Confirm ${this.title}`, state, context, lastFetchedOn),
[
FlagsQuickPickItem.create<Flags>(state.flags, [], {
label: this.title,
detail: `Will fetch ${reposToFetch}`,
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--prune'], {
label: `${this.title} & Prune`,
description: '--prune',
detail: `Will fetch and prune ${reposToFetch}`,
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--all'], {
label: `${this.title} All`,
description: '--all',
detail: `Will fetch all remotes of ${reposToFetch}`,
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--all', '--prune'], {
label: `${this.title} All & Prune`,
description: '--all --prune',
detail: `Will fetch and prune all remotes of ${reposToFetch}`,
}),
],
context,
);
let step: QuickPickStep<FlagsQuickPickItem<Flags>>;
if (state.repos.length === 1 && GitReference.isBranch(state.reference)) {
step = this.createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context, lastFetchedOn),
[
FlagsQuickPickItem.create<Flags>(state.flags, [], {
label: this.title,
detail: `Will fetch ${GitReference.toString(state.reference)}`,
}),
],
);
} else {
const reposToFetch =
state.repos.length === 1
? `$(repo) ${state.repos[0].formattedName}`
: `${state.repos.length} repositories`;
step = QuickCommand.createConfirmStep(
appendReposToTitle(`Confirm ${this.title}`, state, context, lastFetchedOn),
[
FlagsQuickPickItem.create<Flags>(state.flags, [], {
label: this.title,
detail: `Will fetch ${reposToFetch}`,
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--prune'], {
label: `${this.title} & Prune`,
description: '--prune',
detail: `Will fetch and prune ${reposToFetch}`,
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--all'], {
label: `${this.title} All`,
description: '--all',
detail: `Will fetch all remotes of ${reposToFetch}`,
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--all', '--prune'], {
label: `${this.title} All & Prune`,
description: '--all --prune',
detail: `Will fetch and prune all remotes of ${reposToFetch}`,
}),
],
context,
);
}
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}

+ 2
- 2
src/commands/gitCommands.actions.ts View File

@ -52,8 +52,8 @@ export namespace GitActions {
});
}
export function fetch(repos?: string | string[] | Repository | Repository[]) {
return executeGitCommand({ command: 'fetch', state: { repos: repos } });
export function fetch(repos?: string | string[] | Repository | Repository[], ref?: GitBranchReference) {
return executeGitCommand({ command: 'fetch', state: { repos: repos, reference: ref } });
}
export function merge(repo?: string | Repository, ref?: GitReference) {

+ 2
- 2
src/views/nodes/branchNode.ts View File

@ -50,8 +50,8 @@ export class BranchNode
view: BranchesView | CommitsView | RemotesView | RepositoriesView,
parent: ViewNode,
public readonly branch: GitBranch,
// Specifies that the node is shown as a root under the repository node
private readonly root: boolean,
// Specifies that the node is shown as a root and not nested under the branches node
public readonly root: boolean,
options?: {
expanded?: boolean;

+ 2
- 2
src/views/nodes/branchTrackingStatusNode.ts View File

@ -38,8 +38,8 @@ export class BranchTrackingStatusNode extends ViewNode implement
public readonly branch: GitBranch,
public readonly status: BranchTrackingStatus,
public readonly upstreamType: 'ahead' | 'behind' | 'same' | 'none',
// Specifies that the node is shown as a root under the repository node
private readonly root: boolean = false,
// Specifies that the node is shown as a root and not nested under the branches node
public readonly root: boolean = false,
) {
super(GitUri.fromRepoPath(status.repoPath), view, parent);
}

+ 6
- 4
src/views/viewCommands.ts View File

@ -324,10 +324,12 @@ export class ViewCommands {
}
@debug()
private fetch(node: RemoteNode | RepositoryNode | BranchTrackingStatusNode) {
private fetch(node: RemoteNode | RepositoryNode | BranchNode | BranchTrackingStatusNode) {
if (node instanceof RepositoryNode) return GitActions.fetch(node.repo);
if (node instanceof RemoteNode) return GitActions.Remote.fetch(node.remote.repoPath, node.remote.name);
if (node instanceof BranchTrackingStatusNode) return GitActions.fetch(node.repoPath);
if (node instanceof BranchNode || node instanceof BranchTrackingStatusNode) {
return GitActions.fetch(node.repoPath, node.root ? undefined : node.branch);
}
return Promise.resolve();
}
@ -424,7 +426,7 @@ export class ViewCommands {
private pull(node: RepositoryNode | BranchNode | BranchTrackingStatusNode) {
if (node instanceof RepositoryNode) return GitActions.pull(node.repo);
if (node instanceof BranchNode || node instanceof BranchTrackingStatusNode) {
return GitActions.pull(node.repoPath, node.branch);
return GitActions.pull(node.repoPath, node.root ? undefined : node.branch);
}
return Promise.resolve();
@ -434,7 +436,7 @@ export class ViewCommands {
private push(node: RepositoryNode | BranchNode | BranchTrackingStatusNode, force?: boolean) {
if (node instanceof RepositoryNode) return GitActions.push(node.repo, force);
if (node instanceof BranchNode || node instanceof BranchTrackingStatusNode) {
return GitActions.push(node.repoPath, undefined, node.branch);
return GitActions.push(node.repoPath, undefined, node.root ? undefined : node.branch);
}
return Promise.resolve();

Loading…
Cancel
Save