Wednesday, March 3, 2010

git submodule moving

how do you update a git submodule? say the submodule used to be at gitosis@example.com:submodule_a.git, but the developers switched hosts and now it's at gitosis@example.net:submodule_a.git. turns out all you have to do is change .git/config.

in superproject/.git/config


before:
[submodule "submodule_a"]
url = gitosis@example.com:submodule_a.git

after:
[submodule "submodule_a"]
url = gitosis@example.net:submodule_a.git


now git submodule update will use example.net instead of example.com. but that doesn't change the content of the repository, just the configuration for your local copy of the superproject. if someone clones your repo, they'll try to reach the submodule at gitosis@example.com:submodule_a.git. to avoid this, update .gitmodules to point at the new location as well.

in superproject/.gitmodules


before:
[submodule "submodule_a"]
path = submodule_a
url = gitosis@example.com:submodule_a.git

after:
[submodule "submodule_a"]
path = submodule_a
url = gitosis@example.net:submodule_a.git

when git submodule init reads the .gitmodules file (in a newly cloned repo), it will get the new location for the submodule and setup the .git/config file accordingly.

helpful, but not what i wanted


places i went looking for this info, but didn't find it:
http://book.git-scm.com/5_submodules.html
http://progit.org/book/ch6-6.html
http://pitupepito.homelinux.org/?p=24
http://gaarai.com/2009/04/20/git-submodules-adding-using-removing-and-updating/
http://www.hackido.com/2009/01/quick-tip-remove-git-submodule.html

Tuesday, March 2, 2010

gitosis on ubuntu karmic 9.10

quickstart


as some_user@example.com:


on the server that will host the git repos,

sudo aptitude install gitosis
sudo -H -u gitosis gitosis-init < ~/.ssh/id_rsa.pub
git clone gitosis@localhost:gitosis-admin.git
cd gitosis-admin
scp newuser@example.net:.ssh/id_rsa.pub keydir/newuser@example.net.pub
vim gitosis.conf #:tabnew /usr/share/doc/gitosis/examples/example.conf
#add newuser@example.net to project_foo_group, make project_foo writable, close
git add .
git ci -m "add newuser@example.net to project_foo_group, make project_foo writable"
git push origin master

example gitosis.conf pushed back to gitosis-admin.git:

[gitosis]

[group gitosis-admin]
writable = gitosis-admin
members = some_user@example.com

[group project_foo_group]
members = some_user@example.com new_user@example.net
writable = project_foo

then as newuser at example.net:



cd project_foo
git remote add origin gitosis@example.com:project_foo.git
git push origin master

again, but cluttered with explanations


as some_user@example.com


sudo aptitude install gitosis
turns out there's a gitosis package in ubuntu. but it was unclear what installing it did. after reading some docs, such as /usr/share/doc/gitosis/README.rst.gz (installed with the gitosis package) and a blog post about hosting git, i was ready to guess. i found that the gitosis user had already been set up. finding its home directory was a matter of sudo su gitosis -;cd;pwd. this let me know first, that there was indeed a user named gitosis and second, that its home directory was at /srv/gitosis. this turns out to be irrelevant because the gitosis package already knows this. that directory was empty, iirc. so i guessed that i needed to pick up at gitosis-init.

sudo -H -u gitosis gitosis-init < ~/.ssh/id_rsa.pub

tell gitosis whom to trust for its administration. make the user gitosis run gitosis-init and give it the public key of whomever will admin the gitosis server (in this case it's the public rsa key of the current user). gitosis-init takes care of putting this file in the right place with the right name(/srv/gitosis/repositories/gitosis-admin.git/gitosis-export/keydir/some_user@example.com.pub). the exact place doesn't matter. it just matters that gitosis knows about it and will refer to it to verify requests, like cloning:

git clone gitosis@localhost:gitosis-admin.git

the current user (some_user@example.com) wants to clone from the user gitosis at localhost the gitosis-admin git repository. the user gitosis sees this request and needs to verify that it should fulfill that request. it uses the key (some_user@example.com.pub) that was just set up in the gitosis-init step. ssh magic happens here. the user gitosis trusts the incoming request and pushes out the repository to the requester, some_user@example.com. now some_user@example.com can modify the repository and write it back (all of these permissions and configurations are set up by gitosis-init.

cd gitosis-admin

when you clone the repo, its contents are put into a folder in the current directory, so go into it.

scp newuser@example.net:.ssh/id_rsa.pub keydir/newuser@example.net.pub

copy yet another public key into the key directory. this is the public key of newuser at example.net. copy it to the directory keydir with the filename user@host.pub. gitosis knows to look in this directory for files named like this for the public key.

vim gitosis.conf #:tabnew /usr/share/doc/gitosis/examples/example.conf
#add newuser@example.net to project_foo_group, make project_foo writable, close

modify gitosis.conf to add the relevant sections. scroll up a bit to see gitosis.conf. there is an example configuration at the location specified. in my example i create a group called new_project_group for the repository new_project. it says that the users some_user@example.com and newuser@example.net can write (which implies read and write) to the project new_project.

git add .
git ci -m "add newuser@example.net to project_foo_group, make project_foo writable"

save those changes! the public key and the configuration change! very important. but remember, this is just saving locally. you haven't told anyone else about this.

git push origin master

put those changes back up to the repository that gitosis@example.com knows about! gitosis will check its current configuration and see that it accepts changes from some_user@example.com to the gitosis-admin.git repository. gitosis has some kind of hook magic going on here. i'm not sure if it's a post-commit, or post-applypatch or what. but something black box happens here. the result of the black box is that changes you just pushed back to the gitosis-admin repo are now reflected by gitosis@example.com. it now knows about a new_project_group group, and the public key of newuser@example.net (for more ssh magic), and about the new_project repository.

as newuser@example.net


so now that the server has been set up and configured and doodadded, it's time to go put some content in it, other than the content that determines the configuration and the doodadding.

cd project_foo

newuser@example.net already has a project with some commits in it. so go into that directory.

git remote add origin gitosis@example.com:project_foo.git

tell that git repo about the new git server! gitosis on example.com knows about the project_foo git repo from the configuration file pushed to it earlier.

git push origin master

and the finish! this will push the master branch to the location nicknamed origin. origin is the nickname for gitosis@example.com:new_project.git. gitosis receives this request, does more ssh magic by looking at the public key pushed in gitosis-admin/keydir/newuser@example.net.pub. hooray! gitosis@example.com will see that the repo doesn't already exist, and accept the push, creating and populating the repo in one swoop! hooray!

Where am I?