sctweedie / csvdiff3

3-way diff/merge tools for CSV files
MIT License
9 stars 4 forks source link

How to use with git LFS? #12

Open turion opened 8 months ago

turion commented 8 months ago

I successfully created a test repo with a CSV file where I could rebase some commits with your tool that would have created a conflict otherwise. Awesome!

I don't know how to use this in another repo where I also have git LFS on CSV files. I tried combining filters and your merge tool:

*.csv filter=lfs merge=csv_pkg diff=lfs -text

With the same git config:

[merge "csv_pkg"]
    name = 3-way CSV merge
    driver = csvmerge3 --key=\"timestamp\" %O %A %B -o %A
    recursive = text

But I'm getting: csvdiff3.merge3.PrimaryKeyError: Cannot find a valid primary key in timestamp

turion commented 8 months ago

I'm assuming the error comes from your tool trying to interpret the LFS pointers as CSVs, and fails.

turion commented 8 months ago

I'm currently experimenting with a shell script like this:

#! /bin/sh

tmpfileO=$(mktemp /tmp/csv-merge.O.XXXXXX)
tmpfileA=$(mktemp /tmp/csv-merge.A.XXXXXX)
tmpfileB=$(mktemp /tmp/csv-merge.B.XXXXXX)
tmpfileM=$(mktemp /tmp/csv-merge.M.XXXXXX)

cat $1 | git-lfs smudge -- $4 > $tmpfileO
cat $2 | git-lfs smudge -- $4 > $tmpfileA
cat $3 | git-lfs smudge -- $4 > $tmpfileB
csvmerge3 --key=timestamp $tmpfileO $tmpfileA $tmpfileB -o $tmpfileM
cat $tmpfileM | git-lfs clean -- $4 > $2

But I don't know whether that's the best approach.