Ruby on Rails, Git and CRLF - nontrivial - ruby-on-rails

I am learning Ruby on Rails and I use Windows 7. When I try to commit my changes to Git, I receive the fatal: LF would be replaced by CRLF message.
It seems that rails generate generates files with LF, not CRLF. Of course, I may switch from
git config --global core.autocrlf true
git config --global core.safecrlf true
to
git config --global core.autocrlf true
git config --global core.safecrlf warn
but I don't like the possibility of crushing any committed binary into pieces.
I tried to avoid the problem with .gitattributes, but my lines like
* text=auto
*.rb text
do not help.
Is there a way to make Rails generate files with CRLF ending? Or is there a way to make Git auto-transform the .rb and .erb files, but not others?

I don't like the possibility of crushing any committed binary into
pieces.
Are you sure that's a real problem?
If you turn the warnings off (core.autocrlf true) git will make the adjustments when you commit and you can continue being productive.
If you truly have a solid reason for not wanting to do this you are going to have difficulty as I don't think there is a simple way (there is always some way) to have Rails generate files with the CRLF ending and it's weird to have git auto-transform based on file type.
I can certainly be wrong, but it seems like you're trying a bit too much to work against your tools?
Possibly useful reference: git commit creates assets and temporary files for some reason
If you really want to go down the road of attempting to configure git to make these changes you can check out a git attribute filter driver as suggested in this response: Can git automatically switch between spaces and tabs?
Another useful reference to the above proposed solution: https://stackoverflow.com/a/2354278/1026898

Related

Git conflict - mergetool not configured

I have had an issue with my project: I forgot to pull the remote branch before working. then I got a conflict with a stylesheet called application.css
Though when I pulled the remote branch to origin, all not conflicted files were updated (which was good). Only the above file was marked as conflicting.
My command line tool said I had to fix the conflict before commiting.
I then ran : git mergetool
But got an error mergetool not configured and then something called vdiff was launched.
It is a Windows command line conflict resolving tool but I am a bit lost of what I should do. I have no knowledge of the keys that I may use
Can you help me fix this ?
why don't you just open up it up with something like sublime text and then edit the conflicted application.css file manually?
After the conflict is solved you'll have to mark the file as resolved by executing
git add <filename>
Finally, after solving all conflicts, a merge conflict situation needs to be concluded by a regular commit.

Git isn't pushing everything on my initial commit for my ASP.NET MVC projects. It's always missing references?

I use SourceTree.. i don't have anything in the .gitignore files.. I never had this problem with other types of projects before.. For some reason with my ASP.NET MVC project.. i'll make an initial commit and i'll pull right away in a diff location just to make sure and it's always erroring because it's missing references.. i dont think it's pushing ALL the files and it's missing some.
I've tried it the command line way using these commands here:
git add --all
and also tried
git add --all :/
nothing works. everytime i pull to see if it included everything, i always get a lot of references errors as it seems like it's just not pushing everything.. i'm so frustrated.
thanks for any help.
okay so a coworker was able to find the solution for me.
git config --get core.excludesfile
found that i had a weird global hidden file somewhere random in a hidden folder
git config --globalcore.excludesfile false
that disabled it

Gerrit patch comparision for Sql files

I am using Gerrit for code review for all the SQL files that is being used in the Project. Gerrit is hosted on Linux machine and its version is 2.6.1.
I have problem in comparing SQL patch set and all the SQL files are considered to a binary file by Gerrit and hence unable to provide the comparison.
For reference, following is the response on Gerrit comparison:
diff --git a/web/dev-db/sp/dbo.usp_getactivityownerlist.sql b/web/dev-db/sp/dbo.usp_getactivityownerlist.sql
index f623dd3..e2ed93b 100644
--- a/web/dev-db/sp/dbo.usp_getactivityownerlist.sql
+++ b/web/dev-db/sp/dbo.usp_getactivityownerlist.sql
Binary files differ
Is there any way I can configure Gerrit to consider .SQL file as a text file rather than binary file so that patch comparison is easy.
Try adding the following line to your $repo/.git/info/attributes:
*.sql crlf diff
It normally happens when user set core.autocrlf to false in global config file. This effectively disabled "smart" detection of line endings in text files.
It can be encoding issue as well, Git works best with utf-8, if the encoding is in something like utf-16, Git will think it's binary, no matter what you set in .gitattributes

Writing Rails on multiple Os (windows and osx)

I have have to work on a windows machine at work but have a mac at home. All of my rails code is written on the mac which is using RVM and deploying to heroku using GIT.
However I want to start working on the code on a windows machine (code held in dropbox and synced automatically)
I remember that line endings caused hell in git when I used to write python code... What are the requirements to be able to right RoR using two different operating systems?
You can configure git to convert line endings to one or the other upon committing: http://help.github.com/line-endings/
When you are describing paths, be sure to use built in methods for constructing them OS independently, like File.join.
You need to use the core.autocrlf feature.
From the manual
core.autocrlf
Setting this variable to "true" is almost the same as setting the text attribute to "auto" on all files except that text files are
not guaranteed to be normalized: files that contain CRLF in the
repository will not be touched. Use this setting if you want to have
CRLF line endings in your working directory even though the repository
does not have normalized line endings. This variable can be set to
input, in which case no output conversion is performed.
git config --global core.autocrlf true
So, In your windows machine, set this feature to true, which means,
During commit, your line endings will automatically be changed to LF and when you checkout your local files will have Windows' line endings (i.e., CRLF)
git config --global core.autocrlf input
In your non-Windows machine, set this to input, which means
Don't do any conversions, I'm not prone to any line ending changes
Why not configure heroku on your work machine instead? You already have version control (git) to take care of syncing and sharing your app.

vim plugin command w/o a buffer

I have a problem with many vim commands that come from plugins. They don't within an empty buffer.
For example :Gstatus from fugitive plugin doesn't work when in a new tab/buffer.
The strangest thing though is that initially, just after running vim, it works. i.e. if I just run vim and type :Gstatus it will work. but if before that I do :newtab or :enew it will not work.
The difference that I see that the first open buffer seems to be in a [Rails] mode, and the new ones are not.
These commands work on files and/or directories. When doing :tabnew you don't open a file or a directory. Since fugitive is only a (nice) wrapper around git, doing :Gstatus is like doing $ git status in your "Pictures" folder: it's not a git repository so git does nothing.
You could try to :cd to an actual git repository and do :Gstatus there.

Resources