14

When I add a shell script (foo.sh) to subversion, by default it sets the svn:mime-type to application/x-shellscript. Since this does not start with text/, diff and blame essentially ignore the file. I looked at the official list of text mime-types but did not see anything that looked like a shell script.

Is there a good value to set it to?

Update

Following the advice below, I set the mime-type to text/x-shellscript. However, blame still thinks that it is a binary file.

$ svn blame file.sh 
Skipping binary file: 'file.sh' 
$ svn proplist file.sh 
Properties on 'file.sh':
  svn:executable
  svn:mime-type 
$ svn propget svn:mime-type file.sh
 text/x-shellscript

Is there something else that I need to do to convince subversion that it is a text file?

3 Answers 3

16

The file utility uses `text/x-shellscript' for shell scripts:

$ file --mime-type /tmp/test.sh
/tmp/test.sh: text/x-shellscript
1
  • 2
    Helpful, but just to clarify: Whether text/x-shellscript is returned depends entirely on the shebang line of the file in question, not its filename suffix (.sh), if any. In short: the shebang line must be #!/bin/(sh|bash|csh|tcsh|ksh|zsh) (expressed as a regex; not sure if there are more); note that a #!/usr/bin/env -based shebang line is not recognized. If these conditions aren't met and the file is otherwise a text file, text/plain is returned.
    – mklement0
    Sep 29, 2015 at 4:28
1

Auto-properties are fully-client-side feature. With auto=properties you can also define|redefine some properties for added to Subversion repository objects (i.e for old adds you have to redefine wrong mime-type)

In config file of your subversion (platform-dependent location)

  • in [miscellany] section uncomment # enable-auto-props = yes string
  • in [auto-props] section uncomment # *.sh = svn:eol-style=native;svn:executable and edit accordinly (remove unwanted, add needed like svn:mime-type=text/plain)

After this all new *.sh files in repo will appear as text/plain.

But, because config is client-side and changes in it does not populated in repo, any other Subversion client will continue to add *.sh files as text/x-shellscript unless your changes are not repeated

1

Subversion rarely sets mime types by itself; either your client did it by itself (in which case you will probably want to adjust its configuration), or some form of standard svn auto-props processing is active (again, you will want to adjust it - for shell scripts you'll also want to set svn:eol-style to LF; some shells will barf on DOS/Windows line endings, and by ensuring Unix line endings are used everywhere, you avoid issues with using the files via a network share, or some Windows builds of shells (e.g. Cygwin)).

The problem with svn blame is that the property is versioned. Any revision of the file from before the property change is still binary (because the mime type does not start with text/), so diffs (and blames) will not work (easily) against those revisions.

I think the only fix for this is to get an admin to modify the repository to remove the "bad" mime type.

However, as a workaround, you should be able to pass --force to blame, to tell it to treat all files as text.

In fact, looking at http://subversion.1072662.n5.nabble.com/svn-blame-not-working-for-files-which-had-binary-mime-type-in-a-previous-revision-td177847.html, recent subversion clients will tell you to use --force.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.