Tag Archives: repository

How to split a git repository into two

First of all, as a disclaimer: I am not a git guru but. It seems this subject is somehow obscure and it required googling around almost one day. Well, let's get started. I assume that we have the following structure:

repo1.git/
                .git/
                directory1/
                directory2/
                directory3/

and we want:

repo2.git/
                .git/
                directory2/
repo3.git/
                .git/
                directory1/
                directory3/

Please note that only step one will be carried out on server and the rest of them on client.

Step 1. Create two new empty repositories

[codesyntax lang="bash"]

git init --bare repo2.git
git init --bare repo3.git

[/codesyntax]

Step 2. Clone the original repositories

[codesyntax lang="bash"]

git clone --no-hardlinks git@server:repo1.git repo2
git clone --no-hardlinks git@server:repo1.git repo3

[/codesyntax]

Step 3. Filter-branch and reset to exclude other files, so they can be pruned. This step is actually very time consuming. So, depending how large your repository is, you will have to go to buy a coffee or not :)

[codesyntax lang="bash"]

cd repo2/
git filter-branch --subdirectory-filter directory2 HEAD -- --all
git reset --hard
git gc --aggressive
git prune

[/codesyntax]

Step 4. Replace remote origin to point to new repo2.git and push the changes

[codesyntax lang="bash"]

git remote rm origin
git remote add origin git@server:repo2.git
git push origin master

[/codesyntax]

Step 5. Remove directory2/ from the repo3. You finished your coffee? If yes, go and buy another one :)

[codesyntax lang="bash"]

cd ../repo3
git filter-branch --index-filter "git rm -r -f --cached --ignore-unmatch directory2" --prune-empty HEAD
git reset --hard
git gc --aggressive
git prune

[/codesyntax]

Step 6. Replace remote origin to point to new repo3.git and push the changes.

[codesyntax lang="bash"]

git remote rm origin
git remote add origin git@server:repo3.git
git push origin master

[/codesyntax]

How to install mercurial on debian squeeze

This document describes how to install and configure mercurial on linux debian squeeze. With minor changes you can use this procedure on different linux distributions.

1. Install required packages
[codesyntax lang="bash"]

aptitude install mercurial libapache2-mod-wsgi

[/codesyntax]

2. Create repositories directories

mkdir -pv /repositories
chown -R www-data:www-data /repositories
cd /repositories

3. Configure hgweb.cgi script in order to server the repositories via Apache
[codesyntax lang="bash"]

cp /usr/share/doc/mercurial/examples/hgweb.cgi .
chmod a+x hgweb.cgi
vim /repositories/hgweb.cgi
:%s/\/path\/to\/repo\/or\/config/\/repositories\/hgweb.config
:wq

[/codesyntax]

4. Configure hgweb.config

[codesyntax lang="bash"]

vim /repositories/hgweb.config

[/codesyntax]

[collections]
/repositories = /repositories

[codesyntax lang="bash"]

:wq

[/codesyntax]

5. Configure Apache

[codesyntax lang="bash"]

vim /etc/apache2/sites-available/code.domain.com

[/codesyntax]

ServerName code.domain.com
ServerAlias code.domain.com

ScriptAlias /repositories "/repositories/hgweb.cgi"

DocumentRoot /repositories

ErrorLog /var/log/apache2/code.domain.com-error_log
CustomLog /var/log/apache2/code.domain.com-access.log combined
LogLevel warn
ServerSignature Off
[codesyntax lang="bash"]

:wq

[/codesyntax]

6. Restart Apache
[codesyntax lang="bash"]

/etc/init.d/apache2 restart

[/codesyntax]

7. Make a test repository

[codesyntax lang="bash"]

mkdir test
cd test
hg init

[/codesyntax]

8. Enable notify extension

[codesyntax lang="bash"]

vim /etc/mercurial/hgrc.d/hgext.rc
:%s/# hgext.notify/hgext.notify
:wq

[/codesyntax]

9. Configure email notifications for earlier created repository
[codesyntax lang="bash"]

vim /repositories/test/.hg/hgrc

[/codesyntax]

[paths]
default = ssh://root@code.domain.com//repositories/configs
default-push = ssh://root@code.domain.com//repositories/configs
# in case you have ssh on a non standard port then you should use something like that
#default-push = ssh://root@code.domain.com:port//repositories/configs

[extensions]
hgext.notify=

[hooks]
changegroup.notify = python:hgext.notify.hook

[email]
from = mercurial@domain.com

[smtp]
host = domain.com

[web]
baseurl= http://code.domain.com/repositories/

[notify]
sources = serve

test = False
diffstat = False
merge = False

maxdiff = 0

template = Subject: [{webroot|basename}]: {desc|strip|firstline}\n\ndetails: {baseurl}{webroot|basename}/rev/{node|short}\nchangeset: {rev}:{node|short}\nuser: {author}\ndate: {date|date}\ndescription:\n{desc}\n\nfiles changed:\n {files}\n\n\n

[usersubs]
user@example.com = *

[reposubs]
configs = user@example.com
[codesyntax lang="bash"]

:wq

[/codesyntax]

10. Copying some files in the repository
[codesyntax lang="bash"]

rsync -avz /some/files/* .
hg add
hg status
hg commit -m "Added initial files to the repo" -u user
hg push

[/codesyntax]