travisjeffery / ClangFormat-Xcode

Xcode plug-in to to use clang-format from in Xcode and consistently format your code with Clang
https://twitter.com/travisjeffery
MIT License
2.89k stars 288 forks source link

Fixed a crash and a logic error, gitignore updated #101

Closed V01dZer0 closed 8 years ago

V01dZer0 commented 8 years ago

Fixed a crash with oh-my-zsh, whose 'which clang-format' command returns 'clang-format not found', instead of an empty string.

Fixed a logic error: abs(unsigned long - unsigned long) doesn't make sense.

git ignore file added xcworkspace

V01dZer0 commented 8 years ago

@travisjeffery new pull request has been created for oh-my-zsh crash fix.

travisjeffery commented 8 years ago

can we not ignore the workspace? also what's the behavior now for oh-my-zsh users? just uses the bundled version of clang-format?

V01dZer0 commented 8 years ago

@travisjeffery

should or should not ignore workspace:

xcworkspace is not under version control before, so each time enter 'git status' command, git will notice me there are untracked file under project.xcworkspace, that makes me feel the project unclean.
There are 3 file/folders in it (as described here)

  1. contents.xcworkspacedata Maybe the project will include other projects in the future, so you may want to added this file to version control then.
  2. xcuserdata already ignored
  3. xcshareddata Contains original repo info, and will be generated by Xcode if deleted. So I think this folder should be ignored for github public projects, since there are many forks, and for each fork, this file will be different.
what's the behavior now for oh-my-zsh users? just uses the bundled version of clang-format?

I didn't change the behaviour when the extension use clang-format in bundle or the system installed one, just fix this problem: when execute command 'which clang-format', and no clang-format installed to system, oh-my-zsh will return string 'clang-format not found' , instead of an empty string in bash. The extension will use the 'clang-format not found' string as the system clang-format path to start an NSTask, this will raise an exception and not catched, then the Xcode crashes.
So this commit will decide if the 'which clang-format' returned string is really a file path, or a warning noticed by shell. Use clang-format in bundle if the users didn't installed clang-format by themselves, otherwise use the user installed one, this is same as before.

Many of my friends use oh-my-zsh, but seldom install a clang-format by themselves.

oh-my-zsh is a very popular and powerful shell for mac, you may want to try it, and this line is not an advertisement : )

V01dZer0 commented 8 years ago

@travisjeffery And the crash stack is here: https://github.com/travisjeffery/ClangFormat-Xcode/issues/99