From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW with Git

Dear all,

 

I am a researcher using LabVIEW to develop some code, and recently I decided to implement some version control to our code using Git. While trying to make the diff work I encountered this thread that helped me to get finally what I wanted. Just for the history, I am using LabVIEW 2009 Professional (32bit) running it on a Windows 7 64bit machine.

 

I have some comments on the script of ewitcher:

 

First of all the script seems to be working only when comparing two old versions of a file (not the current tip of the HEAD with an old version). That is because git diff normally automatically copies the old versions of a file in the windows 'temp' folder, but it doesn't do so for the current version of the file. Thus when calling the LVCompare and adding the arguments $1 and $2, the $1 variable (which is the current version of the file) doesn't contain the working directory.

 

Secondly, when comparing two old versions of a file, git diff copies both files in the windows temp folder. This makes the script and LVCompare work, however the comparison is slow, cause LVCompare has to find all the subVIs that the original VIs are using.

 

In order to solve both of these problems I implemented the following method in the lvcompare.sh script:

 

- lvcompare.sh finds the two VIs that are to be compared and copies them in the main working folder of the repository. It also changes slightly the name (by adding the string 'temp_' in the beginning) so it doesn't overwrite anything.

- Then, it takes the name of the VIs from the $5 and $2 variables, strips down all the directories (in order to just keep the name), adds the working folder of the repository and stores this string as 'tgt5' and 'tgt2' variables.

- It then changes all the / to \

- It calls the LVCompare

- It deletes the files it created

 

Here is the code:

 

#!/bin/bash

#Based on script by ewitcher

read -p "Press any key to start the comparison" cp "$5" "$PWD/temp_${5##*/}" #Moving and renaming the temp file cp "$2" "$PWD/temp_${2##*/}" #Moving and renaming the temp file tgt5=$PWD/temp_${5##*/} #Setting up the correct value to the tgt5 parameter tgt2=$PWD/temp_${2##*/} #Setting up the correct value to the tgt5 parameter tgt5=$(echo ${tgt5} | sed 's/\//\\/g') #Changing the backslashes with slashes tgt2=$(echo ${tgt2} | sed 's/\//\\/g') #Changing the backslashes with slashes echo Launching LVCompare.exe: $tgt1 $tgt2 # Names are friendly... # LVCompare command line "C:\Program Files (x86)\National Instruments\Shared\LabVIEW Compare\LVCompare.exe" "$tgt5" "$tgt2" -lvpath "C:\Program Files (x86)\National Instruments\LabVIEW 2009\LabVIEW.exe" -nobdcosm -nobdpos -nofppos rm -rf "$tgt5" "$tgt2" #removing unnecessary files

 

As you can also see, I use the 5th ($5) argument from the diff command, instead of the 1st ($1). The first one is always the latest version of the file, which shouldn't be the case when the user wants to compare two old versions of a file.

 

Last but not least, I also configured git a bit differently. Instead of using lvcompare.sh with a difftool, I added an attribute in the .gitattribute file so that git uses a specific driver for .vi files, and also I set up git to use

 

Added in the .gitattributes:

#Use a custom driver to diff LabView files
*.vi diff=lvcompare

Added in the settings of git:

diff.lvcompare.command=lvcompare.sh

This way, when git diff encounters a file that is not a .vi it uses it's native diff function instead of calling LVCompare.

 

So in order to invoke the diff, the user just has to do a 'git diff' and the system will automatically understand when to use LVCompare and when not.

 

Hope this works for everybody 🙂

 

Message 21 of 28
(5,936 Views)

Hi

 

just FYI: I found this and it works great over here.

 

https://github.com/joerg/LabViewGitEnv

 

 

cheers

      ARUN

Message 22 of 28
(5,846 Views)

I couldn't get this to work, many commands fail along the way.

And not being a "command-enabled" person, it's hard to tell what's wrong... 😞


We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

0 Kudos
Message 23 of 28
(5,319 Views)

I would be happy to help out if you post the error codes that you encounter as well as the LabVIEW version, software and OS that you're using to replicate the code. Have you used TortoiseGIT to configure your code? Are you running LabVIEW Professional if it is a 2009 version?

 

Ben R.
Aerospace & Defense Test
Solutions Marketer
National Instruments
0 Kudos
Message 24 of 28
(5,297 Views)

Would it not be nice  to have a KnowledgeBase about this? I'm using GIT for a lot of projects, and I think it's very nice to have the graphical tools available. 

I'm in an academic situatation, so it would be nice to have some article to refer to to students to setup their environment. We're mostly using Git Extentions as GUI. I'd be more than happy to test drive instructions.

0 Kudos
Message 25 of 28
(3,839 Views)

KBs usually contain product-related information especially geared towards support. Since there is pretty limited integration between git and labview, there wouldn't be a lot to talk about.

There are some resources, though:

The git user group:
https://decibel.ni.com/content/groups/git-user-group

 

I wrote these up as a set of steps for my coworkers. I don't know that they're that useful since I've walked people through them personally, but whatever.
https://decibel.ni.com/content/docs/DOC-37416
https://decibel.ni.com/content/docs/DOC-37417

I'd also recommend looking in to http://www.sourcetreeapp.com/ rather than Git Extensions. I think its pretty nice.

Message 26 of 28
(3,818 Views)

Thanks for these resources. I found a few before, but not your own writeups. I'll try it out soon.

I had found (and tried) tortoiseGit, which very easily integrates LabViewMerge and LabViewCompare. However, I don't like to do everything from  the explorer window (just a personal preference).

 

I tried out SourceTree before, but found it to be very slow and resource hungry. Maybe it's improved now, I'll give it another go.

0 Kudos
Message 27 of 28
(3,776 Views)

thank you for your advice, I will have a try

0 Kudos
Message 28 of 28
(2,430 Views)