Revert should clean up repository state when there is nothing to revert#816
Conversation
|
I think I'd prefer the |
4de6fc2 to
725d366
Compare
|
@nulltoken - I added the |
725d366 to
afc0fdb
Compare
❤️ it! |
There was a problem hiding this comment.
I'm not sure I follow the reasoning behind this (However, I'm not a hardcore Reverter, so there's that 😉).
Providing we're reverting once again the same commit, there's nothing to actually do, the workdir and the index would stay untouched. Thus, I don't understand why the RevertStatus would change depending on the commitOnSuccess value.
Similarly, why would the repo.Info.CurrentOperation be set to Revert if no change to the index or workdir has been applied?
There was a problem hiding this comment.
So, I think that there are two concerns here:
- The status returned when you ask to not commit and there's nothing to revert. I agree here with @nulltoken that it's odd that the status changes depending on whether you intend to commit or not. I would expect to get a
RevertStatus.NothingToRevertwhether I asked it to be committed or not. - Whether
repo.Info.CurrentOperation be set to Revert if no change to the index or workdir has been applied? I think this makes sense, so that one could reasonably emulategit revert --no-commit` using LibGit2Sharp.
There was a problem hiding this comment.
@jamill Do you foresee any issue returning RevertStatus.NothingToRevert in both cases?
There was a problem hiding this comment.
I see - the way I thought about that status was that it would convey what the operation did. When asked to commit the revert, and there was nothing to revert, effectively nothing changed. In the case where you do not want the commit reverted, then we still do something for you - we have put you in the "revert" state... so, we did what you requested and the state of the repo is changed.
So, RevertStatus.NothingToRevert is an indication that the operation resulted in no changes, while the RevertStatus.Reverted indicates that we changed the state of the repository, rather than a statement of what changes were reverted.
@jamill Do you foresee any issue returning RevertStatus.NothingToRevert in both cases?
No... we could do it that way as well.
There was a problem hiding this comment.
So, RevertStatus.NothingToRevert is an indication that the operation resulted in no changes, while the RevertStatus.Reverted indicates that we changed the state of the repository
Oh that's interesting. I was looking at it like "nothing to commit", just indicating that no work was performed. I had just inferred that the repository was still in the reverting state.
|
@nulltoken That is a great question 😄 Partly, this is because this is how the command line behaves. If you revert from the command line and specify the As to the part of |
|
@peff I'd be very grateful if you could help us with this reverting use case. 🙏 |
|
@nulltoken Which alternate behaviors are you considering? Having revert always clean up itself if there are no changes (even when you asked it to not commit the result)? |
afc0fdb to
4dcb904
Compare
This has been updated to return |
There was a problem hiding this comment.
Revert was run, but there were no changes to commit.
If reverting with the option to commit on success, and the revert completes successfully but there are no changes to commit, then revert will clean up the revert operation in progress state and the RevertStatus will indicate that there was nothing to revert.
4dcb904 to
329c652
Compare
|
🎱 |
Currently - when calling Revert that results in no changes to revert, the repository is left in a reverting operation. From the command line - git will cleanup the operation state (unless you are reverting with the --no-commit option).
This change is to update Revert to follow that behavior. One thing I considered was adding a
RevertStatus.NothingToCommit, as it might be unexpected to get aRevertSatus.Revertedresult when nothing was reverted. But I think that is not needed as this can be inferred from the result (RevertStatus.Reverted+nullcommit indicates that there was nothing to revert). In this caseRevertStatus.Revertedwould mean that these changes were already reverted (even if no new revert commit was generated).