Skip to content

Commit 45df59c

Browse files
committed
Add the logic to finish or abort merges
1 parent 668de29 commit 45df59c

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/renderer/components/index-viewer.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,14 @@ export class IndexViewer extends React.PureComponent<IndexViewerProps, IndexView
187187
const message = this.state.description ?
188188
`${this.state.summary}\n\n${this.state.description}` :
189189
this.state.summary;
190-
if (this.state.amend) {
191-
await this.props.repo.amend(message);
190+
if (this.props.repoState === RepoState.Merge) {
191+
await this.props.repo.finishMerge(message);
192192
} else {
193-
await this.props.repo.commit(message);
193+
if (this.state.amend) {
194+
await this.props.repo.amend(message);
195+
} else {
196+
await this.props.repo.commit(message);
197+
}
194198
}
195199
// Close path viewer if it is open
196200
this.props.onPatchSelect(null, PatchType.Committed);
@@ -224,7 +228,9 @@ export class IndexViewer extends React.PureComponent<IndexViewerProps, IndexView
224228
disabled={this.state.unstagedPatches.length === 0}>
225229
Commit and merge
226230
</button>
227-
<button className='red-button' type='submit'>
231+
<button className='red-button'
232+
type='button'
233+
onClick={() => this.props.repo.abortMerge()}>
228234
Abort merge
229235
</button>
230236
</>

src/renderer/helpers/repo-wrapper.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,31 @@ export class RepoWrapper {
563563
}
564564
}
565565

566+
async finishMerge(message: string) {
567+
try {
568+
const author = this.getSignature();
569+
const index = await this.repo.index();
570+
const oid = await index.writeTree();
571+
const mergeHeads = await this.getMergeHeads();
572+
if (this.headCommit === null) {
573+
throw new Error('Head not valid');
574+
}
575+
if (mergeHeads.length === 0) {
576+
throw new Error('No merge head found');
577+
}
578+
await this.repo.createCommit('HEAD', author, author, message, oid, [this.headCommit, ...mergeHeads]);
579+
await this.repo.stateCleanup();
580+
} catch (e) {
581+
this.onNotification(`Unable to merge: ${e.message}`, NotificationType.Error);
582+
}
583+
}
584+
585+
async abortMerge() {
586+
if (this.repo.isMerging() && this.headCommit) {
587+
await this.reset(this.headCommit, Git.Reset.TYPE.HARD);
588+
}
589+
}
590+
566591
async fetchAll() {
567592
try {
568593
await this.repo.fetchAll(RepoWrapper.getCredentialsCallback());

0 commit comments

Comments
 (0)