-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git Commit.Template, Restore Previous Commit Msg On Undo #8933
Conversation
* I'm going ahead and commiting changes for possibility of others seeing this code. I will rely on later being able to correctly rebase changes. * Added `getCommitInfo` to the git command chain: `IRawGitService`, `GitService`, `GitChannel`, `ChangesView`. * Is erroring in a side-effect that I am having problems debugging, as the contributing guidance doesn't explain debugging the node process side (explicitly anyway).
* Cleaned up and corrected changeView calling code to avoid initial git commit msg stuff. * Refactored `lastCommitMsg` to `prevCommitMsg` in pipeline. * Added `getCommitInfo` to git `IModel`. * Added commitInfo to Model implementation class. * Changed `IRawGitService.getCommitInfo` to return `IRawStatus` instead of `ICommitInfo` directly. * Changed `IGitService.getCommitInfo` to return `IModel`. * This was required because it expects a status when performing a git operation from the client (not really documented nor obvious). * Added `Repository.getLog(ILogOptions)` for getting the previous commit msg, but allowing extensibility. * Added `ILogOptions` with single `prevCount` for extensibility of other use cases when executing `git log -1` (which gets the previous commit msg). InProgress: * Implementing getCommitInfo to parse possible template file, as well as parse the previous log message.
* Added ability to specify commit.template using `~`, e.g. `~/.somefile` * Only works for local commit template. Not implemented for global commit.template, where the template location is in the home/users folder.
* Seems to be working with limited testing. * I am using `IStorageService` with no explicit scope, and I am unsure of the implications of this. * There might should be an option for this functionality.
* Refactored `status` to `model` in lambda callback. This reflects the actual item being returned.
@bill-mybiz, thanks for your PR! By analyzing the annotation information on this pull request, we identified @joaomoreno and @egamma to be potential reviewers |
Hi @bill-mybiz, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
@bill-mybiz, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
Very cool! I have a few suggestions:
|
Gracias!
Yes, tslint! I completely forgot to run that as I was just trying to get this thing going.
In the beginning, I totally agreed with not seeing any reason to put it on the model. I originally had the I think you would probably want the |
Also, here are the implementations in the
These are just a few. You can check out them at |
You don't really need to implement this call as an operation, since it is a pure call (no consequences). You can just copy what is done by the |
* Removed all previous commit message code. * Changed `getCommitInfo` call to return a string that is the template contents. * Removed from `IModel`, `IRawStatus` * Still has issue of locating `~/some/path/with/tilde` in it. * path.resolve resolves to the repo's `.build` path and not the user folder. * I'm testing this on Windows, and I don't know the behavior on Linux.
That is certainly why I tried that approach the first time (and failed). But now everything was much clearer and this was pretty easy to make these changes. I went ahead and removed There is still a problem with locating paths that are in the form of |
Awesome, I ended up doing another commit on top and merged it in:
Great job, and thanks! 🎆 |
@joaomoreno I think there is a bug from this line of code that was left over from my first go at removing the previous commit msg aspect. If you simply unstage a single file, it will wipe out the commit message. |
To be more explicit, the bug is that the second clause in the |
Thanks! 8c38fca |
@joaomoreno You're gonna hate me dude, but there looks to be another teensy bug. Now when the commit occurs, it is not stripping the I'm sorry I didn't catch this earlier, but I've had to use the competition (Atom 😱) for Elixir support, and I have been using vim via the command line. Anyway, I can look into it if you want. It's your call. |
That's quite alright, I don't hate you ❤️ I'll fix it in #11646 PS: 😱 The A word. |
Relates to issues: #7830 and #6190. I have put most of my notes and discussion in #7830.
To effect the changes, there are basically four parts:
1. The git server-side CLI commands and state.
The two git CLI commands we need to run for these changes include
git config --get commit.template
andgit log -1 --format=%B
. The first reads thecommit.template
entry if it exists, and the second gets the previous commit message. This is very simple, but the distributed architecture makes the implementation of this somewhat extensive.Since the commit.template command is a read on the config, this was most easily executed by using the repo's existing run command:
repo.run(['config', '--get', 'commit.template'])
. I could have also done this with the log I suppose, but it seemed a good fit for its own method on theRepository
class.Also, there is a design decision on how to capture the state involved in these operations. This stems from the existing design requiring a status on each git operation execution. I chose to combine the information in an
ICommitInfo
to keep it cleaner for our use case. I then added this to theIModel
because, AFAICT, this is how state is passed in these operations.It essentially works like the following: Operation -> Status -> Model.
When an operation is executed, whatever it is, it then executes an updated status, which creates an updated model that is expected on the client/browser.
2. The git client-server pipeline to expose the new behavior/state.
There are several abstraction layers when communicating between the client/server with this being an electron application. I had a design decision on how to access the above behavior/state:
I went with 1 and added a
getCommitInfo
method along client-server communication pipeline, because it didn't seem to fit anywhere in the existing code. After completion, it's conceivable that it could fit in theRawGitService.status
method. Actually, I think that this is probably where it should be, but I wanted to go ahead and start this PR. If I change it to this, then I don't think I will need to change any of the existing client-server channel code, and it would simplify a great deal. But, on the other hand, it's working now as-is (except it does not work with a global commit.template file specified as~/.somefile
. It can handle this format for a local commit template in the repo's .git folder).3. The git changes view which contains the input box. AND 4. The git undo last commit action.
This is pretty straight-forward on the
ChangesView
. I've added aonCommitInputShown
method and hooked this in thesetVisible
method. The only real nuance to this is understanding the workflow of theUndoLastCommitAction
implementation.Because of the distributed design of the actions, there must be a way of sharing state between the action and the
ChangesView.commitInputBox
. It had to get the previous commit info before executing the undo/reset action, and we need a way to get this previous message into the input box when it is shown. So I simply store the previous commit message in local storage (without an explicit scope) using theIStorageService
when running theUndoLastCommitAction
. Then, the first time that theonCommitInputShown
is called, it always checks this first. If it exists, then it immediately sets its value to that and removes it from local storage.Other than this nuance, it should be obvious from the code how this works.