Paulis software -> Vedit resources -> Git Integration 31. 10. 2018  
--------

GIT integration 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.

This package contains:

  • Main macro
  • Doubleclick event macros
  • Syntax files
  • File type specific configuration
  • Installing Git Integration
  • See below for description of each file in the package.

    This package 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.

    Download Download vedit_git_11.zip   -   V1.1   -   2018-10-30   -   16 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 and on the status of selected file.
    (Click on a button below to see the description of corresponding function.)

    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.
    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)1).
    Undo - Discards changes in the work file and fetches current version from git (git checkout).
    Undelete - Restore deleded workfile by fetching it from repository (git checkout). 2)
    Unstage - Remove file from staging area (git reset). 3)
    Commit - Commits all files from staging area into git repository.

    1) Button [Remove] is displayed instead of [Add] if the workfile has been deleded.
    2) Button [Undelede] is displayed instead of [Undo] if the workfile has been deleded.
    3) Button [Unstage] is displayed instead of [Undo] if the file has been staged.

    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, and the following buttons are displayed instead:

    Files - List files that where changed on the selected commit.
    Get - Fetch selected revision of selected file into a temporary file.

    Detailed description:

    Screenshot showing Status and Log windows.

    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.)

    Click on the thumbnail on the right to see screenshot showing git Satus and Log windows. →


    Log

    Git Log dialog

    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 are options Files and Get (see below).

    If you select Diff while the Log display is active, you can choose diff for selected commit. You can choose to compare selected revision to previous revision, or to compare any two revisions. (See Diff below).

    Diff

    Git Diff dialog

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

    A dialog box opens where you can select the options for git diff:

    1) These options are available if you call git diff while Git Log is the active file.
    2) This option is available if you have highlighted a block (see below).

    Additional options can be selected with checkboxes:
      [ ] Ignore space change - If number of spaces (e.g. indent level) has been changed, that change is not shown.
      [ ] ignore Newline type - CR, LF or CR-LF change is ignored.
      [ ] Word Diff - list the differences word-by-word instead of line-by-line.


    If you call git diff while Git Log is the active file, you have the additional options mentioned above. You can choose a revision by moving cursor anywhere in the revision headers or description. To complare any two revisions, first highlight a block anywhere in the description of the first (older) revision you want to compare. Then move cursor to the second revision and execute git diff.

    If the log was made for a single file, you can choose to show the changes on that file or to all files. If the log was made for all commits in a dir or in the repository, you can only list diff for 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.

    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.

    Undelete

    If your workfile has been deleded but not removed from repository, this function restores the file by fetching it from repository (git checkout).

    Unstage

    Remove the selected file from staging area (undo [Add] or [Remove]) (git reset HEAD). After that, you can undo any changes you have made on work file by using [Undo] or [Undelede].

    Commit

    Updates all the files in your staging area into your local git repository. A confirmation dialog box opens. Here you can choose to create a new commit or to amend previous commit (e.g. to modify the commit message or add more files to the commit).

    When you click OK, 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 as commit message. If you selected 'Amend', the previous commit message is already filled in.

    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.

    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 xxx" 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.

    Get

    This function is available when you call git.vdm from Log display window. Fetches the selected old revision of a file.

    Move the cursor to the revision you want to fetch. Then call git.vdm and select 'Get'. A dialog box opens where you can choose where the file is to be stored: VEDIT_TEMP directory or to 'current dir' (the same directory as your workfile). The name of the file is formed by inserting '#' and the first 5 digits of the revision hash at the begin of the original file name. (If you choose to store the file in VEDIT_TEMP directory, it will be automatically deleded next time you boot your PC.)


    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 Integration 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 (COMMIT_EDITMSG).

    (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 Integration

    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 integration 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 message etc.).
    3. Enter your username and e-mail addres into git configuration (these are required by git). If you have already entered this information, the current values are displayed and you may change them if needed. If no changes are needed, you can either click OK or Skip.
    4. 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 (anywhere in your computer), it is opened instead. Optionally, 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. (Note: if you already have these in your exclude file, they are still added at the end of file, so you need to delete the old ones.)
      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.)

    ---

    Change log

    V1.1 -- 2018-09-30

    V1.0 -- 2015-01-17

    ---

    Links

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