5

I've started using Github for hosting much of my code, including my Matlab code. It turns out that Github syntax highlights code based on its extension rather than the content of the file. This is not so great for Matlab m files. They get recognized as Objective-C files, also .m, and improperly identified/highlighted. Github does highlight Matlab m files if they have the .matlab extension, but the problem with this is that Matlab seems to refuse to run files that that don't have the .m extension. I haven't been able to come up with a solution, as I'd like my matlab files to play nicely with both Github and Matlab. So here are couple of questions:

  1. Is there a way to have all .m files converted to .matlab extensions when pushed to Github? This would also need to convert .matlab files to .m extensions when fetching or cloning from Github?

  2. If 1. isn't possible, is there a way to get Matlab to run files that have a .matlab extension?

If yes to either 1 or 2, I'd love some tips or examples of how to do this.

moorepants
  • 1,673
  • 2
  • 18
  • 22
  • 1
    This seems like a good feature request for github, to tag the file type and thus get the right syntax highlighting. I'm not sure it's a good idea to go changing file extensions between your working copy and your repository. – Alex May 25 '11 at 07:21
  • Correct matlab syntax highlight has finally been added to Github with the linguist project: https://github.com/github/linguist, so this question isn't that relevant anymore. – moorepants Jul 27 '11 at 04:40

2 Answers2

3

You can use git hooks to do point 1 in your question. If you look in .git/hooks/, you'll find some examples that you can use (what the different files do are explained here). Basically all you need to do is add a post-receive hook that will rename the files from .m to .matlab on github and a post-fetch or post-pull hook (might be fudging my terminologies a little here) that will rename them back to .m files.

Also, take a look at some of the related questions on git hooks on SO: 1, 2, 3, 4, and many more...

That said, I agree with Alex that it's generally not a good idea to change the extension between repositories, as you can end up breaking code for others who might use your scripts.

Community
  • 1
  • 1
abcd
  • 40,177
  • 7
  • 71
  • 97
  • Do the git hashes get computed based on the file contents alone? If so, does it matter if the extension is different on one repo than the other? I'm curious what you Alex and you think the complications are that may arise from setting up a hook to do this. I will submit a feature request for github but they've already closed several requests to do this. – moorepants May 25 '11 at 17:14
1

Check to see if Github will respect your attributes file(s). If so then set up a pattern for *.m and set the approprtiate attributes to ge the right viewing style.

The attributes file is also a place for the matlab LF normalisation of eol=LF (even on Windows) git-crlf-conversion-for-m-matlab-files

Community
  • 1
  • 1
Philip Oakley
  • 11,745
  • 8
  • 42
  • 63