-
Notifications
You must be signed in to change notification settings - Fork 29.5k
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
A full editor can be used as git commit message editor #95266
A full editor can be used as git commit message editor #95266
Conversation
extensions/git/src/commands.ts
Outdated
window.showInformationMessage( | ||
localize('useless verbose commit', "Verbose committing has no effect. The setting 'git.useEditorToCommit' is not enabled.") | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure whether to include this warning or not. Up to you guys :)
extensions/git/src/git.ts
Outdated
const args = ['commit', '--quiet']; | ||
const options: SpawnOptions = {}; | ||
|
||
if (!opts.useEditor || message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a message is supplied, it should still be used for the commit. This allows to use the input box for quick commits, although git.useEditorToCommit
is enabled.
extensions/git/src/gitEditor.ts
Outdated
// We don't want to remember the cursor position. | ||
// One should be able to start writing the message immediately. | ||
const position = new Position(0, 0); | ||
editor.selection = new Selection(position, position); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vscode seems to remember where my cursor was in an older file. This was quite annoying since I couldn't start writing the commit message immediately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably because the path to the git-commit is always .git/COMMIT_EDITMSG
or something. If you change how vscode calls git commit, you can make this a randomly named temp file. The downside is that you will lose the automated report that git commit gives you (especially when using --verbose
) but then again, you have a whole IDE that can provide this information so maybe that's a good future path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably because the path to the git-commit is always .git/COMMIT_EDITMSG or something. If you change how vscode calls git commit, you can make this a randomly named temp file.
does not using .git/COMMIT_EDITMSG mean no proper integration with prepare-commit-msg hook? it would be nice to preserve this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's why I refrained from using a custom/tmp file. I think the overall experience is still the best when the original file is used.
extensions/git/src/gitEditor.ts
Outdated
return new Promise((c, e) => { | ||
const onDidChange = window.onDidChangeVisibleTextEditors((editors) => { | ||
if (editors.indexOf(editor) < 0) { | ||
onDidChange.dispose(); | ||
return c(true); | ||
} | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure about this part. Could be, that I missed some edge cases where this fails?
One test in windows is failing, seems to be not connected to my changes tho |
@JohnnyCrazy How can I help with this PR? I see that there are some merge conflicts. I could try to help you clean that up with a rebased version or a merge commit. Thanks for doing this! |
Thanks for the ping, missed that there are new changes and conflicts 👍 I will have a look today/tomorrow and will report, if I run into any issues. Most changes seem to be straightforward to fix. |
No worries about the conflicts @JohnnyCrazy, I can take care of them. Assigning this to May. |
Fantastic work here. But because git is an extension, the way we handle the "closing of the COMMIT_MESSAGE" file is problematic:
For that reason, I've brought these changes into Everything else works to perfection. We might need to realign these settings and simply consider having this turned on by default. |
Yes, I already had a weird feeling when I was writing that "on close" part 😉 Regarding the settings, one thing which held me back to make it the default action was the command trigger Anyway, if you need anything or want me to further explore solutions using the FS Provider API, feel free to ping me! |
Actually, yeah, if you'd like to give it a go, here's what I was thinking. We can't really figure out when the file has been closed or not, this is a long standing open feature request into our API which won't get resolved any time soon. So we're going to have to go with the same semantics as you currently have. But in doing so, we need to use a different file on for each commit, so we avoid having potential save conflicts. Idea: When we get pinged to open that What do you think? If you agree I can simply push the merge conflict resolution to your branch and you can pick it up from there? |
Sounds good, the only question/reassurement I currently have is regarding So, as I understood, we will continue to use
Sure! |
Absolutely right! It's definitely better than the current approach. And we can discuss with @jrieken and @bpasero if we can't have the notion of editors which should automatically close if their document gets deleted, at a later stage. |
@JohnnyCrazy Just resolved the conflicts. Looking forward to the further changes! 💪 |
Open Editors API could be coming this month: #15178 (comment)! 🔥 At least in some proposed state, which we could use in git. Let's keep an eye on that, it would be very helpful here. I wonder if, given that API, we should still do the FS Provider dance. 🤔 My gut feeling tells me we don't actually have to go with that hassle, especially because git can't handle multiple simultaneous commits. So I propose we wait for that proposed API to advance and experiment with that, what do you think @JohnnyCrazy? |
Yes, I agree. In the end we would abuse a rather unrelated API and the code would get more complicated. Looking forward to an Editor Tab API! 👍 |
As far as I understood #15178, it will take some time. I would happily invest some more time finding a solution for the whole open editor problem, maybe involving the FS Provider API like you suggested. What is your take on this @joaomoreno ? I could imagine once the Editor API is out, the refactoring amount is rather minimal. But in the end you have more experience here, so up to you 👍 |
#15178 is definitely in the horizon... we're just a bit overloaded and other stuff got prioritized. We can definitely see if the FS Provider gives us a better experience here, so we're not blocked by that feature request. Let me know how it goes. |
Just curious if this would get merged any time soon, we'd love to start using this in our process. |
@joaomoreno I pushed a first implementation of a fs-provider based solution in f18ba9a Some notes for that: Dirty commit message files are not a problem anymore. We're handling all the contents in-memory and the real file is only touched 2 times: When starting the commit and when it finishes up. Using an uuid as the URI
Right now, the URI (incl. uuid) for the file is generated when we receive the IPC call. Thus, we can only delete the in-memory file once the callback to Instead of directly comparing if the spawned The problem with opening a new tab of course still exists due to |
I don't know if you are aware of https://github.com/kahole/edamagit but it solves the problem tackled by this PR. Maybe it doesn't cover all the edge cases. But it is a very good solution in the meantime. |
@joaomoreno, this PR is now ready to be reviewed. Let me know if you have any questions or concerns. Thanks! |
@lszomoru - Did you mean "not" ready? Or "now" ready? |
@rmunn, thanks! Updated my comment. This is now ready to be reviewed. |
This is awesome. Great job @lszomoru for getting this done! And many thanks to @JohnnyCrazy for being so patient with us and collaborating with us along the way! 🚀 👏 |
All the credit goes to @JohnnyCrazy 🚀 |
Good stuff @lszomoru ! Really enjoyed working on this one, thanks for the guidance and help along the way @joaomoreno ! 😊 |
@JohnnyCrazy, after we have merged the PR we ran into some issues and we had to revert the changes. Unfortunately, we ran out of time before we had to shut down the main branch for the release, so these changes did not make it into the May release. I have create a new PR (#151491) to get these changes into the June release. |
This PR fixes #30562
This PR introduces the ability to use a full editor pane to write a commit message.
XidmaU9T4x.mp4
Settings
git.useEditorToCommit: boolean
If enabled, a full editor will be created for every commit action. These include triggered git commands like
Git: Commit All
and alsoCTRL+ENTER
on an empty input box in the repository pane. If the input box is not empty, the full editor will not be used. This still allows for quick, small commit messages.Once the editor is created, it behaves like
GIT_EDITOR="code --wait" git commit
: As soon as the file is closed, the contents will be used as message and the commit continues. If it's empty, the commit aborts and aAborting commit due to empty commit message
warning is shown.git.verboseCommit: boolean
If enabled, the opened
COMMIT_EDITMSG
will contain more output. It's basically appending--verbose
to the git call.If
git.verboseCommit
is enabled butgit.useEditorToCommit
is not, a warning will be shown as the setting is pointless.Implementation
The implementation of the git commit integration is similar to the askpass one:
.sh/.bat
file is passed as theGIT_EDITOR
environment variable to the git commit callCOMMIT_EDITMSG
) via IPC to the main electron process and waits for its answer.vscode: git commit
waits forgit: commit
waits foripc-client-js: GIT_EDITOR
waits forvscode: close of file
Testing
Testing was successful on windows and linux. I wanted to test the WSL Integration as well, but was unable to get it working with the downloaded VSIX in Code-OSS.
Initially I had a problem with the timeout of the IPC. This was solved by removing the timeout. This will also be the default in node 13