Skip to content

Commit

Permalink
Adds squash to merge git command
Browse files Browse the repository at this point in the history
Replaces terminal merge with merge git command
Replaces terminal rebase with rebase git command
  • Loading branch information
eamodio committed Aug 31, 2019
1 parent 5126e62 commit b8cbc95
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 106 deletions.
76 changes: 24 additions & 52 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2750,11 +2750,6 @@
"light": "images/light/icon-compare-threedot.svg"
}
},
{
"command": "gitlens.views.terminalCheckoutBranch",
"title": "Checkout Branch (via Terminal)",
"category": "GitLens"
},
{
"command": "gitlens.views.terminalCreateBranch",
"title": "Create Branch (via Terminal)...",
Expand All @@ -2766,23 +2761,18 @@
"category": "GitLens"
},
{
"command": "gitlens.views.terminalMergeBranch",
"title": "Merge Branch (via Terminal)",
"category": "GitLens"
},
{
"command": "gitlens.views.terminalRebaseBranch",
"title": "Rebase (Interactive) Branch (via Terminal)",
"command": "gitlens.views.mergeBranchInto",
"title": "Merge Branch into Current",
"category": "GitLens"
},
{
"command": "gitlens.views.terminalRebaseBranchToRemote",
"title": "Rebase (Interactive) Branch to Remote (via Terminal)",
"command": "gitlens.views.rebaseOntoBranch",
"title": "Rebase Current onto Branch",
"category": "GitLens"
},
{
"command": "gitlens.views.terminalSquashBranchIntoCommit",
"title": "Squash Branch into Commit (via Terminal)",
"command": "gitlens.views.rebaseOntoUpstream",
"title": "Rebase Current onto Upstream",
"category": "GitLens"
},
{
Expand Down Expand Up @@ -3653,10 +3643,6 @@
"command": "gitlens.views.setComparisonToThreeDot",
"when": "false"
},
{
"command": "gitlens.views.terminalCheckoutBranch",
"when": "false"
},
{
"command": "gitlens.views.terminalCreateBranch",
"when": "false"
Expand All @@ -3666,19 +3652,15 @@
"when": "false"
},
{
"command": "gitlens.views.terminalMergeBranch",
"when": "false"
},
{
"command": "gitlens.views.terminalRebaseBranch",
"command": "gitlens.views.mergeBranchInto",
"when": "false"
},
{
"command": "gitlens.views.terminalRebaseBranchToRemote",
"command": "gitlens.views.rebaseOntoBranch",
"when": "false"
},
{
"command": "gitlens.views.terminalSquashBranchIntoCommit",
"command": "gitlens.views.rebaseOntoUpstream",
"when": "false"
},
{
Expand Down Expand Up @@ -4439,6 +4421,21 @@
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.rebaseOntoUpstream",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+current\\b)(?=.*?\\b\\+tracking\\b)/",
"group": "1_gitlens_1@1"
},
{
"command": "gitlens.views.mergeBranchInto",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
"group": "1_gitlens_1@2"
},
{
"command": "gitlens.views.rebaseOntoBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
"group": "1_gitlens_1@3"
},
{
"command": "gitlens.openBranchInRemote",
"when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(tracking|remote)\\b)/",
Expand Down Expand Up @@ -4489,31 +4486,6 @@
"when": "viewItem =~ /gitlens:(branch|tag)\\b/",
"group": "7_gitlens_more@2"
},
{
"command": "gitlens.views.terminalCheckoutBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
"group": "8_gitlens@1"
},
{
"command": "gitlens.views.terminalRebaseBranchToRemote",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+current\\b)(?=.*?\\b\\+tracking\\b)/",
"group": "8_gitlens@1"
},
{
"command": "gitlens.views.terminalMergeBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
"group": "8_gitlens@2"
},
{
"command": "gitlens.views.terminalRebaseBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
"group": "8_gitlens@3"
},
{
"command": "gitlens.views.terminalSquashBranchIntoCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
"group": "8_gitlens@4"
},
{
"command": "gitlens.views.terminalCreateBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:(branch|commit|tag)\\b/",
Expand Down
38 changes: 35 additions & 3 deletions src/commands/git/cherry-pick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,45 @@ import { Logger } from '../../logger';
interface State {
repo: Repository;
destination: GitBranch;
source: GitBranch | GitReference;
source?: GitBranch | GitReference;
commits?: GitLogCommit[];
}

export interface CherryPickGitCommandArgs {
readonly command: 'cherry-pick';
state?: Partial<State>;
}

export class CherryPickGitCommand extends QuickCommandBase<State> {
constructor() {
constructor(args?: CherryPickGitCommandArgs) {
super('cherry-pick', 'cherry-pick', 'Cherry Pick', false, { description: 'via Terminal' });

if (args === undefined || args.state === undefined) return;

let counter = 0;
if (args.state.repo !== undefined) {
counter++;
}

if (args.state.destination !== undefined) {
counter++;
}

if (args.state.source !== undefined) {
counter++;

if (!GitBranch.is(args.state.source)) {
counter++;
}
} else if (args.state.commits !== undefined) {
counter++;
}

this._initialState = {
counter: counter,
confirm: true,
...args.state
};
}

execute(state: State) {
Expand All @@ -35,7 +67,7 @@ export class CherryPickGitCommand extends QuickCommandBase<State> {
runGitCommandInTerminal('cherry-pick', state.commits.map(c => c.sha).join(' '), state.repo.path, true);
}

runGitCommandInTerminal('cherry-pick', state.source.ref, state.repo.path, true);
runGitCommandInTerminal('cherry-pick', state.source!.ref, state.repo.path, true);
}

protected async *steps(): StepAsyncGenerator {
Expand Down
33 changes: 32 additions & 1 deletion src/commands/git/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,31 @@ interface State {
flags: string[];
}

export interface MergeGitCommandArgs {
readonly command: 'merge';
state?: Partial<State>;
}

export class MergeGitCommand extends QuickCommandBase<State> {
constructor() {
constructor(args?: MergeGitCommandArgs) {
super('merge', 'merge', 'Merge', false, { description: 'via Terminal' });

if (args === undefined || args.state === undefined) return;

let counter = 0;
if (args.state.repo !== undefined) {
counter++;
}

if (args.state.source !== undefined) {
counter++;
}

this._initialState = {
counter: counter,
confirm: true,
...args.state
};
}

execute(state: State) {
Expand Down Expand Up @@ -146,6 +168,15 @@ export class MergeGitCommand extends QuickCommandBase<State> {
count
)} from ${state.source.name} into ${state.destination.name}`,
item: ['--no-ff']
},
{
label: `Squash ${this.title}`,
description: `--squash ${state.source.name} into ${state.destination.name}`,
detail: `Will squash all commits into a single commit when merging ${Strings.pluralize(
'commit',
count
)} from ${state.source.name} into ${state.destination.name}`,
item: ['--squash']
}
]
);
Expand Down
24 changes: 23 additions & 1 deletion src/commands/git/rebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,31 @@ interface State {
flags: string[];
}

export interface RebaseGitCommandArgs {
readonly command: 'rebase';
state?: Partial<State>;
}

export class RebaseGitCommand extends QuickCommandBase<State> {
constructor() {
constructor(args?: RebaseGitCommandArgs) {
super('rebase', 'rebase', 'Rebase', false, { description: 'via Terminal' });

if (args === undefined || args.state === undefined) return;

let counter = 0;
if (args.state.repo !== undefined) {
counter++;
}

if (args.state.source !== undefined) {
counter++;
}

this._initialState = {
counter: counter,
confirm: true,
...args.state
};
}

execute(state: State) {
Expand Down
15 changes: 9 additions & 6 deletions src/commands/gitCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
StepSelection
} from './quickCommand';
import { Directive, DirectiveQuickPickItem } from '../quickpicks';
import { CherryPickGitCommand } from './git/cherry-pick';
import { CherryPickGitCommand, CherryPickGitCommandArgs } from './git/cherry-pick';
import { FetchGitCommand, FetchGitCommandArgs } from './git/fetch';
import { MergeGitCommand } from './git/merge';
import { MergeGitCommand, MergeGitCommandArgs } from './git/merge';
import { PullGitCommand, PullGitCommandArgs } from './git/pull';
import { PushGitCommand, PushGitCommandArgs } from './git/push';
import { RebaseGitCommand } from './git/rebase';
import { RebaseGitCommand, RebaseGitCommandArgs } from './git/rebase';
import { StashGitCommand, StashGitCommandArgs } from './git/stash';
import { SwitchGitCommand, SwitchGitCommandArgs } from './git/switch';
import { Container } from '../container';
Expand All @@ -25,9 +25,12 @@ import { configuration } from '../configuration';
const sanitizeLabel = /\$\(.+?\)|\W/g;

export type GitCommandsCommandArgs =
| CherryPickGitCommandArgs
| FetchGitCommandArgs
| MergeGitCommandArgs
| PullGitCommandArgs
| PushGitCommandArgs
| RebaseGitCommandArgs
| StashGitCommandArgs
| SwitchGitCommandArgs;

Expand All @@ -39,12 +42,12 @@ class PickCommandStep implements QuickPickStep {

constructor(args?: GitCommandsCommandArgs) {
this.items = [
new CherryPickGitCommand(),
new MergeGitCommand(),
new CherryPickGitCommand(args && args.command === 'cherry-pick' ? args : undefined),
new MergeGitCommand(args && args.command === 'merge' ? args : undefined),
new FetchGitCommand(args && args.command === 'fetch' ? args : undefined),
new PullGitCommand(args && args.command === 'pull' ? args : undefined),
new PushGitCommand(args && args.command === 'push' ? args : undefined),
new RebaseGitCommand(),
new RebaseGitCommand(args && args.command === 'rebase' ? args : undefined),
new StashGitCommand(args && args.command === 'stash' ? args : undefined),
new SwitchGitCommand(args && args.command === 'switch' ? args : undefined)
];
Expand Down
4 changes: 4 additions & 0 deletions src/views/nodes/branchTrackingStatusNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export class BranchTrackingStatusNode extends ViewNode<ViewWithFiles> implements
}):status:upstream:(${this.status.upstream}):${this.direction}`;
}

get repoPath(): string {
return this.uri.repoPath!;
}

async getChildren(): Promise<ViewNode[]> {
const ahead = this.direction === 'ahead';
const range = ahead
Expand Down

0 comments on commit b8cbc95

Please sign in to comment.