Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the xltrail-generated diff of an Excel workbook in Beyond Compare?

I'm using Git for Windows with the xltrail extension to provide a readable output when using git diff <Excel workbook>. I'm also using the graphical diff/merge tool Beyond Compare 4 Pro which runs when using git difftool and provides a nice side-by-side diff and three-way merge interface.

However, when I run git difftool <Excel workbook>, I get the normal git diff output without a prompt to open Beyond Compare. How can I get Git, xltrail, and Beyond Compare to work together?

Edit #1

Here's a complete example of this not working:

$ git config diff.tool; git config difftool.bc.path; git config difftool.prompt
bc
c:/Program Files/Beyond Compare 4/bcomp.exe
false


$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[diff "xltrail"]
        command = git-xltrail-diff.exe
[merge "xltrail"]
        name = xltrail merge driver for Excel workbooks
        driver = git-xltrail-merge.exe %P %O %A %B


$ cat ~/.gitconfig
# This is Git's per-user configuration file.

[user]
        name = Andrew Keeton
        email = [email protected]

[push]
        default = simple

[alias]
        co  = checkout
        ci  = commit
        cam = commit -am
        st  = status
        br  = branch

        # short log
        shlog = log --pretty=format:\"%C(yellow bold)%h%Creset %ad %C(cyan)|%Creset %s%C(magenta)%d%Creset %C(bold)[%an]%Creset\" --date=short --name-only
        hist  = log --pretty=format:\"%C(yellow bold)%h%Creset %ad %C(cyan)|%Creset %s%C(magenta)%d%Creset %C(bold)[%an]%Creset\" --date=short --graph

[diff]
        tool = bc

[difftool "bc"]
        path = c:/Program Files/Beyond Compare 4/bcomp.exe

[difftool]
        prompt = false


$ git st
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   workbook.xlsm
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")


$ git diff README.md
diff --git a/README.md b/README.md
index a052e20..3fd700d 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,11 @@

 ## Tips

+* Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+* Curabitur a dui eu massa feugiat varius tempor eget tellus.
+* Nullam et fringilla eros.
+* Etiam euismod ipsum enim, non molestie nunc varius eu.
+
 * In Excel, press `CTRL+G` to open the *Go To* window.  This makes it easy to find the various tables and "anchors."

 ## xltrail


$ git difftool README.md
<See screenshot of README.md in Beyond Compare 4>


$ git diff workbook.xlsm
diff --xltrail a/workbook.xlsm b/workbook.xlsm
--- a/workbook.xlsm/VBA/Module/modWorksheet
+++ b/workbook.xlsm/VBA/Module/modWorksheet
@@ -14,6 +14,7 @@
     Dim dDouble1 As Double
     Dim dDouble2 As Double
     Dim dDouble3 As Double
+    Dim sString1 As String
     Dim dDouble4 As Double

     Dim iInteger1 As Integer



$ git difftool workbook.xlsm
diff --xltrail a/workbook.xlsm b/workbook.xlsm
--- a/workbook.xlsm/VBA/Module/modWorksheet
+++ b/workbook.xlsm/VBA/Module/modWorksheet
@@ -14,6 +14,7 @@
     Dim dDouble1 As Double
     Dim dDouble2 As Double
     Dim dDouble3 As Double
+    Dim sString1 As String
     Dim dDouble4 As Double

     Dim iInteger1 As Integer

Screenshot of README.md in Beyond Compare 4

Screenshot of README.md in Beyond Compare 4

like image 544
Andrew Keeton Avatar asked Oct 25 '18 18:10

Andrew Keeton


2 Answers

Complete Solution (added by question-asker)

Create an executable script xltrail-bc-diff.sh in the existing C:\Users\<User>\AppData\Local\Programs\Git xltrail\ directory:

#!/bin/bash
#
# xltrail-bc-diff.sh massages the output of git-xltrail-diff.exe and passes it
# into Beyond Compare in "Text Patch" mode.
#
# Input arguments from `git diff` are:
#    $1   $2       $3      $4       $5       $6      $7
#    path old-file old-hex old-mode new-file new-hex new-mode

path="$1"
tempDiffPath=`mktemp --suffix=".diff"`

# xltrail's diff output is color-coded with no option to remove it
# (see https://github.com/ZoomerAnalytics/git-xltrail/issues/30) so we use
# sed to strip the color codes.
git-xltrail-diff.exe $@ | sed 's/\x1b\[[0-9;]*m//g' > $tempDiffPath

BCompare.exe -fv="Text Patch" $tempDiffPath

Add the following to your git config file:

[diff "xltrail-bc"]
    command = xltrail-bc-diff.sh

In the repository there should be a .gitattributes file that was created by xltrail to associate Excel files with the xltrail diff and merge tools. Change the diff entries to use xltrail-bc:

*.xla diff=xltrail-bc
*.xlam diff=xltrail-bc
*.xls diff=xltrail-bc
*.xlsb diff=xltrail-bc
*.xlsm diff=xltrail-bc
*.xlsx diff=xltrail-bc
*.xlt diff=xltrail-bc
*.xltm diff=xltrail-bc
*.xltx diff=xltrail-bc

And now git diff <Excel workbook> should open up in Beyond Compare.


Original Answer

First, you need to setup your git with something like that:

git config --global diff.tool bc4
git config --global difftool.bc4.cmd "\"C:/Program Files (x86)/Beyond Compare 4/BCompare.exe\" \"\$LOCAL\" \"\$REMOTE\""
git config --global difftool.prompt false

Then, you can check/edit your .git/config file, and ensure having something like that:

[diff]
tool = bc4

If it is not enough, please post your .git/config file.

Edit, for further needs. It seems it not basically possible to plug xtrail and Beyond Compare like that. I reproduced your issue with success. I though something may be possible to be done in the .gitattributes file, but without success.

So ... the only possible solution, complex one, will be to create your own diff script, and to plug all tools together.

On my side, I tried with a GNU/Bash script (you can get it supported installing Git Bash on your Windows), but you may want to create a .bat one.

First, you need to update your .git/config configuration file, to specify the path to your new script file, for instance:

[diff "myComplexDiff"]
    command = C:/Users/XXX/Documents/complexGitDiff.sh

Then, you need to link file extension with this diff, updating your .gitattributes file, with something like (to ba adpated for any wanted extension ):

*.xls diff=myComplexDiff

And then, the script, which can look like this:

#!/bin/bash -x
# Sample of information given by git
# b851185776b7826a6cc82d3aa6a8d53fa47e0c26 100644 simpleTest.xls 0000000000000000000000000000000000000000 100644
fileName="$1"
tmpFile="/tmp/"$( date +'%s')"$fileName.diff"
git-xltrail-diff.exe $@ >"$tmpFile"
c:\\Program\ Files\\Beyond\ Compare\ 4\\bcomp.exe "$fileName" "$tmpFile"

Actually I didn't find the needed option for Beyond Compare to accept the diff output of git-xltrail-diff.exe, but it is the only remaining thing to do.

like image 53
Bsquare ℬℬ Avatar answered Oct 31 '22 16:10

Bsquare ℬℬ


In the meantime, this also works with SourceTree which is free unlike BeyondCompare.

Just make sure to upgrade to the latest version of SourceTree while git-xltrail is installed and activated. You don't even have to change any settings, it should just work.

For details, see my blog post here: https://dev.to/fzumstein/how-to-diff-excel-vba-code-in-sourcetree-git-client-36k

like image 22
Felix Zumstein Avatar answered Oct 31 '22 17:10

Felix Zumstein