Subject: Filter-branch's "move tree to subdirectory" example fails with BSD sed?

From: Christopher Tiwald <[email-masked]>
Date: Sat, 14 Apr 2012 12:00:28 -0400

The "Move tree to subdirectory" example in the 'git filter-branch'
manpage fails on Mac OSX 10.7.3, but succeeds on Ubuntu 10.04. I'm
using git version 1.7.0.4, which happened to be the version installed
on the Ubuntu VM I had laying around. I think it's a difference between
'sed' on the two systems.

The example:
git filter-branch --index-filter \
        'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
                GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                        git update-index --index-info &&
         mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD

Demonstrating the problem is with sed:
git init "test"
cd "test"
mkdir -p subdirA/subdirB
echo content > subdirA/subdirB/file
git add .
git commit -m "initial commit"
git ls-files -s | sed "s-\t\"*-&newsubdir/-"

On Mac 10.7.3 the final command outputs:
100644 d95f3ad14dee633a758d2e331151e950dd13e4ed 0	subdirA/subdirB/file

On Ubuntu 10.04:
100644 d95f3ad14dee633a758d2e331151e950dd13e4ed 0	newsubdir/subdirA/subdirB/file

I can solve my immediate problem using Ubuntu, but is there a way we
could rewrite the example to work on both systems? I'm afraid differences
between BSD and GNU 'sed' are a bit beyond me.

--
Christopher Tiwald