Clone wiki

VisualHg2 / Home

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.

Getting Started

Download and install latest version of VisualHg.

To activate VisualHg go to Tools - Options - Source Control and select VisualHg as source control plug-in.

Source control plugin selection

Now when you open a source controlled solution, you'll see status icons in Solution Explorer.

Solution Explorer showing status icons

Status Icons

Visual Studio 2012 and 2013 (showing default and alternative icons):

Clean Clean (alternative) Clean

Modified Modified (alternative) Modified

Renamed Renamed (alternative) Renamed (this is a special status)

Added Added (alternative) Added

Removed Removed (alternative) Removed

Missing Missing (alternative) Missing

Ignored Ignored (alternative) Ignored (you'll see it after modifying the file)

Copied Copied (alternative) 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:

Clean Clean (alternative) Clean

Modified Modified (alternative) Modified

Added Added (alternative) Added, Copied or Renamed (actual status is shown in tooltip)

Removed Removed (alternative) Removed

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.

Default status icons Default set

Alternative status icons Alternative set

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.

Context Menu

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.

Pending changes

Options

Options

Options are stored in %APPDATA%\VisualHg\Options.xml file.

Diff Tools

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:

Compare files

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:

KDiff3 displaying nice file names

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.

Updated