When resolving a merge conflict allow accepting the default commit message

Fixes #6403
This commit is contained in:
Haritha Wickremasinghe
2019-01-14 13:22:03 -05:00
parent 2ab82c12ed
commit 23058bece6
3 changed files with 43 additions and 16 deletions

View File

@@ -1292,22 +1292,24 @@ export class CommandCenter {
private async commitWithAnyInput(repository: Repository, opts?: CommitOptions): Promise<void> {
const message = repository.inputBox.value;
const getCommitMessage = async () => {
if (message) {
return message;
let _message: string | undefined = message;
if (!_message) {
let value: string | undefined = undefined;
if (opts && opts.amend && repository.HEAD && repository.HEAD.commit) {
value = (await repository.getCommit(repository.HEAD.commit)).message;
}
_message = await window.showInputBox({
value,
placeHolder: localize('commit message', "Commit message"),
prompt: localize('provide commit message', "Please provide a commit message"),
ignoreFocusOut: true
});
}
let value: string | undefined = undefined;
return _message ? repository.cleanUpCommitEditMessage(_message) : _message;
if (opts && opts.amend && repository.HEAD && repository.HEAD.commit) {
value = (await repository.getCommit(repository.HEAD.commit)).message;
}
return await window.showInputBox({
value,
placeHolder: localize('commit message', "Commit message"),
prompt: localize('provide commit message', "Please provide a commit message"),
ignoreFocusOut: true
});
};
const didCommit = await this.smartCommit(repository, getCommitMessage, opts);
@@ -1328,7 +1330,7 @@ export class CommandCenter {
return;
}
const didCommit = await this.smartCommit(repository, async () => repository.inputBox.value);
const didCommit = await this.smartCommit(repository, async () => repository.cleanUpCommitEditMessage(repository.inputBox.value));
if (didCommit) {
repository.inputBox.value = await repository.getCommitTemplate();

View File

@@ -1514,6 +1514,24 @@ export class Repository {
}
}
cleanupCommitEditMessage(message: string): string {
//TODO: Support core.commentChar
return message.replace(/^\s*#.*$\n?/gm, '').trim();
}
async getMergeMessage(): Promise<string | undefined> {
const mergeMsgPath = path.join(this.repositoryRoot, '.git', 'MERGE_MSG');
try {
const raw = await readfile(mergeMsgPath, 'utf8');
return raw.trim();
}
catch {
return undefined;
}
}
async getCommitTemplate(): Promise<string> {
try {
const result = await this.run(['config', '--get', 'commit.template']);
@@ -1532,7 +1550,7 @@ export class Repository {
}
const raw = await readfile(templatePath, 'utf8');
return raw.replace(/^\s*#.*$\n?/gm, '').trim();
return raw.trim();
} catch (err) {
return '';

View File

@@ -1105,6 +1105,10 @@ export class Repository implements Disposable {
return await this.run(Operation.GetCommitTemplate, async () => this.repository.getCommitTemplate());
}
async cleanUpCommitEditMessage(editMessage: string): Promise<string> {
return this.repository.cleanupCommitEditMessage(editMessage);
}
async ignore(files: Uri[]): Promise<void> {
return await this.run(Operation.Ignore, async () => {
const ignoreFile = `${this.repository.root}${path.sep}.gitignore`;
@@ -1257,8 +1261,11 @@ export class Repository implements Disposable {
const config = workspace.getConfiguration('git');
const shouldIgnore = config.get<boolean>('ignoreLimitWarning') === true;
const useIcons = !config.get<boolean>('decorations.enabled', true);
this.isRepositoryHuge = didHitLimit;
const mergeMessage = await this.repository.getMergeMessage();
if (mergeMessage) {
this.inputBox.value = mergeMessage;
}
if (didHitLimit && !shouldIgnore && !this.didWarnAboutLimit) {
const knownHugeFolderPaths = await this.findKnownHugeFolderPathsToIgnore();