Paulis software -> Vedit resources -> Git Support 17. 01. 2015  
--------

GIT support for VEDIT

Git is a free, open source revision control system created in 2005 by Linus Torvalds for Linux kernel development. It is a lightweight, distributed system with an emphasis on speed. It does not require a server, so you can use it on your PC for example for your Vedit macro development, but it scales up to huge projects with hundreds of developers.

With this package you can perform some of the most common Git functions directly from within Vedit text editor. This makes it easy to perform the functions on the file you are editing, and to easily perform some operations that would require cryptic commands when using the command line tool.

The macro has been tested with Vedit 6.24, but it should work with older versions, too. However, some of the functionality (such as double-click) require Vedit 6.21 or later.

See below for description of each file in the package.

Download Download git_10.zip   -   V1.0   -   2015-01-17   -   13 K   -   Vedit 6.15 / 6.21

Main macro

git.vdm dialog box

git.vdm displays a dialog box for performing some basic git operations on your work files. The options available depend on context.

Add - Adds a new or modified file into staging area for commit (git add).
Remove - Adds a deleted file into staging area to be removed from repository (git rm).
Undo - Discards changes in the work file and fetches current version from git (git checkout).
Commit - Commits all files from staging area into git repository.
Status - Displays current commit status (modified files and files ready for commit).
Log - Lists commit log for current file, directory or repository.
Diff - Compare different versions of a file or directory.

If git.vdm is called while Log output (git_log.tmp) is the active buffer, the dialog box is somewhat different. Add and Undo buttons are omitted, but Files button is displayed.

Files - List files that where changed on the selected commit.

Detailed description:

Add
Remove

Add button adds current file (or a file selected from Status window) into staging area ready for commit (git add). If the file was previously not in the repository it is added there, otherwise a new version of the file is created in the repository.
If a deleted file is selected from Status window, the button is changed to Remove, and it will remove the file from index (git rm).

( In git workflow, you first add all the files related to your change into staging area and then use commit (below) to update all the files in the repository simultaneously. )

Undo

Discards all the changes you have made on current file by fetching current version from git repository (git checkout). If you have added the file in staging area and then made further edits, Undo fetches the version from staging area. After Undo, the file will no more be listed as changed in git status display, but any version in staging area will remain there.

You may want to use this option for example if you have written some ad-hoc testing code that you do not want to add to repository.

Commit

Updates all the files in your staging area into git repository. A second instance of Vedit opens for entering the commit message. Status of changed files is listed as comments (the comments will not be included in commit message). You can type one or more lines of text. When done, close this instance of Vedit and answer "Yes" when prompted to save the changes. If you leave the commit message empty (the message contains only comments), the commit is aborted.

After the commit has been performed, a message window is displayed at the bottom of screen. The window is green on success and red if there were any errors. You will have to close this window manually after reading the message.

Status

Opens a window to display current commit status. Lists files in the staging area (changes to be committed), changed files not yet added to staging area, and files that are not tracked by git.

If you double-click on a filename in this window, that file is opened for edit (requires Vedit 6.20 or later).
If you call git.vdm when the status window is active, you can perform operations (Add, Remove, Undo, Log, Diff) for the file on the cursor line. (If there is no filename on cursor line, the next filename is searched forward.)

Git Log dialog

Log

Lists commit log for the changes on the repository / current dir / current file (or file selected from status display).
A dialog box opens where you can choose options for log:

"List commits for" selection defaults to "File". Other options are remembered if you change them.

Click OK to create the log listing. A new window opens to display the log with syntax highlighting.

If you call git.vdm while the log display is active, the main dialog will have some different options. The Add and Undo options are not available. Instead, there is Files option (see below).

If you select Diff while the Log display is active, you can choose diff for selected commit. You can select a commit by moving cursor on any line of the text related to that commit. (See Diff below).

Git Diff dialog

Diff

Compares two versions of files with diff algorithm and creates list of changes between the versions.

