07-14-2014 11:16 AM
One of the great powers of Git is feature branches. If you have several features to add to a VI separately, Git can help you do that seamlessly. Even if you are the only person working on a repo (even if it's all local and you don't have a remote repo!) branching in git is helpful.
With a little help in the configuration files (gitconfig, etc.) you can get merge to automatically call the appropriate NI program to help solve conflicts.
These lines are in my local repo's .git/config file:
[diff "lvcompare"]
name = LabView Diff (Compare)
command = lvcompare.sh
[merge "lvmerge"]
name = LabView Merge
driver = lvmerge.sh %O %B %A %A
Below are the bash shell scripts I wrote/modified to work here. Place them in your C:\Program Files (x86)\Git\bin folder. I have nearly identical scripts and config lines for TestStand sequence files.
LVCompare.sh:
#!/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: $tgt5 $tgt2 # Names are friendly...
# LVCompare command line
"C:\Program Files (x86)\National Instruments\Shared\LabVIEW Compare\LVCompare.exe" -lvpath "C:\Program Files (x86)\National Instruments\Labview 2013\LabView.exe" "$tgt5" "$tgt2" -nobdcosm -nobdpos -nofppos
rm -rf "$tgt5" "$tgt2" #removing unnecessary files
--------------------------------
LVMerge.sh:
#!/bin/bash
#Based on script by ewitcher
# Mergetool already asks for a confirm - JP
# read -p "Press any key to start the comparison"
echo $1 # Base
echo $2 # Remote (theirs)
echo $3 # Local (yours)
echo $4 # Merged
cp "$1" "$PWD/temp_${1##*/}" #Moving and renaming the temp file
cp "$2" "$PWD/temp_${2##*/}" #Moving and renaming the temp file
cp "$3" "$PWD/temp_${3##*/}" #Moving and renaming the temp file
tgt1=$PWD/temp_${1##*/} #Setting up the correct value to the tgt1 parameter
tgt2=$PWD/temp_${2##*/} #Setting up the correct value to the tgt2 parameter
tgt3=$PWD/temp_${3##*/} #Setting up the correct value to the tgt3 parameter
tgt4=$PWD/$4 #Setting up the correct value to the tgt4 parameter
# stream edit: (substitute) "/" with "\" (g)lobally (the whole string)
# Extra c\ due to Git running in MINGW32, replace with C:\
tgt1=$(echo ${tgt1} | sed 's/\//\\/g' | sed 's/\\c\\/C:\\/')
tgt2=$(echo ${tgt2} | sed 's/\//\\/g' | sed 's/\\c\\/C:\\/')
tgt3=$(echo ${tgt3} | sed 's/\//\\/g' | sed 's/\\c\\/C:\\/')
tgt4=$(echo ${tgt4} | sed 's/\//\\/g' | sed 's/\\c\\/C:\\/')
echo Launching LVMerge.exe With args:
echo $tgt1
echo $tgt2
echo $tgt3
echo $tgt4 # Names are friendly...
# LVMerge command line
"C:\Program Files (x86)\National Instruments\Shared\LabVIEW Merge\LVMerge.exe" "$tgt1" "$tgt2" "$tgt3" "$tgt4"
rm -rf "$tgt1" "$tgt2" "$tgt3" #removing unnecessary files
----------------
The last piece of the puzzle is to tell Git to launch these things when the files change. Add this to your repo's .git\info\attributes file:
# Use a custom driver to diff/merge LabView files
*.vi diff=lvcompare merge=lvmerge