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

Add commit fixup and rebase with autosquash #573

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Config {
const userConfig = this.config.get('contextMenuActionsVisibility', {});
const config: ContextMenuActionsVisibility = {
branch: { checkout: true, rename: true, delete: true, merge: true, rebase: true, push: true, viewIssue: true, createPullRequest: true, createArchive: true, selectInBranchesDropdown: true, unselectInBranchesDropdown: true, copyName: true },
commit: { addTag: true, createBranch: true, checkout: true, cherrypick: true, revert: true, drop: true, merge: true, rebase: true, reset: true, copyHash: true, copySubject: true },
commit: { addTag: true, createBranch: true, checkout: true, cherrypick: true, commitFixup: true, revert: true, drop: true, merge: true, rebase: true, reset: true, copyHash: true, copySubject: true },
commitDetailsViewFile: { viewDiff: true, viewFileAtThisRevision: true, viewDiffWithWorkingFile: true, openFile: true, markAsReviewed: true, markAsNotReviewed: true, resetFileToThisRevision: true, copyAbsoluteFilePath: true, copyRelativeFilePath: true },
remoteBranch: { checkout: true, delete: true, fetch: true, merge: true, pull: true, viewIssue: true, createPullRequest: true, createArchive: true, selectInBranchesDropdown: true, unselectInBranchesDropdown: true, copyName: true },
stash: { apply: true, createBranch: true, pop: true, drop: true, copyName: true, copyHash: true },
Expand Down Expand Up @@ -218,7 +218,8 @@ class Config {
},
rebase: {
ignoreDate: !!this.config.get('dialog.rebase.ignoreDate', true),
interactive: !!this.config.get('dialog.rebase.launchInteractiveRebase', false)
interactive: !!this.config.get('dialog.rebase.launchInteractiveRebase', false),
autosquash: !!this.config.get('dialog.rebase.autosquash', false)
},
resetCommit: {
mode: resetCommitMode === 'Soft' ? GitResetMode.Soft : (resetCommitMode === 'Hard' ? GitResetMode.Hard : GitResetMode.Mixed)
Expand Down
19 changes: 17 additions & 2 deletions src/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,13 +1001,17 @@ export class DataSource extends Disposable {
* @param actionOn Is the rebase on a branch or commit.
* @param ignoreDate Is `--ignore-date` enabled.
* @param interactive Should the rebase be performed interactively.
* @param autosquash Is `--autosquash` enabled.
* @returns The ErrorInfo from the executed command.
*/
public rebase(repo: string, obj: string, actionOn: RebaseActionOn, ignoreDate: boolean, interactive: boolean) {
public rebase(repo: string, obj: string, actionOn: RebaseActionOn, ignoreDate: boolean, interactive: boolean, autosquash: boolean) {
if (interactive) {
return this.openGitTerminal(
repo,
'rebase --interactive ' + (getConfig().signCommits ? '-S ' : '') + (actionOn === RebaseActionOn.Branch ? obj.replace(/'/g, '"\'"') : obj),
'rebase --interactive ' +
(autosquash ? '--autosquash ' : '') +
(getConfig().signCommits ? '-S ' : '') +
(actionOn === RebaseActionOn.Branch ? obj.replace(/'/g, '"\'"') : obj),
'Rebase on "' + (actionOn === RebaseActionOn.Branch ? obj : abbrevCommit(obj)) + '"'
);
} else {
Expand Down Expand Up @@ -1092,6 +1096,17 @@ export class DataSource extends Disposable {
return this.runGitCommand(args, repo);
}

/**
* Commit the stashed files to fixup a commit.
* @param repo The path of the repository.
* @param commitHash The hash of the commit to drop.
* @returns The ErrorInfo from the executed command.
*/
public commitFixup(repo: string, commitHash: string) {
const args = ['commit', '--fixup=' + commitHash];
return this.runGitCommand(args, repo);
}

/**
* Reset the current branch to a specified commit.
* @param repo The path of the repository.
Expand Down
9 changes: 8 additions & 1 deletion src/gitGraphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ export class GitGraphView extends Disposable {
refresh: msg.refresh
});
break;
case 'commitFixup':
this.sendMessage({
command: 'commitFixup',
commitHash: msg.commitHash,
error: await this.dataSource.commitFixup(msg.repo, msg.commitHash)
});
break;
case 'compareCommits':
this.sendMessage({
command: 'compareCommits',
Expand Down Expand Up @@ -528,7 +535,7 @@ export class GitGraphView extends Disposable {
command: 'rebase',
actionOn: msg.actionOn,
interactive: msg.interactive,
error: await this.dataSource.rebase(msg.repo, msg.obj, msg.actionOn, msg.ignoreDate, msg.interactive)
error: await this.dataSource.rebase(msg.repo, msg.obj, msg.actionOn, msg.ignoreDate, msg.interactive, msg.autosquash)
});
break;
case 'renameBranch':
Expand Down
16 changes: 16 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ export interface ContextMenuActionsVisibility {
readonly createBranch: boolean;
readonly checkout: boolean;
readonly cherrypick: boolean;
readonly commitFixup: boolean;
readonly revert: boolean;
readonly drop: boolean;
readonly merge: boolean;
Expand Down Expand Up @@ -496,6 +497,7 @@ export interface DialogDefaults {
readonly rebase: {
readonly ignoreDate: boolean,
readonly interactive: boolean
readonly autosquash: boolean
};
readonly resetCommit: {
readonly mode: GitResetMode
Expand Down Expand Up @@ -686,6 +688,17 @@ export interface RequestCommitDetails extends RepoRequest {
readonly avatarEmail: string | null; // string => fetch avatar with the given email, null => don't fetch avatar
readonly refresh: boolean;
}

export interface ResponseCommitFixup extends ResponseWithErrorInfo {
readonly command: 'commitFixup';
readonly commitHash: string;
}

export interface RequestCommitFixup extends RepoRequest {
readonly command: 'commitFixup';
readonly commitHash: string;
}

export interface ResponseCommitDetails extends ResponseWithErrorInfo {
readonly command: 'commitDetails';
readonly commitDetails: GitCommitDetails | null;
Expand Down Expand Up @@ -1095,6 +1108,7 @@ export interface RequestRebase extends RepoRequest {
readonly actionOn: RebaseActionOn;
readonly ignoreDate: boolean;
readonly interactive: boolean;
readonly autosquash: boolean;
}
export interface ResponseRebase extends ResponseWithErrorInfo {
readonly command: 'rebase';
Expand Down Expand Up @@ -1257,6 +1271,7 @@ export type RequestMessage =
| RequestCherrypickCommit
| RequestCleanUntrackedFiles
| RequestCommitDetails
| RequestCommitFixup
| RequestCompareCommits
| RequestCopyFilePath
| RequestCopyToClipboard
Expand Down Expand Up @@ -1322,6 +1337,7 @@ export type ResponseMessage =
| ResponseCleanUntrackedFiles
| ResponseCompareCommits
| ResponseCommitDetails
| ResponseCommitFixup
| ResponseCopyFilePath
| ResponseCopyToClipboard
| ResponseCreateArchive
Expand Down
15 changes: 14 additions & 1 deletion web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,10 @@ class GitGraphView {
title: 'Create Branch' + ELLIPSIS,
visible: visibility.createBranch,
onClick: () => this.createBranchAction(hash, '', this.config.dialogDefaults.createBranch.checkout, target)
}, {
title: 'Fixup this Commit',
visible: visibility.commitFixup,
onClick: () => this.commitFixupAction(hash)
}
], [
{
Expand Down Expand Up @@ -1688,13 +1692,19 @@ class GitGraphView {
private rebaseAction(obj: string, name: string, actionOn: GG.RebaseActionOn, target: DialogTarget & (CommitTarget | RefTarget)) {
dialog.showForm('Are you sure you want to rebase ' + (this.gitBranchHead !== null ? '<b><i>' + escapeHtml(this.gitBranchHead) + '</i></b> (the current branch)' : 'the current branch') + ' on ' + actionOn.toLowerCase() + ' <b><i>' + escapeHtml(name) + '</i></b>?', [
{ type: DialogInputType.Checkbox, name: 'Launch Interactive Rebase in new Terminal', value: this.config.dialogDefaults.rebase.interactive },
{ type: DialogInputType.Checkbox, name: 'Auto-squash', value: this.config.dialogDefaults.rebase.autosquash, info: 'Only applicable to an interactive rebase.' },
{ type: DialogInputType.Checkbox, name: 'Ignore Date', value: this.config.dialogDefaults.rebase.ignoreDate, info: 'Only applicable to a non-interactive rebase.' }
], 'Yes, rebase', (values) => {
let interactive = <boolean>values[0];
runAction({ command: 'rebase', repo: this.currentRepo, obj: obj, actionOn: actionOn, ignoreDate: <boolean>values[1], interactive: interactive }, interactive ? 'Launching Interactive Rebase' : 'Rebasing on ' + actionOn);
let autosquash = interactive && <boolean>values[1];
let ignoreDate = !interactive && <boolean>values[2];
runAction({ command: 'rebase', repo: this.currentRepo, obj: obj, actionOn: actionOn, ignoreDate: ignoreDate, interactive: interactive, autosquash: autosquash }, interactive ? 'Launching Interactive Rebase' : 'Rebasing on ' + actionOn);
}, target);
}

private commitFixupAction(hash: string) {
runAction({ command: 'commitFixup', repo: this.currentRepo, commitHash: hash }, 'Commiting Fixup');
}

/* Table Utils */

Expand Down Expand Up @@ -3229,6 +3239,9 @@ window.addEventListener('load', () => {
dialog.showError('Unable to load Commit Details', msg.error, null, null);
}
break;
case 'commitFixup':
refreshOrDisplayError(msg.error, 'Unable to Commit');
break;
case 'compareCommits':
if (msg.error === null) {
gitGraph.showCommitComparison(msg.commitHash, msg.compareWithHash, msg.fileChanges, gitGraph.createFileTree(msg.fileChanges, msg.codeReview), msg.codeReview, msg.codeReview !== null ? msg.codeReview.lastViewedFile : null, msg.refresh);
Expand Down