Git not recognizing rails plugin - ruby-on-rails

I installed the table_builder plugin from https://github.com/p8/table_builder, followed the directions at the bottom titled For a pre rails 3.0 table_builder: which works great.
The problem is since I checked out a branch of it, when I try to commit this to MY GIT repo, it doesnt think there are files even there.. git status diplays nothing, git add wont add the files..
Any suggestions as to how I can get this committed?

Maybe you cloned the plugin directly into your own repository and you now have the plugin repository within your repository?
A git repository will by default ignore any other repositories and their working directories that are located within it.
If so, you have (at least) two options:
Clone the plugin elsewhere, and then
copy the necessary files into your
repository
Clone the plugin into your repository
and then delete the plugin's .git
folder
There are other ways to manage this with git-submodule but I'm not an expert on that so I defer to someone with more knowledge.

Check the .gitignore file in your project root folder. If git status doesn't see the files and git add won't add them, it's most likely because they're being specifically ignored.

Related

Starting over with Git

I decided to learn how to use Version Control over Christmas break, so I downloaded Git, opened a GitHub account and started reading the online tutorial linked to from the GitHub website. When I got to this part http://progit.org/book/ch2-2.html I got stuck because I wasn't sure how to add files. For instance, I tried
git add C:/Finish.txt
And it said
Fatal: 'C:/Finish.txt' is outside repository
I was confused until I remember that a long time ago I had tried teaching myself Ruby on Rails and played around with Git back then. It never really went anywhere, but there's all this residual stuff floating around my system and I don't know how to change it. For instance, my Untracked files (which should be empty) are rails_projects/ and sample/.
How can I just erase all the old stuff and start over?
You should make a folder for your repository, move Finish.txt to that repository, then do git add.
For example:
# here you create C:\myrepo
cd C:\myrepo
git init .
# here you edit C:\myrepo\Finish.txt
git add Finish.txt
git commit -m "Added Finish.txt"
Start a new repository, e.g.
c:
md c:\newrepo
cd c:\newrepo
git init .
copy \Finish.txt .
git add Finish.txt
git commit -m "started over"
I strongly recommend against adding anything to C:\, let alone putting a git repo there. Unless of course you want to accidentally add all of your system disk to git :)
I can also heartily recommend using TortoiseGit which has some excellent explorer integration.
Delete any .git folder that you find in your drive.
To create a repo go to a folder that you want the repo in ( and not just randomly), do:
git init
Then proceed... Add only files that you put within this repo and not randomly from some location.
It would be very unusual to have the root directory of your hard drive be a git repository. That's probably why it's giving you the error.
git repositories are typically in a subdirectory and that subdirectory is typically a project.
To initialize a subdirectory as a git repository, you'd do:
git init (directory)
Then you'd add your files and commit.

should script/plugin create a .git folder?

I noticed that if I do something like:
script/plugin install git://github.com/plug-xyz.git
It says it is creating a .git folder:
Initialized empty Git repository in /Users/g/Documents/app/vendor/plugins/xyz/.git/
But after the plugin is installed, it seems that the .git folder is gone.
I ask because when I try to update the plugin, nothing happens. It says it is updating, but when I check the files, they have not been updated to the latest version. I then removed the plugin, and re-installed it, and it was able to grab the most recent version.
Is it not possible to perform script/plugin update on git plugins?
You can see the changeset here: http://dev.rubyonrails.org/changeset/9049
It does remove the .git folder, presumably to save space by not storing history. This is traditional for a source control "install" instead of "checkout" or "clone" command, although it doesn't use a hypothetical "git install" command to do this.
script/plugin update looks for the .svn directory in each plugin so it can run svn update. That obviously won't work for git checkouts whether or not their .git folder has been removed. You should edit that script and send them a patch to enable the git version of update. It would probably be a pretty simple change.
.git folder is removed so that it doesn't get checked into your own SCM. For example, not everyone's using Git as their SCM (me for one) and wouldn't want to check in .git repos into my own for obvious reasons.
According to the help spat out by script/plugin, -x option would add SVN external. I found these two articles addressing this specific issue, but haven't tried solutions since I don't use .git

