File name not passed to Clean/Smudge Filter script?

30 views
Skip to first unread message

Ken Ismert

unread,
Apr 23, 2013, 12:34:33 PM4/23/13
to msy...@googlegroups.com
Hello, all:

I have run into an unfortunate situation where SQL files in my project are stored in a mixture of ansi and utf-16 formats. Thanks SQL Server Management Studio!

So, I tried to modify my earlier Clean/Smudge filter to use this script:

#!/bin/bash
set -o nounset
set -o errexit
# all this shows is that variable 1 is not set
mypath="${1:-unset_or_null}"
if [ ! -e "$mypath" ]; then
    echo "Number of arguments passed: $#" 1>&2
    echo "$@" 1>&2
    echo "File does not exist! Given path: $mypath" 1>&2
    exit 1
fi
iconv -f $(file -b --mime-encoding "$mypath") -t utf-8 "$mypath"
exit 0

The only problem is, the file name is never passed into this script!

Questions:

1. Is this a bug? The above approach certainly works when setting up a diff filter
2. Is there a file name placeholder I can put directly into gitconfig? I tried putting in "$1" in the filter definition, but that failed.

Thanks,
-Ken

Johannes Sixt

unread,
Apr 23, 2013, 3:03:15 PM4/23/13
to Ken Ismert, msy...@googlegroups.com
Am 23.04.2013 18:34, schrieb Ken Ismert:
> So, I tried to modify my earlier Clean/Smudge filter to use this script:
> ...
> The only problem is, the file name is never passed into this script!
> ...
> 2. Is there a file name placeholder I can put directly into gitconfig? I
> tried putting in "$1" in the filter definition, but that failed.

Use %f instead of $1.

-- Hannes

Ken Ismert

unread,
Apr 23, 2013, 8:26:23 PM4/23/13
to msy...@googlegroups.com, Ken Ismert

> Use %f instead of $1.

Yep, that did it. In the manual, too. Thanks, Hannes.

Why do diff filters have an implicit file parameter, and clean/smudge filters require %f?

-Ken
Reply all
Reply to author
Forward
0 new messages