diff --git a/src/webviews/apps/rebase/rebase.ts b/src/webviews/apps/rebase/rebase.ts index ec37651..6fdd8e6 100644 --- a/src/webviews/apps/rebase/rebase.ts +++ b/src/webviews/apps/rebase/rebase.ts @@ -265,7 +265,9 @@ class RebaseEditor extends App { const $subhead = document.getElementById('subhead')! as HTMLHeadingElement; $subhead.innerHTML = `${state.branch}Rebasing ${ state.entries.length - } commit${state.entries.length !== 1 ? 's' : ''} onto ${state.onto}`; + } commit${state.entries.length !== 1 ? 's' : ''}${ + state.onto ? ` onto ${state.onto}` : '' + }`; const $container = document.getElementById('entries')!; @@ -320,20 +322,22 @@ class RebaseEditor extends App { $container.appendChild($el); } - const commit = state.commits.find(c => c.ref.startsWith(state.onto)); - if (commit != null) { - const [$el] = this.createEntry( - { - action: undefined!, - index: 0, - message: commit.message.split('\n')[0], - ref: state.onto, - }, - state, - ++tabIndex, - ); - $container.appendChild($el); - $container.classList.add('entries--base'); + if (state.onto) { + const commit = state.commits.find(c => c.ref.startsWith(state.onto)); + if (commit != null) { + const [$el] = this.createEntry( + { + action: undefined!, + index: 0, + message: commit.message.split('\n')[0], + ref: state.onto, + }, + state, + ++tabIndex, + ); + $container.appendChild($el); + $container.classList.add('entries--base'); + } } document diff --git a/src/webviews/rebaseEditor.ts b/src/webviews/rebaseEditor.ts index 7462c67..1a3cb1c 100644 --- a/src/webviews/rebaseEditor.ts +++ b/src/webviews/rebaseEditor.ts @@ -210,36 +210,42 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl const contents = document.getText(); const entries = this.parseEntries(contents); - const [, , , onto] = rebaseRegex.exec(contents) ?? ['', '', '']; + let [, , , onto] = rebaseRegex.exec(contents) ?? ['', '', '']; const authors = new Map(); const commits: Commit[] = []; - let commit = await Container.git.getCommit(repoPath!, onto); - if (commit != null) { - if (!authors.has(commit.author)) { - authors.set(commit.author, { - author: commit.author, + const ontoCommit = await Container.git.getCommit(repoPath!, onto); + if (ontoCommit != null) { + if (!authors.has(ontoCommit.author)) { + authors.set(ontoCommit.author, { + author: ontoCommit.author, avatarUrl: ( - await commit.getAvatarUri({ defaultStyle: Container.config.defaultGravatarsStyle }) + await ontoCommit.getAvatarUri({ defaultStyle: Container.config.defaultGravatarsStyle }) ).toString(true), - email: commit.email, + email: ontoCommit.email, }); } commits.push({ - ref: commit.ref, - author: commit.author, - date: commit.formatDate(Container.config.defaultDateFormat), - dateFromNow: commit.formatDateFromNow(), - message: commit.message || 'root', + ref: ontoCommit.ref, + author: ontoCommit.author, + date: ontoCommit.formatDate(Container.config.defaultDateFormat), + dateFromNow: ontoCommit.formatDateFromNow(), + message: ontoCommit.message || 'root', }); } for (const entry of entries) { - commit = await Container.git.getCommit(repoPath!, entry.ref); + const commit = await Container.git.getCommit(repoPath!, entry.ref); if (commit == null) continue; + // If the onto commit is contained in the list of commits, remove it and clear the 'onto' value — See #1201 + if (commit.ref === ontoCommit?.ref) { + commits.splice(0, 1); + onto = ''; + } + if (!authors.has(commit.author)) { authors.set(commit.author, { author: commit.author, @@ -261,7 +267,7 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl return { branch: branch?.name ?? '', - onto: onto ?? '', + onto: onto, entries: entries, authors: [...authors.values()], commits: commits,