Skip to content

mkwpaul/tfvc.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tfvc.nvim

tfvc.nvim is a neovim plugin providing integration for TeamFoundation version control (TFS), referred to as 'tfvc' from here on.

It provides commands to checkout files, undo changes, view history, view changesets, compare pending changes and other things. Some commands of the TF cli tool do not -and will not- have dedicated commands though.

The goal is to optimize the workflow around working with a tfvc repository using nvim, not to replace the commandline tool.

Tested on Windows 10/11 and TF Version 17.10.34824.3, although it'll probably work with earlier versions.

Requirements

This plugin depends on the TF executable bundled with Visual Studio. It also depends on you having setup an active workspace with TF.exe workspace.

Installation & Setup

Add this repository with your plugin-manager of choice. Here's Lazy:

  { 'mkwpaul/tfvc.nvim' },

Ensure that the parent directory of the TF.exe is listed in your PATH variable, either by appending the location of the executable manually or by running nvim within Visual Studios's developer Shell profile. You can alternatively specify the absolute path to the TF executable via the executable_path option.

Options

-- Every individual option can be set either by setting 
vim.g.tfvc_option = 'value'
vim.g.tfvc_option2 = true
-- 
-- or by setting
vim.g.tfvc = { option = 'value', option2 = true, }
--
-- or by calling
require('tfvc').setup { option = 'value', option2 = true, }

Note that calling setup isn't required to initialize this plugin, it just merges the provided options table with vim.g.tfvc.

Options set as namespaced fields on vim.g have priority, so that they can be set interactively via something like :let g:tfvc_diff_open_folds = v:true for example.

Example configuration:

---@type tfvc.user_vars
vim.g.tfvc = {
  output_encoding = 'cp1252',
  version_control_web_url = 'http://zesrvtfs:8080/tfs/DefaultCollection/MyProj/_versionControl',
}

Full list of Options:

  • debug

verbose output for debugging. You should probably leave this unset. Default is false.

  • default_versionspec

Versionspec to use with commands when no versionspec is specified, Default is 'T' which indicates to use the latest server version.

  • diff_no_split

if true, then hide the buffer that is compared against, when using TF diff, Default is false.

  • diff_open_folds

if true, then don't collapse regions without changes, when using TF diff Default is false.

  • diff_open_cmd

Command to use when opening diffsplits from history or changeset buffers. Should be of edit, split, vsplit, above split, top etc. see :h window

Default is above split i.e. open splits above the current window.

  • executable_path

Full path to the TF executable. If not set, the it will be assumed that the tf executable is in the PATH. Only necessary when you can't make the TF executable availible via PATH. Default is TF.

  • filter_status_by_cwd

When using TF status, only show changed files under the current working directory Default is true, i.e. do filter by CWD.

  • history_entry_limit

Number of entries to load in history buffers. Default is 300 entries.

  • history_open_cmd

command to use when navigating to tfvc:///history paths via TF history. This should be one of edit, split, vsplit, above split, top etc. see :h window

Default is edit i.e. open history in current window.

  • output_encoding

if specified, use iconv to convert output from tf.exe from the specified encoding to utf-8, value is passed as-is to iconv, so it should be an encoding it understands.

  • version_control_web_url

This should look something like http://{host}/tfs/{collection}/{project}/_versionControl.

Commands

Only one actual user-command is registerd. All different actions are provided as sub-commands to the one :TF command.

  • :TF add

