From f2627d69f6fc48f641427e15e7a2acf7923d8027 Mon Sep 17 00:00:00 2001 From: Michael Hutchison Date: Mon, 18 Nov 2019 13:32:10 +1100 Subject: [PATCH] Type & code refactoring and improvements. --- src/avatarManager.ts | 13 +++++- src/config.ts | 5 +- src/dataSource.ts | 50 +++++++++++--------- src/extensionState.ts | 3 +- src/gitGraphView.ts | 18 ++++---- src/types.ts | 103 ++++++++++++++++++++++-------------------- web/dialog.ts | 2 +- web/main.ts | 42 ++++++++--------- 8 files changed, 131 insertions(+), 105 deletions(-) diff --git a/src/avatarManager.ts b/src/avatarManager.ts index 6c12fc0b..2e8ced39 100644 --- a/src/avatarManager.ts +++ b/src/avatarManager.ts @@ -7,7 +7,6 @@ import { DataSource } from './dataSource'; import { ExtensionState } from './extensionState'; import { GitGraphView } from './gitGraphView'; import { Logger, maskEmail } from './logger'; -import { AvatarCache } from './types'; export class AvatarManager { private readonly dataSource: DataSource; @@ -383,6 +382,14 @@ class AvatarRequestQueue { } } +export interface Avatar { + image: string; + timestamp: number; + identicon: boolean; +} + +export type AvatarCache = { [email: string]: Avatar }; + interface AvatarRequestItem { email: string; repo: string; @@ -391,15 +398,19 @@ interface AvatarRequestItem { checkAfter: number; attempts: number; } + interface GitHubRemoteSource { type: 'github'; owner: string; repo: string; } + interface GitLabRemoteSource { type: 'gitlab'; } + interface GravatarRemoteSource { type: 'gravatar'; } + type RemoteSource = GitHubRemoteSource | GitLabRemoteSource | GravatarRemoteSource; \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index 1f0d0d33..2567dbe8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -11,6 +11,7 @@ import { DefaultColumnVisibility, DialogDefaults, FileViewType, + GitResetMode, GraphStyle, RefLabelAlignment, TabIconColourTheme @@ -145,10 +146,10 @@ class Config { interactive: !!this.config.get('dialog.rebase.launchInteractiveRebase', false) }, resetCommit: { - mode: resetCommitMode === 'Soft' ? 'soft' : (resetCommitMode === 'Hard' ? 'hard' : 'mixed') + mode: resetCommitMode === 'Soft' ? GitResetMode.Soft : (resetCommitMode === 'Hard' ? GitResetMode.Hard : GitResetMode.Mixed) }, resetUncommitted: { - mode: resetUncommittedMode === 'Hard' ? 'hard' : 'mixed' + mode: resetUncommittedMode === 'Hard' ? GitResetMode.Hard : GitResetMode.Mixed }, stashUncommittedChanges: { includeUntracked: !!this.config.get('dialog.stashUncommittedChanges.includeUntracked', true) diff --git a/src/dataSource.ts b/src/dataSource.ts index 3be8c76d..6b4db786 100644 --- a/src/dataSource.ts +++ b/src/dataSource.ts @@ -6,7 +6,7 @@ import { Uri } from 'vscode'; import { AskpassEnvironment, AskpassManager } from './askpass/askpassManager'; import { getConfig } from './config'; import { Logger } from './logger'; -import { BranchOrCommit, CommitOrdering, DateType, ErrorInfo, GitCommitDetails, GitCommitNode, GitCommitStash, GitFileChange, GitFileStatus, GitRepoSettings, GitResetMode } from './types'; +import { ActionOn, CommitOrdering, DateType, ErrorInfo, GitCommitDetails, GitCommitNode, GitCommitStash, GitFileChange, GitFileStatus, GitRepoSettings, GitResetMode } from './types'; import { abbrevCommit, compareVersions, constructIncompatibleGitVersionMessage, getPathFromStr, getPathFromUri, GitExecutable, realpath, runGitCommandInNewTerminal, UNABLE_TO_FIND_GIT_MSG, UNCOMMITTED } from './utils'; @@ -184,20 +184,20 @@ export class DataSource { /* Get Data Methods - Commit Details View */ - public getCommitDetails(repo: string, commitHash: string): Promise { + public getCommitDetails(repo: string, commitHash: string): Promise { return Promise.all([ this.getCommitDetailsBase(repo, commitHash), this.getDiffNameStatus(repo, commitHash, commitHash), this.getDiffNumStat(repo, commitHash, commitHash) ]).then((results) => { results[0].fileChanges = generateFileChanges(results[1], results[2], null); - return results[0]; + return { commitDetails: results[0], error: null }; }).catch((errorMessage) => { - return { hash: '', parents: [], author: '', email: '', date: 0, committer: '', body: '', fileChanges: [], error: errorMessage }; + return { commitDetails: null, error: errorMessage }; }); } - public getStashDetails(repo: string, commitHash: string, stash: GitCommitStash): Promise { + public getStashDetails(repo: string, commitHash: string, stash: GitCommitStash): Promise { return Promise.all([ this.getCommitDetailsBase(repo, commitHash), this.getDiffNameStatus(repo, stash.baseHash, commitHash), @@ -214,24 +214,27 @@ export class DataSource { } }); } - return results[0]; + return { commitDetails: results[0], error: null }; }).catch((errorMessage) => { - return { hash: '', parents: [], author: '', email: '', date: 0, committer: '', body: '', fileChanges: [], error: errorMessage }; + return { commitDetails: null, error: errorMessage }; }); } - public getUncommittedDetails(repo: string): Promise { - let details: GitCommitDetails = { hash: UNCOMMITTED, parents: [], author: '', email: '', date: 0, committer: '', body: '', fileChanges: [], error: null }; + public getUncommittedDetails(repo: string): Promise { return Promise.all([ this.getDiffNameStatus(repo, 'HEAD', ''), this.getDiffNumStat(repo, 'HEAD', ''), this.getStatus(repo) ]).then((results) => { - details.fileChanges = generateFileChanges(results[0], results[1], results[2]); - return details; + return { + commitDetails: { + hash: UNCOMMITTED, parents: [], author: '', email: '', date: 0, committer: '', body: '', + fileChanges: generateFileChanges(results[0], results[1], results[2]) + }, + error: null + }; }).catch((errorMessage) => { - details.error = errorMessage; - return details; + return { commitDetails: null, error: errorMessage }; }); } @@ -518,7 +521,7 @@ export class DataSource { /* Git Action Methods - Branches & Commits */ - public async merge(repo: string, obj: string, type: BranchOrCommit, createNewCommit: boolean, squash: boolean) { + public async merge(repo: string, obj: string, actionOn: ActionOn, createNewCommit: boolean, squash: boolean) { let args = ['merge', obj]; if (squash) args.push('--squash'); else if (createNewCommit) args.push('--no-ff'); @@ -526,20 +529,20 @@ export class DataSource { let mergeStatus = await this.runGitCommand(args, repo); if (mergeStatus === null && squash) { if (await this.areStagedChanges(repo)) { - return this.runGitCommand(['commit', '-m', 'Merge ' + type.toLowerCase() + ' \'' + obj + '\''], repo); + return this.runGitCommand(['commit', '-m', 'Merge ' + actionOn.toLowerCase() + ' \'' + obj + '\''], repo); } } return mergeStatus; } - public rebase(repo: string, obj: string, type: BranchOrCommit, ignoreDate: boolean, interactive: boolean) { + public rebase(repo: string, obj: string, actionOn: ActionOn, ignoreDate: boolean, interactive: boolean) { if (interactive) { return new Promise(resolve => { if (this.gitExecutable === null) return resolve(UNABLE_TO_FIND_GIT_MSG); runGitCommandInNewTerminal(repo, this.gitExecutable.path, - 'rebase --interactive ' + (type === 'Branch' ? obj.replace(/'/g, '"\'"') : obj), - 'Git Rebase on "' + (type === 'Branch' ? obj : abbrevCommit(obj)) + '"'); + 'rebase --interactive ' + (actionOn === ActionOn.Branch ? obj.replace(/'/g, '"\'"') : obj), + 'Git Rebase on "' + (actionOn === ActionOn.Branch ? obj : abbrevCommit(obj)) + '"'); setTimeout(() => resolve(null), 1000); }); } else { @@ -568,8 +571,8 @@ export class DataSource { return this.runGitCommand(['rebase', '--onto', commitHash + '^', commitHash], repo); } - public resetToCommit(repo: string, commitHash: string, resetMode: GitResetMode) { - return this.runGitCommand(['reset', '--' + resetMode, commitHash], repo); + public resetToCommit(repo: string, commit: string, resetMode: GitResetMode) { + return this.runGitCommand(['reset', '--' + resetMode, commit], repo); } public revertCommit(repo: string, commitHash: string, parentIndex: number) { @@ -668,7 +671,7 @@ export class DataSource { date: parseInt(commitInfo[4]), committer: commitInfo[5], body: lines.slice(1, lastLine + 1).join('\n'), - fileChanges: [], error: null + fileChanges: [] }; }); } @@ -1031,6 +1034,11 @@ interface GitCommitData { error: ErrorInfo; } +export interface GitCommitDetailsData { + commitDetails: GitCommitDetails | null; + error: ErrorInfo; +} + interface GitCommitComparisonData { fileChanges: GitFileChange[]; error: ErrorInfo; diff --git a/src/extensionState.ts b/src/extensionState.ts index 8e22072f..5e533baa 100644 --- a/src/extensionState.ts +++ b/src/extensionState.ts @@ -1,6 +1,7 @@ import * as fs from 'fs'; import { ExtensionContext, Memento } from 'vscode'; -import { Avatar, AvatarCache, CodeReview, ErrorInfo, FileViewType, GitRepoSet, GitRepoState } from './types'; +import { Avatar, AvatarCache } from './avatarManager'; +import { CodeReview, ErrorInfo, FileViewType, GitRepoSet, GitRepoState } from './types'; import { getPathFromStr } from './utils'; const AVATAR_STORAGE_FOLDER = '/avatars'; diff --git a/src/gitGraphView.ts b/src/gitGraphView.ts index 87b335bd..c46162b5 100644 --- a/src/gitGraphView.ts +++ b/src/gitGraphView.ts @@ -2,12 +2,12 @@ import * as path from 'path'; import * as vscode from 'vscode'; import { AvatarManager } from './avatarManager'; import { getConfig } from './config'; -import { DataSource } from './dataSource'; +import { DataSource, GitCommitDetailsData } from './dataSource'; import { ExtensionState } from './extensionState'; import { Logger } from './logger'; import { RepoFileWatcher } from './repoFileWatcher'; import { RepoManager } from './repoManager'; -import { ErrorInfo, GitCommitDetails, GitGraphViewInitialState, GitRepoSet, RefLabelAlignment, RequestMessage, ResponseMessage, TabIconColourTheme } from './types'; +import { ErrorInfo, GitGraphViewInitialState, GitRepoSet, RefLabelAlignment, RequestMessage, ResponseMessage, TabIconColourTheme } from './types'; import { copyFilePathToClipboard, copyToClipboard, getNonce, openFile, UNABLE_TO_FIND_GIT_MSG, UNCOMMITTED, viewDiff, viewScm } from './utils'; export class GitGraphView { @@ -156,7 +156,7 @@ export class GitGraphView { this.extensionState.updateCodeReviewFileReviewed(msg.repo, msg.id, msg.filePath); break; case 'commitDetails': - let data = await Promise.all([ + let data = await Promise.all([ msg.commitHash === UNCOMMITTED ? this.dataSource.getUncommittedDetails(msg.repo) : msg.stash === null @@ -166,7 +166,7 @@ export class GitGraphView { ]); this.sendMessage({ command: 'commitDetails', - commitDetails: data[0], + ...data[0], avatar: data[1], codeReview: msg.commitHash !== UNCOMMITTED ? this.extensionState.getCodeReview(msg.repo, msg.commitHash) : null, refresh: msg.refresh @@ -301,8 +301,8 @@ export class GitGraphView { break; case 'merge': this.sendMessage({ - command: 'merge', type: msg.type, - error: await this.dataSource.merge(msg.repo, msg.obj, msg.type, msg.createNewCommit, msg.squash) + command: 'merge', actionOn: msg.actionOn, + error: await this.dataSource.merge(msg.repo, msg.obj, msg.actionOn, msg.createNewCommit, msg.squash) }); break; case 'openFile': @@ -349,8 +349,8 @@ export class GitGraphView { break; case 'rebase': this.sendMessage({ - command: 'rebase', type: msg.type, interactive: msg.interactive, - error: await this.dataSource.rebase(msg.repo, msg.obj, msg.type, msg.ignoreDate, msg.interactive) + command: 'rebase', actionOn: msg.actionOn, interactive: msg.interactive, + error: await this.dataSource.rebase(msg.repo, msg.obj, msg.actionOn, msg.ignoreDate, msg.interactive) }); break; case 'renameBranch': @@ -367,7 +367,7 @@ export class GitGraphView { case 'resetToCommit': this.sendMessage({ command: 'resetToCommit', - error: await this.dataSource.resetToCommit(msg.repo, msg.commitHash, msg.resetMode) + error: await this.dataSource.resetToCommit(msg.repo, msg.commit, msg.resetMode) }); break; case 'revertCommit': diff --git a/src/types.ts b/src/types.ts index 964898a7..8e61ef62 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,15 +1,5 @@ /* Git Interfaces / Types */ -export interface GitRepoSettings { - remotes: GitRepoSettingsRemote[]; -} - -export interface GitRepoSettingsRemote { - name: string; - url: string | null; - pushUrl: string | null; -} - export interface GitCommitNode { hash: string; parents: string[]; @@ -24,13 +14,13 @@ export interface GitCommitNode { } export interface GitCommitTag { - name: string; - annotated: boolean; + readonly name: string; + readonly annotated: boolean; } export interface GitCommitRemote { - name: string; - remote: string | null; // null => remote not found, otherwise => remote name + readonly name: string; + readonly remote: string | null; // null => remote not found, otherwise => remote name } export interface GitCommitStash { @@ -48,20 +38,8 @@ export interface GitCommitDetails { committer: string; body: string; fileChanges: GitFileChange[]; - error: ErrorInfo; } -export type GitRepoSet = { [repo: string]: GitRepoState }; -export interface GitRepoState { - columnWidths: ColumnWidth[] | null; - cdvDivider: number; - cdvHeight: number; - fileViewType: FileViewType; - showRemoteBranches: boolean; - hideRemotes: string[]; -} -export type ColumnWidth = number; - export interface GitFileChange { oldFilePath: string; newFilePath: string; @@ -70,6 +48,33 @@ export interface GitFileChange { deletions: number | null; } +export const enum GitFileStatus { + Added = 'A', + Modified = 'M', + Deleted = 'D', + Renamed = 'R', + Untracked = 'U' +} + +export interface GitRepoSettings { + readonly remotes: GitRepoSettingsRemote[]; +} + +export interface GitRepoSettingsRemote { + readonly name: string; + readonly url: string | null; + readonly pushUrl: string | null; +} + +export const enum GitResetMode { + Soft = 'soft', + Mixed = 'mixed', + Hard = 'hard' +} + + +/* Git Repo State */ + export interface CodeReview { id: string; lastActive: number; @@ -77,22 +82,17 @@ export interface CodeReview { remainingFiles: string[]; } -export interface Avatar { - image: string; - timestamp: number; - identicon: boolean; -} -export type AvatarCache = { [email: string]: Avatar }; +export type ColumnWidth = number; -export type BranchOrCommit = 'Branch' | 'Commit'; -export type GitResetMode = 'soft' | 'mixed' | 'hard'; +export type GitRepoSet = { [repo: string]: GitRepoState }; -export const enum GitFileStatus { - Added = 'A', - Modified = 'M', - Deleted = 'D', - Renamed = 'R', - Untracked = 'U' +export interface GitRepoState { + columnWidths: ColumnWidth[] | null; + cdvDivider: number; + cdvHeight: number; + fileViewType: FileViewType; + showRemoteBranches: boolean; + hideRemotes: string[]; } @@ -252,10 +252,10 @@ export interface DialogDefaults { readonly interactive: boolean }; readonly resetCommit: { - readonly mode: 'soft' | 'mixed' | 'hard' + readonly mode: GitResetMode }; readonly resetUncommitted: { - readonly mode: 'mixed' | 'hard' + readonly mode: Exclude }; readonly stashUncommittedChanges: { readonly includeUntracked: boolean @@ -303,6 +303,11 @@ export interface ResponseWithMultiErrorInfo extends BaseMessage { readonly errors: ErrorInfo[]; } +export const enum ActionOn { + Branch = 'Branch', + Commit = 'Commit' +} + export type ErrorInfo = string | null; // null => no error, otherwise => error message @@ -397,9 +402,9 @@ 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 ResponseCommitDetails extends BaseMessage { +export interface ResponseCommitDetails extends ResponseWithErrorInfo { readonly command: 'commitDetails'; - readonly commitDetails: GitCommitDetails; + readonly commitDetails: GitCommitDetails | null; readonly avatar: string | null; readonly codeReview: CodeReview | null; readonly refresh: boolean; @@ -605,13 +610,13 @@ export interface ResponseLoadRepos extends BaseMessage { export interface RequestMerge extends RepoRequest { readonly command: 'merge'; readonly obj: string; - readonly type: BranchOrCommit; + readonly actionOn: ActionOn; readonly createNewCommit: boolean; readonly squash: boolean; } export interface ResponseMerge extends ResponseWithErrorInfo { readonly command: 'merge'; - readonly type: BranchOrCommit; + readonly actionOn: ActionOn; } export interface RequestOpenFile extends RepoRequest { @@ -682,13 +687,13 @@ export interface ResponsePushTag extends ResponseWithErrorInfo { export interface RequestRebase extends RepoRequest { readonly command: 'rebase'; readonly obj: string; - readonly type: BranchOrCommit; + readonly actionOn: ActionOn; readonly ignoreDate: boolean; readonly interactive: boolean; } export interface ResponseRebase extends ResponseWithErrorInfo { readonly command: 'rebase'; - readonly type: BranchOrCommit; + readonly actionOn: ActionOn; readonly interactive: boolean; } @@ -711,7 +716,7 @@ export interface RequestRescanForRepos extends BaseMessage { export interface RequestResetToCommit extends RepoRequest { readonly command: 'resetToCommit'; - readonly commitHash: string; + readonly commit: string; readonly resetMode: GitResetMode; } export interface ResponseResetToCommit extends ResponseWithErrorInfo { diff --git a/web/dialog.ts b/web/dialog.ts index 7a8d4740..487e06bf 100644 --- a/web/dialog.ts +++ b/web/dialog.ts @@ -120,7 +120,7 @@ class Dialog { this.show(DialogType.Message, html, null, 'Close', null, null, null); } - public showError(message: string, reason: string | null, actionName: string | null, actioned: (() => void) | null, sourceElem: HTMLElement | null) { + public showError(message: string, reason: GG.ErrorInfo, actionName: string | null, actioned: (() => void) | null, sourceElem: HTMLElement | null) { this.show(DialogType.Message, '' + SVG_ICONS.alert + 'Error: ' + message + '' + (reason !== null ? '
' + escapeHtml(reason).split('\n').join('
') + '
' : ''), actionName, 'Dismiss', () => { this.close(); if (actioned !== null) actioned(); diff --git a/web/main.ts b/web/main.ts index 5014c86e..ed959382 100644 --- a/web/main.ts +++ b/web/main.ts @@ -737,11 +737,11 @@ class GitGraphView { }, { title: 'Merge into current branch' + ELLIPSIS, visible: visibility.merge && this.gitBranchHead !== refName, - onClick: () => this.mergeAction(refName, refName, 'Branch', sourceElem) + onClick: () => this.mergeAction(refName, refName, GG.ActionOn.Branch, sourceElem) }, { title: 'Rebase current branch on Branch' + ELLIPSIS, visible: visibility.rebase && this.gitBranchHead !== refName, - onClick: () => this.rebaseAction(refName, refName, 'Branch', sourceElem) + onClick: () => this.rebaseAction(refName, refName, GG.ActionOn.Branch, sourceElem) }, { title: 'Push Branch' + ELLIPSIS, visible: visibility.push && this.gitRemotes.length > 0, @@ -889,21 +889,21 @@ class GitGraphView { { title: 'Merge into current branch' + ELLIPSIS, visible: visibility.merge, - onClick: () => this.mergeAction(hash, abbrevCommit(hash), 'Commit', commitElem) + onClick: () => this.mergeAction(hash, abbrevCommit(hash), GG.ActionOn.Commit, commitElem) }, { title: 'Rebase current branch on this Commit' + ELLIPSIS, visible: visibility.rebase, - onClick: () => this.rebaseAction(hash, abbrevCommit(hash), 'Commit', commitElem) + onClick: () => this.rebaseAction(hash, abbrevCommit(hash), GG.ActionOn.Commit, commitElem) }, { title: 'Reset current branch to this Commit' + ELLIPSIS, visible: visibility.reset, onClick: () => { dialog.showSelect('Are you sure you want to reset the current branch to commit ' + abbrevCommit(hash) + '?', this.config.dialogDefaults.resetCommit.mode, [ - { name: 'Soft - Keep all changes, but reset head', value: 'soft' }, - { name: 'Mixed - Keep working tree, but reset index', value: 'mixed' }, - { name: 'Hard - Discard all changes', value: 'hard' } + { name: 'Soft - Keep all changes, but reset head', value: GG.GitResetMode.Soft }, + { name: 'Mixed - Keep working tree, but reset index', value: GG.GitResetMode.Mixed }, + { name: 'Hard - Discard all changes', value: GG.GitResetMode.Hard } ], 'Yes, reset', (mode) => { - runAction({ command: 'resetToCommit', repo: this.currentRepo, commitHash: hash, resetMode: mode }, 'Resetting to Commit'); + runAction({ command: 'resetToCommit', repo: this.currentRepo, commit: hash, resetMode: mode }, 'Resetting to Commit'); }, commitElem); } } @@ -1106,10 +1106,10 @@ class GitGraphView { visible: visibility.reset, onClick: () => { dialog.showSelect('Are you sure you want to reset the uncommitted changes to HEAD?', this.config.dialogDefaults.resetUncommitted.mode, [ - { name: 'Mixed - Keep working tree, but reset index', value: 'mixed' }, - { name: 'Hard - Discard all changes', value: 'hard' } + { name: 'Mixed - Keep working tree, but reset index', value: GG.GitResetMode.Mixed }, + { name: 'Hard - Discard all changes', value: GG.GitResetMode.Hard } ], 'Yes, reset', (mode) => { - runAction({ command: 'resetToCommit', repo: this.currentRepo, commitHash: 'HEAD', resetMode: mode }, 'Resetting uncommitted changes'); + runAction({ command: 'resetToCommit', repo: this.currentRepo, commit: 'HEAD', resetMode: mode }, 'Resetting uncommitted changes'); }, commitElem); } }, { @@ -1166,22 +1166,22 @@ class GitGraphView { runAction({ command: 'deleteTag', repo: this.currentRepo, tagName: refName, deleteOnRemote: deleteOnRemote }, 'Deleting Tag'); } - private mergeAction(obj: string, name: string, type: GG.BranchOrCommit, sourceElem: HTMLElement | null) { - dialog.showForm('Are you sure you want to merge ' + type.toLowerCase() + ' ' + escapeHtml(name) + ' into the current branch?', [ + private mergeAction(obj: string, name: string, actionOn: GG.ActionOn, sourceElem: HTMLElement | null) { + dialog.showForm('Are you sure you want to merge ' + actionOn.toLowerCase() + ' ' + escapeHtml(name) + ' into the current branch?', [ { type: 'checkbox', name: 'Create a new commit even if fast-forward is possible', value: this.config.dialogDefaults.merge.noFastForward }, { type: 'checkbox', name: 'Squash commits', value: this.config.dialogDefaults.merge.squash } ], 'Yes, merge', values => { - runAction({ command: 'merge', repo: this.currentRepo, obj: obj, type: type, createNewCommit: values[0] === 'checked', squash: values[1] === 'checked' }, 'Merging ' + type); + runAction({ command: 'merge', repo: this.currentRepo, obj: obj, actionOn: actionOn, createNewCommit: values[0] === 'checked', squash: values[1] === 'checked' }, 'Merging ' + actionOn); }, sourceElem); } - private rebaseAction(obj: string, name: string, type: GG.BranchOrCommit, sourceElem: HTMLElement | null) { - dialog.showForm('Are you sure you want to rebase the current branch on ' + type.toLowerCase() + ' ' + escapeHtml(name) + '?', [ + private rebaseAction(obj: string, name: string, actionOn: GG.ActionOn, sourceElem: HTMLElement | null) { + dialog.showForm('Are you sure you want to rebase the current branch on ' + actionOn.toLowerCase() + ' ' + escapeHtml(name) + '?', [ { type: 'checkbox', name: 'Launch Interactive Rebase in new Terminal', value: this.config.dialogDefaults.rebase.interactive }, { type: 'checkbox', name: 'Ignore Date (non-interactive rebase only)', value: this.config.dialogDefaults.rebase.ignoreDate } ], 'Yes, rebase', values => { let interactive = values[0] === 'checked'; - runAction({ command: 'rebase', repo: this.currentRepo, obj: obj, type: type, ignoreDate: values[1] === 'checked', interactive: interactive }, interactive ? 'Launching Interactive Rebase' : 'Rebasing on ' + type); + runAction({ command: 'rebase', repo: this.currentRepo, obj: obj, actionOn: actionOn, ignoreDate: values[1] === 'checked', interactive: interactive }, interactive ? 'Launching Interactive Rebase' : 'Rebasing on ' + actionOn); }, sourceElem); } @@ -2073,11 +2073,11 @@ window.addEventListener('load', () => { refreshOrDisplayError(msg.error, 'Unable to Clean Untracked Files'); break; case 'commitDetails': - if (msg.commitDetails.error === null) { + if (msg.commitDetails !== null) { gitGraph.showCommitDetails(msg.commitDetails, gitGraph.createFileTree(msg.commitDetails.fileChanges, msg.codeReview), msg.avatar, msg.codeReview, msg.codeReview !== null ? msg.codeReview.lastViewedFile : null, msg.refresh); } else { gitGraph.closeCommitDetails(true); - dialog.showError('Unable to load Commit Details', msg.commitDetails.error, null, null, null); + dialog.showError('Unable to load Commit Details', msg.error, null, null, null); } break; case 'compareCommits': @@ -2155,7 +2155,7 @@ window.addEventListener('load', () => { gitGraph.loadRepos(msg.repos, msg.lastActiveRepo, msg.loadRepo); break; case 'merge': - refreshOrDisplayError(msg.error, 'Unable to Merge ' + msg.type); + refreshOrDisplayError(msg.error, 'Unable to Merge ' + msg.actionOn); break; case 'openFile': if (msg.error !== null) { @@ -2188,7 +2188,7 @@ window.addEventListener('load', () => { gitGraph.refresh(false); } } else { - dialog.showError('Unable to Rebase current branch on ' + msg.type, msg.error, null, null, null); + dialog.showError('Unable to Rebase current branch on ' + msg.actionOn, msg.error, null, null, null); } break; case 'refresh':