Repository navigation
Enable flow to reorder commits - #12384
Conversation
| * Undo state associated with a multi commit operation being performed on a | ||
| * repository. | ||
| */ | ||
| export interface IMultiCommitOperationUndoState { |
There was a problem hiding this comment.
Not super happy with the name since it's only used for squash and reordering, but maybe it can be used for others? I haven't spent much time looking into that yet 😳
There was a problem hiding this comment.
Yeah. It should be able to be used for cherry-picking when it is refactored to multi-commit-operation. I like it!
| if (beforeCommit !== null && commit.sha === beforeCommit.sha) { | ||
| foundBaseCommitInLog = true | ||
| toReplayBeforeBaseCommit.unshift(commit) | ||
| toReplayAfterReorder.push(commit) |
There was a problem hiding this comment.
I made a mistake here with my logic in #12357 which was putting the "base" commit before the commits you're moving. I adapted the tests in consequence to reflect the actual expected behavior (moved commits should be placed before the base commit).
| switch (kind) { | ||
| case MultiCommitOperationKind.Squash: | ||
| bannerType = BannerType.SquashUndone | ||
| break | ||
| case MultiCommitOperationKind.Reorder: | ||
| bannerType = BannerType.ReorderUndone | ||
| break | ||
| case MultiCommitOperationKind.Rebase: | ||
| case MultiCommitOperationKind.CherryPick: | ||
| case MultiCommitOperationKind.Merge: | ||
| throw new Error( | ||
| `Unexpected multi commit operation kind to undo ${kind}` | ||
| ) | ||
| default: | ||
| assertNever(kind, `Unsupported multi operation kind to undo ${kind}`) | ||
| } |
There was a problem hiding this comment.
Again, maybe we can use this for rebase/cherry-picking/merge? Haven't looked into it yet! 😳
There was a problem hiding this comment.
Yes for cherry-picking.. rebase and merge currently don't support undo.. but maybe they could...
| | { | ||
| readonly type: BannerType.SuccessfulReorder | ||
| /** number of commits reordered */ | ||
| readonly count: number | ||
| /** callback to run when user clicks undo link in banner */ | ||
| readonly onUndo: () => void | ||
| } | ||
| | { | ||
| readonly type: BannerType.ReorderUndone | ||
| /** number of commits reordered */ | ||
| readonly commitsCount: number | ||
| } |
There was a problem hiding this comment.
Maybe we could have just one banner for all the multi commit operations too? 🤔
There was a problem hiding this comment.
Yeah. I think I was heading that way.. but didn't get there on the refactor. :P I am all for it. (Maybe a future PR tho)
| } | ||
|
|
||
| private logHowToRevertSquash(tip: IValidBranch): void { | ||
| private logHowToRevertMultiCommitOperation( |
There was a problem hiding this comment.
I tried to reuse this one for rebase but I saw some differences, so I stopped there since I didn't want to break anything (else) 😂
| // The base commit index will be in row - 1, because row is the position | ||
| // where the new item should be inserted, and commits have a reverse order | ||
| // (newer commits are in lower row values) in the list. | ||
| const baseCommitIndex = row === 0 ? null : row - 1 | ||
|
|
||
| if ( | ||
| this.props.commitSHAs.length === 0 || | ||
| (baseCommitIndex !== null && | ||
| baseCommitIndex > this.props.commitSHAs.length) | ||
| ) { | ||
| return | ||
| } | ||
|
|
||
| const baseCommitSHA = | ||
| row < this.props.commitSHAs.length ? this.props.commitSHAs[row] : null | ||
| baseCommitIndex === null ? null : this.props.commitSHAs[baseCommitIndex] |
There was a problem hiding this comment.
This is also part of the mistake in the logic I mentioned earlier. This logic was wrong, but since the reorder.ts logic was wrong too, everything seemed to work… until you try to put a commit at the beginning or the end of the history 😅
| * This will be set to null if no multi-commit operation has been initiated. | ||
| */ | ||
| readonly squashBranchName: string | null | ||
| readonly branchName: string | null |
There was a problem hiding this comment.
The null discussion again.. since we refactored MultiCommitOperation to be | null should we do that with multiCommitOperationUndoState
There was a problem hiding this comment.
✨ Awesome! - Love how you changed the squashing stuff to multi commit (where my mind was going with it, but wasn't sure yet if those things were reusable) Tested it out and works great!
I had one commit about changing the multiCommitOperationUndoState to a | null like we did for multiCommitOperation ... but this would involve creating an initializer function (and maybe a clear state function) which since this state only has 2 properties may be this is just as "messy" as the null checks. Thus, I good either way with that.
|
I thought about it but didn't actually do it for some reason 🤔 I'll raise another PR with it if you don't mind 😄 |
Closes #12299
Description
This PR enables the flow to reorder commits, handling conflicts and undo. I refactored a few things around undoing squash commits, just to be able to reuse that code for reordering.
However, there are other functions that seemed less easy to reuse, so for now I duplicated them and we'll look for opportunities to refactor later (I'm open to suggestions of course! 😄 )
Screenshots
Screen.Recording.2021-06-07.at.11.52.01.mov
Release notes
Notes: [New] Reorder commits from the History tab