ramar.work

Stupid Git Problems and Windows Interoperability

Unix and Windows still don’t get along very well. I don’t know why this is in 2017, but it’s very much a thing. From access control lists to setting up git and mercurial, moving sound programming tools to Windows is still absolutely too difficult.

Case in point, Git for Windows (or Git in general?) has issues digesting files with Windows line endings. Mind you, this version of Git is running on a Windows system! How is that an issue?!

I discovered this nonsense when playing around with writing some hooks. It’s an incredibly simple hook, but it never came together. It was working fine on Cygwin and regular *nix, as well. Below is the example, borrowed from this page via Digital Ocean:

#Adapted from the Git manual.   This only allows pushes of the master branch.
while oldrev newrev ref
do
     if [[ $ref ~= *./master$ ]]
     then
         echo "Accepting master ref..."
         git --work-tree=../my-dir --git-dir=. checkout -f
     fi
done

This worked in about two minutes on Cygwin, which is a bit of a nightmare in practice, but that’s another story. When trying to duplicate the same thing on Windows Server, error after error kept occurring. Mostly just Bash syntax errors (even though it was valid shell code). So I think maybe Git is calling up the the wrong interpreter or perhaps the while loop is a bad idea.

#One line.  That's it... 
git --work-tree=../mydir --git-dir=. checkout -f
Unfortunately, that didn't quite work either. Now the error was something like:

remote: ': not a valid identifier git
....

Now that is a particularly cryptic error and that forced to start some brute force testing. I whipped up a quick script and tried some new things.

#adds some garbage to a file, commits and pushes to master
echo "yah" >> file && git add file && git commit -m "..." && git push

After many runs of this, it still fails.

Then it dawned on me when I saw the way that Vim saved files. DOS line endings are the default when using a Windows shell (even though Vim is running in said shell.) I opened the file in another application and saved it with Unix line endings. The hook now works. I can’t help but wonder why so much time had to be wasted on such a trival problem. Is Git or Git for Windows really so crippled that it can’t discern between these two? Is Git Bash the issue? Why?