This commit is contained in:
al
2019-09-08 22:40:11 +03:00
parent 4b90d9ba82
commit 4afe989cfa
2 changed files with 23 additions and 14 deletions

View File

@@ -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 } from './repository';
import { Repository, Resource, ResourceGroupType, getBranchName } from './repository';
import { Model } from './model';
import { toGitUri, fromGitUri } from './uri';
import { grep, isDescendant, pathEquals } from './util';
@@ -1370,10 +1370,16 @@ export class CommandCenter {
value = (await repository.getCommit(repository.HEAD.commit)).message;
}
const branchName = repository.getBranchName();
let placeHolder;
const branchName = getBranchName(repository.HEAD, repository.refs);
if (branchName) {
placeHolder = localize('commitMessageWithHeadLabel2', "Message (commit on '{0}')", branchName);
} else {
placeHolder = localize('commit message', "Commit message");
}
return await window.showInputBox({
value,
placeHolder: branchName ? localize('commitMessageWithHeadLabel2', "Message (commit on '{0}')", branchName) : localize('commit message', "Commit message"),
placeHolder,
prompt: localize('provide commit message', "Please provide a commit message"),
ignoreFocusOut: true
});

View File

@@ -1653,7 +1653,7 @@ export class Repository implements Disposable {
}
private updateInputBoxPlaceholder(): void {
const branchName = this.getBranchName();
const branchName = getBranchName(this.HEAD, this.refs);
if (branchName) {
// '{0}' will be replaced by the corresponding key-command later in the process, which is why it needs to stay.
@@ -1663,17 +1663,20 @@ export class Repository implements Disposable {
}
}
getBranchName(): string | undefined {
const HEAD = this.HEAD;
if (HEAD === undefined) {
return;
}
const tag = this.refs.filter(iref => iref.type === RefType.Tag && iref.commit === HEAD.commit)[0];
const tagName = tag && tag.name;
return HEAD.name || tagName || (HEAD.commit || '').substr(0, 8);
}
dispose(): void {
this.disposables = dispose(this.disposables);
}
}
export function getBranchName(HEAD: Repository['HEAD'], refs: Repository['refs']): string | undefined {
if (!HEAD) {
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) {
return;
}
return branchName.substr(0, 8);
}