What Is VisualHg2
VisualHg2 is a Mercurial source control provider for Visual Studio 2010, 2012 and 2013. This is a fork of VisualHG project run by Bernd Schrader.
Now that I finally reached Bernd, he decides whether this project will be merged with the original one.
Before You Start
Download and install TortoiseHg.
VisualHg runs Mercurial (hg.exe) in background and launches TortoiseHg (thg.exe) when you click context menu items.
If you use Mercurial as a command line tool, you don't have to install TortoiseHg, just ensure that %PATH% system variable contains path to Mercurial installation folder. VisualHg will add new files to repository, remove deleted and rename renamed (to preserve the file history). You'll see statuses in Solution Explorer and a list of pending changes, but you won't be able to run actions from context menu.
Download and install latest version of VisualHg.
To activate VisualHg go to Tools - Options - Source Control and select VisualHg as source control plug-in.
Now when you open a source controlled solution, you'll see status icons in Solution Explorer.
Visual Studio 2012 and 2013 (showing default and alternative icons):
Renamed (this is a special status)
Ignored (you'll see it after modifying the file)
Copied (another special one, and a rarity)
Not tracked files don't have status icons.
Visual Studio 2010 allows only 4 custom status icons in Solution Explorer:
Added, Copied or Renamed (actual status is shown in tooltip)
Not tracked, missing and ignored files don't have status icons.
Placeholder for status icon is 7 pixels wide, so it's hard to create decent icons. The default resemble those of original VisualHg. The default are inverted when in Dark theme and the alternative aren't.
If you don't like default ones, you can use the alternative version or create your own. VisualHg uses a single file with icons coming in the following order: empty, modified, added, removed, clean, missing, not tracked, ignored, renamed, copied.
Modified status icon is displayed for projects if any of its children changed. (This feature may be slow, and is optional).
Folders don't have status icons in Visual Studio.
VisualHg appears in File menu and adds context menu to all the solution explorer items, code editor and tabs.
The following actions are available for repositories:
- Status - thg status
- Commit - thg commit
- Update - thg update
- Synchronize - thg sync
- Workbench - thg workbench
- Create Repository - thg init
- Settings - thg repoconfig
- Shelve - thg shelve
The following actions are available for files:
- Add - thg add
- Commit - thg commit
- Diff - kdiff3 or any other diff tool specified, renames are detected
- Revert - thg revert
- History - thg history, renames are detected
Visibility of the items depends on the file status.
Add, Commit and Revert will appear for project if the actions they represent can be applied to any of project children. (This feature may be slow, and is optional).
Pending Changes Tool Window
VisualHg provides a tool window with a list of files with pending changes, found at View - VisualHg Pending Changes.
Options are stored in %APPDATA%\VisualHg\Options.xml file.
Before the tool is opened hg.exe is run to create a copy of file at parent revision in temporary folder. Its path substitutes %PathA% in diff tool arguments, %PathB% stands for current file path. To display nice file names in diff tool use %NameA% and %NameB%. No quotes around variables are needed.
When no custom tool is specified, VisualHg opens Visual Studio 2012 and 2013 compare files window:
In Visual Studio 2010 VisualHg uses KDiff3 which comes with TortoiseHg installation. KDiff3 is started with the following arguments:
%PathA% --fname %NameA% %PathB% --fname %NameB%
File names shown in KDiff3:
How It Works
VisualHg runs hg.exe and caches file statuses. It subscribes to file system events and updates status for the changed files. Mercurial special files are ignored except dirstate a change in which tells VisualHg to refresh the cache for all the files. After the cache has changed VisuaHg waits for Visual Studio to become idle to update status icons and pending changes list.
VisualHgService class implements several interfaces which allow it to listen to Visual Studio events such as file being added, renamed or removed. Then hg.exe is run to update the repository.
And that's all, folks.