18

Directly related: svn diff: file marked as binary type (Per the comment on the answer)

Why would my SVN client mark some files as binary?

Specifically, .sql has prop svn:mime-type = application/octet-stream when using TortoiseSVN.

I checked Right-click > Tortoise context menu > Settings > General > Subversion configuration file, and nothing is uncommented in [miscellany] or [auto-props], so where is the decision coming from?

From what I can see in the related posts, I can "fix it" by either deleting the property on affected files, or globally change the behavior on new files via config/setting, but is there a "simple" way to do both for all affected files?

Somewhat related:

Community
  • 1
  • 1
drzaus
  • 21,536
  • 14
  • 123
  • 183
  • Jeez, and removing the `mime-type` property (assuming it's defaulting to `text/plain`) shows a bunch of `NUL` character garbage every other character. Is my scenario just not applicable? The TortoiseMerge viewer compares it fine... – drzaus Oct 21 '13 at 16:09
  • 1
    I've got the same exact problem ... `.sql` files keep getting uploaded as `application/octet-stream` when they're clearly `text/plain`, with no `auto-props` set. Too bad no one has supplied an answer :( – brazilianldsjaguar Jan 20 '14 at 23:11

2 Answers2

18

Well, I found the issue in my particular case:

A developer had saved a template .sql file he was using for new scripts. This file, somehow, was saved with UCS-2 (or Unicode) encoding. Whenever he added files, TortoiseSVN determined that it was a binary file. By switching the encoding to UTF-8, the template and files derived from it are added correctly as text/plain.

Additional Info (Edit)

I found what might have been the culprit. When generating some scripts using the GUI, SQL Server Management Studio writes them as Unicode in the query window. If the file is saved, it will be saved as Unicode as well. Interestingly enough, files opened via the File>New don't save like this. An issue was raised with Microsoft about this back in 2007 (found here), that apparently hasn't been resolved.

brazilianldsjaguar
  • 1,369
  • 1
  • 19
  • 43
  • well that's going to be a pain to track down...but worth a shot – drzaus Jan 22 '14 at 21:36
  • I was able to spot it because of `Notepad++`, which has a nice `Encoding...` menu that allows you to view current and change encoding. – brazilianldsjaguar Jan 22 '14 at 22:46
  • Yeah, Notepad++ makes it easy to fix per file, but if you've got many files it seems a [batch script](http://www.msfn.org/board/topic/158633-how-to-check-text-file-encoding-from-command-line/) (or [this](http://stackoverflow.com/questions/18684793/powershell-batch-change-files-encoding-to-utf-8)) will be necessary. – drzaus Jan 28 '14 at 17:18
  • 1
    Agreed. I've added more information for the sake of completeness (e.g. how the files might have gotten into UCS-2 in the first place) – brazilianldsjaguar Jan 29 '14 at 01:27
7

Here's a quick way to fix this problem:

notepad %APPDATA%\Subversion\config

Scroll down to and uncomment this line:

enable-auto-props = yes

Under [auto-props] add this line:

*.sql = svn:mime-type=text/plain

Now when you add .SQL files to SVN, they will automatically be marked as text (not octet-stream).

EDIT: Removed unnecessary line ending file alteration.

user95209
  • 69
  • 1
  • 3
  • Interesting. I had done the same thing, only difference was that my auto-props were set to `*.sql = svn:mime-type=application/x-sql` instead (not sure why). Changing it to your suggestion made it show up as I wanted when committing. But I would point out that the `svn:eol-style=native` isn't necessary, and it's actually changing the file on disk. – drzaus Sep 22 '14 at 16:56
  • I'd mark this the answer but it doesn't seem to help for existing files. – drzaus Sep 22 '14 at 16:58
  • 2
    Existing files will have to be checked out, have their properties altered, and checked in again. But that is really a different question. – user95209 Oct 01 '14 at 01:15
  • the correct and IANA-registered mime type for SQL is `application/sql` per [RFC 6922](https://tools.ietf.org/html/rfc6922). Not sure what this does to TortoiseSVN's behavior. – rmalayter Oct 03 '17 at 19:51
  • The only way I was able to get JSON and SQL to display on an `svn diff` was to use `text/plain` as my mime type. Their respective application mime-types produce the following message for me when I try to see a difference: `Cannot display: file marked as a binary type` – Erkin Djindjiev Jun 28 '19 at 14:19