diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 49ba5956cd0..349435d7aeb 100755 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -5,7 +5,7 @@ import { Uri, commands, Disposable, window, workspace, QuickPickItem, OutputChannel, Range, WorkspaceEdit, Position, LineChange, SourceControlResourceState, TextDocumentShowOptions, ViewColumn, ProgressLocation, TextEditor, MessageOptions, WorkspaceFolder } from 'vscode'; import { Git, CommitOptions, Stash, ForcePushMode } from './git'; -import { Repository, Resource, ResourceGroupType, getBranchName } from './repository'; +import { Repository, Resource, ResourceGroupType } from './repository'; import { Model } from './model'; import { toGitUri, fromGitUri } from './uri'; import { grep, isDescendant, pathEquals } from './util'; @@ -1371,13 +1371,15 @@ export class CommandCenter { value = (await repository.getCommit(repository.HEAD.commit)).message; } - let placeHolder; - const branchName = getBranchName(repository.HEAD, repository.refs); + const branchName = repository.headShortName; + let placeHolder: string; + if (branchName) { placeHolder = localize('commitMessageWithHeadLabel2', "Message (commit on '{0}')", branchName); } else { placeHolder = localize('commit message', "Commit message"); } + return await window.showInputBox({ value, placeHolder, diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 851be585b41..416e98ce79a 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -579,6 +579,23 @@ export class Repository implements Disposable { return this._refs; } + get headShortName(): string | undefined { + if (!this.HEAD) { + return; + } + + const HEAD = this.HEAD; + const tag = this.refs.filter(iref => iref.type === RefType.Tag && iref.commit === HEAD.commit)[0]; + const tagName = tag && tag.name; + const branchName = HEAD.name || tagName || HEAD.commit; + + if (branchName === undefined) { + return; + } + + return branchName.substr(0, 8); + } + private _remotes: Remote[] = []; get remotes(): Remote[] { return this._remotes; @@ -1643,7 +1660,7 @@ export class Repository implements Disposable { } private updateInputBoxPlaceholder(): void { - const branchName = getBranchName(this.HEAD, this.refs); + const branchName = this.headShortName; if (branchName) { // '{0}' will be replaced by the corresponding key-command later in the process, which is why it needs to stay. @@ -1657,16 +1674,3 @@ export class Repository implements Disposable { this.disposables = dispose(this.disposables); } } - -export function getBranchName(HEAD: Repository['HEAD'], refs: Repository['refs']): string | undefined { - if (HEAD === undefined) { - return; - } - const tag = refs.filter(iref => iref.type === RefType.Tag && iref.commit === HEAD.commit)[0]; - const tagName = tag && tag.name; - const branchName = HEAD.name || tagName || HEAD.commit; - if (branchName === undefined) { - return; - } - return branchName.substr(0, 8); -}