Skip to content
Merged
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
28 changes: 15 additions & 13 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

let value: string | undefined = undefined;
if (opts && opts.amend && repository.HEAD && repository.HEAD.commit) {
value = (await repository.getCommit(repository.HEAD.commit)).message;
}

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
});
}

return await window.showInputBox({
value,
placeHolder: localize('commit message', "Commit message"),
prompt: localize('provide commit message', "Please provide a commit message"),
ignoreFocusOut: true
});
return _message ? repository.cleanUpCommitEditMessage(_message) : _message;

};

const didCommit = await this.smartCommit(repository, getCommitMessage, opts);
Expand All @@ -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();
Expand Down
20 changes: 19 additions & 1 deletion extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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 '';
Expand Down
9 changes: 8 additions & 1 deletion extensions/git/src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down Expand Up @@ -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();
Expand Down