Installing rails plugins as git submodules

(Why there is no|Is there a) way to run
./script/plugin install -SOME_HIDDEN_OPTION git://github.com...
So that the plugin is installed as git submodule. The reason for submodules is to keep unrelated code off project's repository.
Perhaps there is a reason not keep plugins as submodules?
./script/plugin install git://github.com/something/something...
Should work without a submodule...
If you want to update the plugin, just navigate into that plugin's folder and do a git pull.
The only advantage of the submodule is that you can see all your submodules from anywhere in the git repository. Otherwise, git just find the nearest git repository and works on that... in te above case, navigating to the plugin's directory will make it the repository you are working on.
Submodules are a bit warty. Also if you clone your repo and one of your submodule remotes is down you're stuck.
I end up tweaking the local code on occasion as well, which necessitates it being in my repo.
Braid makes managing this situation simple.

Where to place Git repository

I just started using Git and I want to know if this is the right way of using it. I started a Rails app with:
rails newapp
Then I did:
cd newapp
git init
git add .
git commit -a
So is it "right" to init my git inside my working directory?
Yes. You can place a git repository anywhere - including the invisible .git directory created by another git repository. I have a friend who has git track all his system config files in case he makes a mistake.
When working on a project, you want to init your repository in the root directory of the project.
To elaborate, each "working copy" of a Git repository is itself a Git repository. If you have a remote copy on a server, that is also a repository. You don't "check out" from there - rather, you "push" your changes and they are merged. If working on a purely personal project, the remote repository is often unnecessary. If you do want to host remotely, Github is a good, free, public choice.
Yep. Looks good to me.
Yes. In a DCVS like git, your working copy is your repository.

How to update rails plugins installed through git but in a svn repo?

My rails app is in a svn repository, but several of the plugins are installed through git and later added to the svn repo. How can I update these plugins? I can't seem to get script/plugin update to do anything. I'd really like to update activemerchant to get rid of the Inflector warnings.
If you haven't made any local changes to the plugin and you don't need to track what changes to it the update will bring, you can just run script/plugin install again, passing in --force if you need to. For example:
script/plugin install --force git://github.com/dchelimsky/rspec.git
If you already have a static copy of a plugin checked into Subversion, it can be a pain to update it via script/plugin, so here's what I end up doing in order to switch it from a static install to a Git checkout all within one Subversion commit:
git clone git://github.com/foo/bar.git ~/foobar
mv ~/foobar/.git rails_app/vendor/plugins/foobar/.git
rm -rf ~/foobar
cd rails_app/vendor/plugins
git reset --hard
Then make sure to add .git and everything else that has changed to the Subversion project and you will be all up-to-date. You can use other git commands to pull down updates, move to a different branch, etc. Then just check things in again once they are at the state that you want.
One thing I do in this case, I remove the plugin directory then I commit to SVN, this will remove the old plugin in the repo. (I usually moved it in a tmp directory, just in case and delate it later once the new one is working fine)
I then reinstall the new version of the plugin, and commit again.
Easy.
You should just be able to navigate to the plugin's directory and hit:
git pull
. I'm pretty sure that script/install plugin just checks the code out from the git repo.
In order for Git to be able to recognise the repository as a Git repository, you will need to add the .git subdirectory and everything under it to Subversion as well. Otherwise, the plugin will just look like another pile of source code and Git will say it's "Not a Git repository".
Ran into the same situation and used this solution: had paperclip installed as a plugin sitting in an svn repo as part of my app. Now I wanted to use the latest version instead and didnt change a bit of the paperclip plugin so I could easyly remove it from the app/svn and install it as a gem instead. done.

Resources