A dialog box opens where you can select the options for git diff. You can choose to compare your work file to staged file (or to last commit if there is no staged file), or to compare staged file to last commit. In addition, you can choose to ignore space change, and to list the differences word-by-word (Word Diff) instead of line-by-line.

If you call git diff while Git Log is the active file, you have an option to choose an earlier commit from the list by moving cursor on the commit you are interested in. In this case, you have additional options to compare your work file to selected commit, or to compare selected commit to its parent. If the log was made for a single file, diff will show the changes on that file only. If the log was made for all commits in the repository, diff will show changes on all the files modified in that commit.

The diff results are displayed in a new window with syntax highlighting (so you can clearly to see which lines have been changed, added or deleted). If you double-click on a code line in the listing, the corresponding file is opened and the cursor is moved to corresponding line.

Files

This function is available when you call git.vdm from Log display window. Displays list of files changed on the selected commit. To select the commit, move cursor anywhere in the description of the commit (on the commit line or below it) and call git.vdm.

The file list is opened in a new window, together with the commit description. You can double-click on a line containing filename to open that file.

Double-click event macros

git_dclick_status.vdm - implements double-click on the git Status window and Files window. Double-clicking on a filename opens (or switches to) the corresponding file. (If the cursor is not on a filename, the macro tries to search forward for a line which lists modified, added or deleted file.)

git_dclick_diff.vdm - implements double-click on the git diff window. Double-clicking on a code line opens (or switches to) the corresponding file and moves cursor to the corresponding line (in the current version of the file).

(Note: The double-click macros require Vedit 6.20 or later.)

Syntax files

The package contains syntax files to add some color to each of the listings.
The syntax highlighting is automatically activated if you copied the supplied filename specific configuration files (*.CFN) into your config directory (see Installing Git Support below).

GIT_diff.syn provides syntax highlighting for Diff listing (git_diff.tmp). Colors are used to indicate changes. On the "Black chars on White" color scheme, the files on old version (deleted lines) are shown as red, and lines on new version (added lines) are shown as green.

GIT_log.syn provides syntax highlighting for Log listing (git_log.tmp) and changed files list (git_files.tmp).

GIT_status.syn provides syntax highlighting for Status display (git_status.tmp).

GIT_commit.syn provides syntax highlighting for the screen where you enter commit message.

(Note: The syntax colors work best with black-on-white color scheme.)

File type specific configuration

The package contains .CFN files for each output file type. The main purpose of these packages is to automatically enable color syntax highlighting. These files should be moved to your file-cfg folder. This can be done with Git_Setup.vdm macro below.

--------

Installing Git Support

You must already have git installed in such way that you can enter git commands from DOS prompt. To install and configure git, see git documentation (check the links below). For quick start, see chapters 1.6 First-Time Git Setup and 2.1 Getting a Git Repository in Git Book.

To install this git support package, unzip the files into your user-mac directory.
To configure git for Vedit, you can run the supplied macro git_setup.vdm. (This is not mandatory, you can do the configuration steps manually if you like.)

Git_Setup.vdm

Opens a dialog box where you can select the configuration steps you want. The macro performs the following steps:

  1. Move filename specific configuration files (*.CFN) to your file-cfg folder.
    The main purpose of this is to enable syntax highlighting for the status, log etc. displays. (If the files have already been moved, this option is grayed.)
  2. Set Vedit as Git default editor (used for entering commit text etc.).
  3. Create global Exclude file.
    Global exclude file will be used in all your projects. (In addition, you can have project specific .gitignore files.)
    Creates the exclude file by default in your vedit USER_CFG directory and then opens it for editing. If you already have an exclude file, it is opened instead. The macro adds vedit temporary files, .bak files and Wildfilew.vdm temporary files to the list of ignored files. You can manually edit the file if you need. (Dont forget to save the file.)

To make it easier to run git, you can add the following lines in your User or Tools menu:

1 + 128
Git...
#124=Reg_Free Call_File(#124,"git.vdm") Reg_Empty(#124)

(You may need to change the hot-key to suit your menu.)

---

Links

git-scm.com - Git Homepage
Git Book - Online version of the book Pro Git. Learn to use Git.