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

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.

Related

Understanding GitHub work flow; what to do after cloning from github?

I am working with RoR, and have recently cloned a project via GitHub. I have a specific RVM gemset for this project, but nothing inside of it. I am not sure if I should create a new branch and then run bundle install, or vice versa. My concern is I do not want to work on the master branch, but I know I need to set up everything first run bundle install.
What is the right method to get started on this project, with out breaking the master?
GitHub is just a hosting for git repositories. Well, writing just is not giving it proper justice.
However you should learn how truly git works. I heartily recommend reading free Git Book.
In short:
git is distributed
you're working only on local working copy
if you don't tell git specifically you want a file to be tracked - it won't (surprise, surprise!).
So running bundle install will not modify what is tracked by git and - specifically - won't affect remote master. It won't modify your master until you modify some files being already tracked. I think bundle install does not. And even then to modify remote master you need to commit and push changes.
You can work on your master. It's safe.
If its someone else's project, or an open-source project, you should Fork the project on Github. Then clone the fork. This will allow you to work on the project, commit your changes locally and push them back to the forked repository.
If it is your own project, and you do indeed want to work in a branch, then clone the repo and make a branch git checkout -b my_branchname. You will then work in the branch, check your code into the branch. Eventually you will want to merge this branch into the master branch. To do this you can merge locally:
git checkout master
git merge my_branchname
Or, you can create a pull request on Github and then merge the branch into master through the Github web UI.
The bundle command, used in conjunction with RVM will just install gems locally, most likely in your home directory (~/.rvm). Gems are not packaged with the rest of the code, so you don't need to fear messing up the master repo.

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.

Git not recognizing rails plugin

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.

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.

Resources