Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper mime-type of shell scripts in subversion

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?

like image 717
Troy Daniels Avatar asked Mar 08 '13 18:03

Troy Daniels


People also ask

What is SVN MIME type?

; svn:mime-type=text/plain.

How do I know my mime type?

For detecting MIME-types, use the aptly named "mimetype" command. It has a number of options for formatting the output, it even has an option for backward compatibility to "file". But most of all, it accepts input not only as file, but also via stdin/pipe, so you can avoid temporary files when processing streams.

What is shell script in Android?

The Android shell is a command-line interface for the Android operating system. It provides access to the Android file system and allows you to run Android applications from the command line. The Android shell is based on the Linux shell and provides many of the same commands.


3 Answers

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

$ file --mime-type /tmp/test.sh
/tmp/test.sh: text/x-shellscript
like image 122
nosid Avatar answered Oct 05 '22 08:10

nosid


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

like image 28
Lazy Badger Avatar answered Oct 05 '22 08:10

Lazy Badger


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.

like image 36
Zastai Avatar answered Oct 05 '22 07:10

Zastai