Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with git diff? #46

Open
HelenFoster opened this issue Oct 12, 2017 · 4 comments
Open

Help with git diff? #46

HelenFoster opened this issue Oct 12, 2017 · 4 comments

Comments

@HelenFoster
Copy link

Hi, this tool seems very useful and I'd like to try using it with my git-managed spreadsheets.

#30 gives some example config. I have the gitattributes working, but in the gitconfig, command doesn't seem to do anything - I still get the "binary files differ" message. (Using textconv works as expected.) I couldn't find anything in the git documentation about this feature. Any ideas what to try? I'm using git 2.13.6 on Fedora.

Also:
http://programmaticallyspeaking.com/git-diffing-excel-files.html
https://stackoverflow.com/questions/20069976/setup-git-diff-for-special-file-types

I haven't got this far yet, but the first link claims we need a wrapper script to pass arguments 2 and 5 to ExcelCompare, while the other sources don't do this. Which way is it? Maybe it's because that was an older version of ExcelCompare?

@HelenFoster
Copy link
Author

HelenFoster commented Oct 12, 2017

OK, I think I figured it out:

  • The thing specified in command is enabled and disabled by --ext-diff and --no-ext-diff
  • The thing specified in textconv is enabled and disabled by --textconv and --no-textconv
  • If both are present and enabled, command takes priority.
  • If neither is present and enabled, it says "Binary files x and y differ".

the first link claims we need a wrapper script to pass arguments 2 and 5 to ExcelCompare, while the other sources don't do this

It appears that we do need to do this, or it diffs the wrong things.

The wrapper also needs to return 0, or the diff stops after the first Excel file, as explained in #30.

@na-ka-na
Copy link
Owner

I think I will add an option --git_diff_mode where it will return 0 even if files differ. Will that be sufficient?

@HelenFoster
Copy link
Author

HelenFoster commented Oct 13, 2017

I think I will add an option --git_diff_mode where it will return 0 even if files differ. Will that be sufficient?

In this mode, it also needs to use the 2nd and 5th non-option arguments for the filepaths, instead of the 1st and 2nd.

If we write in the gitconfig:
command = excel_cmp --git_diff_mode

Then using git diff on older commits executes something like:
excel_cmp --git_diff_mode foo.xls /tmp/bCXUeU_foo.xls 77d26a92f6552ff9ab6e1d4586f8fa56143e740d 100644 /tmp/cRDpJ0_foo.xls 8fe0234a576d401423cc7068a40b14271e0339a4 100644

And here we want to diff the two files in /tmp.

The other arguments seem to be used to print a message about the git status of the changed file, but that could be worked out later.


Also, it would sometimes be useful to return 0 on "Failed to read as excel file". (Say I have one unimportant spreadsheet in my repo history that doesn't work, and I still want git diff to process the rest of them.) Maybe this should be a separate option.

@HelenFoster
Copy link
Author

I copied the excel_cmp shell script to excel_cmp_git and tried to edit it to approximate the behaviour of the internal git diff. Not sure if this is quite right yet, but I think it's doing what I need it to for now...

#!/usr/bin/env sh

if [ -L $0 ];then
  dir=`readlink -f $0|xargs dirname`
else
  dir=`dirname $0`
fi
tput bold; echo "excel_cmp_git a/$1 b/$1"
tput bold; echo "mode $4..$7"
tput bold; echo "index ${3:0:7}..${6:0:7}"
tput sgr0
java -ea -cp "$dir/dist/*" com.ka.spreadsheet.diff.SpreadSheetDiffer "$2" "$5"
exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants