GiT and RSpec

script/plugin install doesn’t support getting a specific version from
git yet. To do that you have to use ‘git clone’ and then ‘git checkout
1.1.4’ (in this case).

As an alternative to script/plugin or git-clone, you can employ
git-submodules
(on GiT v1.5.3 or later) to obtain the effect of subversion externals.
For
example:

—>

$ git-submodule add
git://github.com/dchelimsky/rspec.git
vendor/plugins/rspec

Initialized empty Git repository in
/home/byrnejb/projects/proforma.git/vendor/plugins/rspec/.git/
remote: Counting objects: 46810, done.
remote: Compressing objects: 100% (10646/10646), done.
remote: Total 46810 (delta 33521), reused 46810 (delta 33521)
Receiving objects: 100% (46810/46810), 5.99 MiB | 103 KiB/s, done.
Resolving deltas: 100% (33521/33521), done.

$ ll vendor/plugins
total 16
drwxrwxr-x 6 byrnejb byrnejb 4096 May 28 14:06 routing_navigator
drwxrwxr-x 12 byrnejb byrnejb 4096 Jun 2 10:09 rspec

$ git-submodule add
git://github.com/dchelimsky/rspec-rails.git
vendor/plugins/rspec-rails

Initialized empty Git repository in
/home/byrnejb/projects/proforma.git/vendor/plugins/rspec-rails/.git/
remote: Counting objects: 46530, done.
remote: Compressing objects: 100% (10649/10649), done.
remote: Total 46530 (delta 33241), reused 46530 (delta 33241)
Receiving objects: 100% (46530/46530), 5.94 MiB | 63 KiB/s, done.
Resolving deltas: 100% (33241/33241), done.

$ git-status

On branch master

Changes to be committed:

(use “git reset HEAD …” to unstage)

modified: .gitmodules

new file: vendor/plugins/rspec

new file: vendor/plugins/rspec-rails

$ git-submodule init

Submodule ‘vendor/plugins/rspec’ (git://github.com/dchelimsky/rspec.git)
registered for path ‘vendor/plugins/rspec’
Submodule ‘vendor/plugins/rspec-rails’
(git://github.com/dchelimsky/rspec-rails.git) registered for path
‘vendor/plugins/rspec-rails’

$ git-status

On branch master

Changes to be committed:

(use “git reset HEAD …” to unstage)

modified: .gitmodules

new file: vendor/plugins/rspec

new file: vendor/plugins/rspec-rails

$ git-commit -m “Added Rspec and Rspec-Rails as submodules”

Created commit b4d1133: Added Rspec and Rspec-Rails as submodules
3 files changed, 8 insertions(+), 0 deletions(-)
create mode 160000 vendor/plugins/rspec
create mode 160000 vendor/plugins/rspec-rails

$ git-status

On branch master

nothing to commit (working directory clean)

$ git-push # over ssh
!!Warning!! - Any attempt to obtain access to this device without
authorization is a criminal act.
[email protected]’s password:
Counting objects: 9, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 607 bytes, done.
Total 5 (delta 1), reused 0 (delta 0)
To
ssh://[email protected]/var/data/vcs-git/hll/proforma.git
ab5353b…b4d1133 master → master

$

<—

Now, when anyone pulls from the canonical repository they will get Rspec
and
Rspec-on-Rails as well, but as submodules pulled directly from the RSpec
repositories. Further, updating all submodules thereafter requires just
these
three steps:

$git-submodule update
$git-commit
$git-push

This is how I load edge rails as well, as a submodule:

$ git-submodule add git://github.com/rails/rails.git vendor/rails
$ git-submodule init
$ git-commit
$ git-push

Once you do this you can locally checkout any version or branch that is
available in the submodule.

Regards,


*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:[email protected]
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3

Hi James,

Thanks for writing these instructions up in detail. I’ve just followed
them
and will play around with them over the next few days. A couple of
questions

  1. I assume with submodules I can create and switch to branches of the
    submodules if I want to try my app out with some patches applied to
    rspec or
    rails? There’s no hidden gotch’ya here?

  2. When I’m getting near deployment for production (a few months away
    yet)
    I’m thinking of freezing to a tagged version of Rails. (Not sure this
    terminology is still correct with Git - but basically I might stick with
    Rails 2.2 or something - but I’m not sure this has benefits anymore).
    How
    would you go about this?

Cheers,

Tim.

I would voice a word of caution on using submodules in Git. Yes, they
are
similar to svn:externals, but in my experience, they are very fragile.
The
fragility comes in when/if you need to switch the submodule
URL/definition
from what it is currently to something else. I’ve had no end of trouble
with this, as have several others.
My current take on Git submodules is that I either don’t use them, or I
fork
whatever it is I’d want as a submodule, and reference my fork as the
submodule. That way, if I need to make changes, switch from someone’s
git
repo of something to someone else’s or whatever, all that is contained
in my
fork, instead of having to switch the submodule in my project.

On Tue, Sep 2, 2008 at 5:49 PM, Tim H. [email protected] wrote:

Hi James,

Thanks for writing these instructions up in detail. I’ve just followed them
and will play around with them over the next few days. A couple of
questions

  1. I assume with submodules I can create and switch to branches of the
    submodules if I want to try my app out with some patches applied to rspec or
    rails? There’s no hidden gotch’ya here?

There is. If you ever run “git submodule init” (and/or update, I
don’t remember) again then it’ll blow away your entire local repo.
Meaning if you’ve made changes that you haven’t pushed, you lose them
all. Suck.

Also, if you’re actually making changes to the child repo, and you’re
working collaboratively, you’re going to be dealing with a bunch of
headaches. Basically, submodules work by git saying
“vendor/plugins/rspec points to commit abc123 from
git://github.com/yourmirror/rspec.git”. If you make changes to the
repo and commit, git will update the reference to the new commit. Now
let’s say one of your coworkers makes a non-conflicting change and
commits…well, now the parent repo has conflicting changes (you say
that the submodule points to foo456 and your coworker says it points
to bar789). You get a conflict in the parent repo, now you have to
resolve it, and you have to do it every single time. This was the
system we originally had when the RSpec repo moved to git and it was a
massive PITA.

Basically, if you want to track remote repos, but you’re not doing
active development on them, submodules work fine. The second you want
to start making changes, submodules are going to be a bitch.

I wrote a gem and some sake tasks to help with this a bit. It’s very
simple but it’s worked beautifully so far for me.
http://github.com/pat-maddox/giternal/tree/master

  1. When I’m getting near deployment for production (a few months away yet)
    I’m thinking of freezing to a tagged version of Rails. (Not sure this
    terminology is still correct with Git - but basically I might stick with
    Rails 2.2 or something - but I’m not sure this has benefits anymore). How
    would you go about this?

Freezing is something that I want to put into giternal but so far
haven’t had a strong enough need to. I might work on it soon just for
the heck of it :slight_smile: The basic idea I have is to flatten the repo…so
you move the .git dir to .git.frozen, add the whole external and
commit. Then to unfreeze you remove the dir from version control
(though without deleting it locally) and move .git.frozen back to
.git. Again, something I want to put in giternal but haven’t done
yet.

Pat