Search code examples
visual-studiovisual-studio-2010version-controlmercurialvisualhg

Automatic Commit in VisualHG


Is it possible to setup VisualHg such that i'm automatically presented with a commit screen every time I quit Visual studio 2010?

This would be extremely useful if I forget to commit some changes.


Solution

  • I've managed to do this using the following steps:

    1. Select Tools > Macros > Macros IDE from the VS 2010 IDE.
    2. This should present you with an empty IDE with Project Explorer on the left
    3. Expand MyMacros and double-click on EnvironmentEvents

    This gives you a file which is set up to handle IDE events. Before the last End Module in the file add the following code:

    Private Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing
        DTE.ExecuteCommand("File.Commit")
    End Sub
    

    This will execute the commit action before the solution closes (which will happen before Visual Studio closes) but VS doesn't wait for the commit window to close before carrying on. This isn't ideal as it means that you'd have to re-load the solution if you wanted to make any changes before committing.

    An alternative solution would be to handle the QueryCloseSolution event and ask the user if they want to commit their changes before closing. If they answer "Yes" then you'd cancel the close solution (by setting the passed in boolean to be True) and call DTE.ExecuteCommand("File.Commit"). That would then leave the solution open whilst you did your commit but would ask you if you wanted to commit every time you close the solution.

    Taking that solution further would involve launching hg status from the QueryCloseSolution event to check if there are outstanding changes before asking the user if they want to commit their changes.