Adds the current file to TFS. Non-blocking equivalent to `:!tf add "%".

  • :TF checkout

Check out the current file from TFS. Non-blocking equivalent to :!tf checkout "%" Does not work with directories (for safety).

  • :TF checkoutModfiedFiles

Checkout all files that 1. are readonly (assumed to be not-checked-out) 2. have unsaved changes.

This Command is provided for the case when you're modifying a larger amount of files programmatically; Through macros, through language-server renames or other means.

In those situations this command lets checkout affected files out after the fact, letting you do :wall without having to rely on TF reconcile which could potentially add additional files you didn't mean to checkout/add.

  • :TF diff

Diffs the local version of the current file with a specific server version, per default the latest version. Optionally takes a versionspec as an argument to specify the version.

  • :TF history

Open history (changelog) of the current file / directory in an interactive buffer. You can also specify a path manually insead of using the current buffer.

  • :TF openWebHistory

Opens the history of the current file or directory in a browser. Requires the version_control_web_url to be set during setup.

  • :TF loadDiffs

Preloads a specific server version of all files with pending changes.

  • :TF status

Opens the quickfix list with checked out files. Depending on the value of option filter_status_by_cwd only shows files that are within the current working directory.

Executing the command with a bang (i.e. TF! status), will reverse the option for that execution.

Alternatively you can specify by providing additional parameter a all or in_cwd

e.g. TF status all

  • :TF undo

Undoes any pending changes in the current file or provided path. Non-blocking equivalent to :!tf undo "%" Does not work with directories (for safety) You can also specify a path manually insead of using the current file.

  • :TF info

Shows status of the current file or directory or provided path. Non-blocking equivalent to :!tf info "%"

  • :TF rename

Moves or renames the current file or directory or provided path.

  • :TF delete

Deletes current file or directory Non-blocking equivalent to :!tf delete "%"

Keybinds

This plugin defines some keybinds by default. Mostly staring with <leader>t.

You can disable default keymaps via vim.g.tfvc_disable_default_keymaps = true Note that unlike other options, this must be set exactly like this, and must be set before the plugin is loaded.

Default keybinds:

  <leader>ta   Add current File to Source Control
  <leader>tu   Undo changes in current file
  <leader>ti   Show info about current file
  <leader>tc   Checkout file for editing
  <leader>tl   Compare local file to latest server version
  <leader>tw   Open Web History for current File/Directory
  <leader>ts   Load Status (Pending Changes) into quickfix list
  <leader>tr   Renames/Moves file or directory
  <leader>th   Shows history of current file in interactive buffer 
  <C-A-j>      Diff next file in quickfix list 
  <C-A-k>      Diff previous file in quickfix list 
  <C-A-l>      Toggle diff view 

Versionspec

Some commands require a file-version which can specified a number of ways. The versionspec format is as follows (taken from the TF.exe help):

  Versionspec:
    Date/Time         D"any .NET Framework-supported format"
                      or any of the date formats of the local machine
    Changeset number  Cnnnnnn
    Label             Llabelname
    Latest version    T
    Workspace         Wworkspacename;workspaceowner

Source Control buffers

tfvc.nvim provides custom buffers for viewing directory- and file-history and changesets.

These buffers define a handful of keymaps for navigation and diff operations. Unlike the default keybinds for normal commands, there is currently no way to disable or remap these keybinds.

Note that viewing diffs may fail, if one version of a file does not exist because it has been renamed or deleted.

History Buffer Keymaps

<CR>          Open the changeset of the current line
dd            Open the changeset of the current line
gx            Open the changeset in the webclient
<leader>te    Open the local path of the file or history

# the remaining are only availible in file-histories, not directory-histories
gf    Open the changset-version of file
dl    Compare changset-version of file with the local version of the file
<CR>  (visual mode keymap) Compare versions based on the start, and end of the visual selection 
dd    (visual mode keymap) Compare versions based on the start, and end of the visual selection 

Changeset Buffer Keymaps

<CR>  Compare changed file with previous version
dd    Compare changed file with previous version
dl    Compare changed file with local version
dt    Compare changed file with latest server version
gf    View file version

Limitations

This plugin currently assumes a case-insensitive file-system.

Questions & Answers

  • How do I check in changes?

Run tf checkin outside of nvim. It will open a gui-tool. It has usable keyboard navigation and you need to use it if you want to associate a specfic work item with your changeset as you check in, as far as I can tell.

  • How to I get the latest changes from the tfvc server?

Run tf get . /recursive /noprompt outside of nvim. if you have conflicts you can run `tf resolve /noprompt /auto:[strat] to resolve them.

  • How do I reload a serverFile or history buffer if it failed to load

The same way you reload local files. With :e!

  • How do I clear untracked changes in my working copy?

Run tf reconcile . /clean /recursive /noprompt.

You can add the /preview flag to preview what it would delete without actually running it.

  • How do I use nvim to resolve merge conflicts?

I don't know. You tell me, when you figure it out.

About

Team Foundation Version Control integration for Neovim

Topics

Resources

Stars

Watchers

Forks

Contributors