Skip to content

Commit

Permalink
#128 New "Fetch into local branch..." action on the remote branch con…
Browse files Browse the repository at this point in the history
…text menu.
  • Loading branch information
mhutchie committed Sep 23, 2019
1 parent b9f8f12 commit af26632
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ export class DataSource {
return remoteStatus;
}

public fetchIntoLocalBranch(repo: string, remote: string, remoteBranch: string, localBranch: string) {
return this.runGitCommand(['fetch', remote, remoteBranch + ':' + localBranch], repo);
}

public async pullBranch(repo: string, branchName: string, remote: string, createNewCommit: boolean, squash: boolean) {
let args = ['pull', remote, branchName];
if (squash) args.push('--squash');
Expand Down
6 changes: 6 additions & 0 deletions src/gitGraphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ export class GitGraphView {
case 'fetchAvatar':
this.avatarManager.fetchAvatarImage(msg.email, msg.repo, msg.remote, msg.commits);
break;
case 'fetchIntoLocalBranch':
this.sendMessage({
command: 'fetchIntoLocalBranch',
error: await this.dataSource.fetchIntoLocalBranch(msg.repo, msg.remote, msg.remoteBranch, msg.localBranch)
});
break;
case 'endCodeReview':
this.extensionState.endCodeReview(msg.repo, msg.id);
break;
Expand Down
12 changes: 12 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,16 @@ export interface ResponseFetchAvatar extends BaseMessage {
readonly image: string;
}

export interface RequestFetchIntoLocalBranch extends RepoRequest {
readonly command: 'fetchIntoLocalBranch';
readonly remote: string;
readonly remoteBranch: string;
readonly localBranch: string;
}
export interface ResponseFetchIntoLocalBranch extends ResponseWithErrorInfo {
readonly command: 'fetchIntoLocalBranch';
}

export interface RequestGetSettings extends RepoRequest {
readonly command: 'getSettings';
}
Expand Down Expand Up @@ -747,6 +757,7 @@ export type RequestMessage =
| RequestEndCodeReview
| RequestFetch
| RequestFetchAvatar
| RequestFetchIntoLocalBranch
| RequestGetSettings
| RequestLoadBranches
| RequestLoadCommits
Expand Down Expand Up @@ -793,6 +804,7 @@ export type ResponseMessage =
| ResponseEditRemote
| ResponseFetch
| ResponseFetchAvatar
| ResponseFetchIntoLocalBranch
| ResponseGetSettings
| ResponseLoadBranches
| ResponseLoadCommits
Expand Down
52 changes: 33 additions & 19 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,28 +860,39 @@ class GitGraphView {
title: 'Checkout Branch' + ELLIPSIS,
onClick: () => this.checkoutBranchAction(refName, remote, null)
});
if (remote !== '') { // If the remote of the remote branch ref is known
menu.push(
{
title: 'Delete Remote Branch' + ELLIPSIS,
onClick: () => {
dialog.showConfirmation('Are you sure you want to delete the remote branch <b><i>' + escapeHtml(refName) + '</i></b>?', () => {
runAction({ command: 'deleteRemoteBranch', repo: this.currentRepo, branchName: refName.substr(remote.length + 1), remote: remote }, 'Deleting Remote Branch');
}, null);
}
},
{
title: 'Pull into current branch' + ELLIPSIS,
if (remote !== '') {
// The remote is known
let branchName = refName.substring(remote.length + 1);
menu.push({
title: 'Delete Remote Branch' + ELLIPSIS,
onClick: () => {
dialog.showConfirmation('Are you sure you want to delete the remote branch <b><i>' + escapeHtml(refName) + '</i></b>?', () => {
runAction({ command: 'deleteRemoteBranch', repo: this.currentRepo, branchName: branchName, remote: remote }, 'Deleting Remote Branch');
}, null);
}
});
if (this.gitBranches.includes(branchName) && this.gitBranchHead !== branchName) {
// A local branch has the same name as the remote branch, and it is not checked out
menu.push({
title: 'Fetch into local branch' + ELLIPSIS,
onClick: () => {
dialog.showForm('Are you sure you want to pull branch <b><i>' + escapeHtml(refName) + '</i></b> into the current branch? If a merge is required:', [
{ type: 'checkbox', name: 'Create a new commit even if fast-forward is possible', value: false },
{ type: 'checkbox', name: 'Squash commits', value: false }
], 'Yes, pull', values => {
runAction({ command: 'pullBranch', repo: this.currentRepo, branchName: refName.substr(remote.length + 1), remote: remote, createNewCommit: values[0] === 'checked', squash: values[1] === 'checked' }, 'Pulling Branch');
dialog.showConfirmation('Are you sure you want to fetch the remote branch <b><i>' + escapeHtml(refName) + '</i></b> into the local branch <b><i>' + escapeHtml(branchName) + '</i></b>?', () => {
runAction({ command: 'fetchIntoLocalBranch', repo: this.currentRepo, remote: remote, remoteBranch: branchName, localBranch: branchName }, 'Fetching Branch');
}, null);
}
});
}
menu.push({
title: 'Pull into current branch' + ELLIPSIS,
onClick: () => {
dialog.showForm('Are you sure you want to pull the remote branch <b><i>' + escapeHtml(refName) + '</i></b> into the current branch? If a merge is required:', [
{ type: 'checkbox', name: 'Create a new commit even if fast-forward is possible', value: false },
{ type: 'checkbox', name: 'Squash commits', value: false }
], 'Yes, pull', values => {
runAction({ command: 'pullBranch', repo: this.currentRepo, branchName: branchName, remote: remote, createNewCommit: values[0] === 'checked', squash: values[1] === 'checked' }, 'Pulling Branch');
}, null);
}
);
});
}
}
copyType = 'Branch Name';
Expand Down Expand Up @@ -998,7 +1009,7 @@ class GitGraphView {

private checkoutBranchAction(refName: string, remote: string | null, prefillName: string | null) {
if (remote !== null) {
dialog.showRefInput('Enter the name of the new branch you would like to create when checking out <b><i>' + escapeHtml(refName) + '</i></b>:', (prefillName !== null ? prefillName : (remote !== '' ? refName.substr(remote.length + 1) : refName)), 'Checkout Branch', newBranch => {
dialog.showRefInput('Enter the name of the new branch you would like to create when checking out <b><i>' + escapeHtml(refName) + '</i></b>:', (prefillName !== null ? prefillName : (remote !== '' ? refName.substring(remote.length + 1) : refName)), 'Checkout Branch', newBranch => {
if (this.gitBranches.includes(newBranch)) {
dialog.showTwoButtons('The name <b><i>' + escapeHtml(newBranch) + '</i></b> is already used by another branch:', 'Choose another branch name', () => {
this.checkoutBranchAction(refName, remote, newBranch);
Expand Down Expand Up @@ -1910,6 +1921,9 @@ window.addEventListener('load', () => {
gitGraph.loadAvatar(msg.email, resizedImage);
});
break;
case 'fetchIntoLocalBranch':
refreshOrDisplayError(msg.error, 'Unable to Fetch into Local Branch');
break;
case 'getSettings':
settingsWidget.loadSettings(msg.settings, msg.error);
break;
Expand Down

0 comments on commit af26632

Please sign in to comment.