Skip to content

Commit

Permalink
Amending without previous commit fails eclipse-theia#7032
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Helming <jhelming@eclipsesource.com>
  • Loading branch information
JonasHelming committed Jan 31, 2020
1 parent d7cf6ec commit e3db67f
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions packages/git/src/browser/git-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,7 @@ export class GitContribution implements CommandContribution, MenuContribution, T
isEnabled: () => !!this.repositoryTracker.selectedRepository
});
registry.registerCommand(GIT_COMMANDS.COMMIT_AMEND, {
execute: () => this.withProgress(async () => {
try {
const message = await this.quickOpenService.commitMessageForAmend();
await this.commit({ message, amend: true });
} catch (e) {
if (!(e instanceof Error) || e.message !== 'User abort.') {
throw e;
}
}
}),
execute: () => this.withProgress(async () => this.amend()),
isEnabled: () => !!this.repositoryTracker.selectedRepository
});
registry.registerCommand(GIT_COMMANDS.STAGE_ALL, {
Expand Down Expand Up @@ -454,6 +445,33 @@ export class GitContribution implements CommandContribution, MenuContribution, T
isVisible: widget => (!widget || widget instanceof ScmWidget) && !this.repositoryProvider.selectedRepository
});
}
async amend(): Promise<void> {
{
const scmRepository = this.repositoryProvider.selectedScmRepository;
if (!scmRepository) {
return;
}

try {
const lastCommit = await scmRepository.provider.amendSupport.getLastCommit();
if (lastCommit === undefined) {
scmRepository.input.issue = {
type: 'error',
message: 'No previous commit to amend'
};
scmRepository.input.focus();
return;
}
const message = await this.quickOpenService.commitMessageForAmend();
await this.commit({ message, amend: true });
} catch (e) {
if (!(e instanceof Error) || e.message !== 'User abort.') {
throw e;
}
}
}
}


protected withProgress<T>(task: () => Promise<T>): Promise<T> {
return this.progressService.withProgress('', 'scm', task);
Expand Down

0 comments on commit e3db67f

Please sign in to comment.