#!/bin/bash
#
# http://stackoverflow.com/a/38140374/204658
#
# Script to convert symbolic links created by a windows git
# clone/checkout to cygwin links. When a typical Windows git checks
# out a symbolic link from the repo it (MsysGit, at least) tend to
# produce text files with flag 120000 and the link target file name as
# the content.  Strategy would simply be to find all those and replace
# by cygwin links.
#
# This will work if you are not planning on commiting anything, e.g.
# in a Jenkins, or other CI, build environment

for f in `git ls-files -s | awk '$1 == "120000" {print $4}'`
do
    echo $f is a symlink pointing to $dir/$target
    dir=$(dirname "${f}")
    pushd "$dir" 2>&1 > /dev/null
    file=$(basename "$f")
    target=`cat "$file"`
    rm "$file"
    ln -s "$target" "$file"
    popd 2>&1 > /dev/null
done
