Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1177239
  • 博文数量: 312
  • 博客积分: 12522
  • 博客等级: 上将
  • 技术积分: 3376
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-27 18:35
文章分类

全部博文(312)

文章存档

2016年(3)

2015年(1)

2013年(1)

2012年(28)

2011年(101)

2010年(72)

2009年(13)

2008年(93)

分类: 项目管理

2011-03-31 17:39:12

Introduction

目录

is an open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Branching and merging are fast and easy to do.

Installation

Before starting, make sure that:

* You already have a Ubuntu 9.04 or Ubuntu 10.04 installed on you computer/server.

* You already have a public ssh key on your local machine you can use that to initialize the repository. Don't have one? .

* You have customised an editor by setting the environment variable EDITOR to your favourite editor.

The following instructions will guide you on how to set up and run a fully managed hosting for projects using git on your server.

Choose an Editor

You may have a favourite text editor that you like to use, so you'll need to specify it by exporting the EDITOR environment variable with the name of the editor binary.

This example sets vim as the editor for use throughout this guide.

ie :

export EDITOR=vim

If you want to use another like nano, pico or gedit then you replace vim with either nano,pico or gedit. Remember gedit (and other Desktop editors like it) requires a valid Xserver display to be available.

Used software

This tutorial was done using Ubuntu 9.04 (Jaunty Jackalope), Ubuntu 10.04 (Lucid Lynx).

We'll be using the latest package available in the archive.

For git project management will be using .

For repository web browsing we will be using . The latest version we will clone directly from a git repository: git clone git://repo.or.cz/viewgit.git

Setting up Git and Project Management

Use your favorite package installer to install git-core and gitosis packages:

sudo apt-get -y install git-core gitosis

Installing the gitosis package will create the user gitosis and the home directory for it at /srv/gitosis which will contain the repositories and configuration information.

Now that you should have both packages installed and a gitosis user, we can set up gitosis.

Initialize gitosis using your key:

sudo -H -u gitosis gitosis-init < initialKeyFileName

where initialKeyFileName name is the name of a copy of the public key from your local machine which is on the server.

If you saw some output like this: Initialized empty Git repository in ./ Your gitosis is installed.

Once done, you can now checkout the gitosis-admin branch on your local machine:

git clone gitosis@yourserver.com:gitosis-admin.git

...but replace yourserver.com with the actual name of your server. Note that gitosis is an account already on your system that was created when you installed the gitosis package.

(If the cloning doesn't work, maybe you have PermitRootLogin no in the SSH server, and you need to add gitosis user to it.)

sudo $EDITOR /etc/ssh/sshd_config
AllowUsers gitosis

Use your favorite editor to modify the contents of the gitosis configuration file on your local machine (changes will be pushed back to server in next step):

cd gitosis-admin
$EDITOR gitosis.conf

Adding a new project to the repository

Here is an example of the gitosis configuration file you cloned before. Here it contains the default gitosis entry, and a new project entry:

[gitosis]

[group team]
writable = testproject
members = keyfilename

[group gitosis-admin]
writable = gitosis-admin
members = keyfilename

keyfilename is the name of the public key without .pub extension. This is the name of the key in the file initialKeyFileName which was used in the gitosis-init command above. It will appear as a file in the keydir with the .pub extension, so you can check it there.

After you're done editing, save the file, and commit it back to the server.

git commit -a -m "Added a new project"
git push

Any future projects will be added the same way.

Committing to the first project

To commit the project you just created, initiate a new git project, add files to it, commit it, then push it to your repository with the name you set up in gitosis config file.

mkdir testproject
cd testproject
git init
touch a_text_file.txt
git add .
git commit -a -m "Initial import"
git remote add origin gitosis@yourserver.com:testproject.git
git push origin master

The project should be committed!

{i} If not, please check your /srv/gitosis/.ssh/authorized_keys file, if that one contains your correct public key!

Adding users

First, gather their public SSH keys, which I'll call "kakashi.pub" and "naruto.pub", and drop them into keydir/ of your local gitosis-admin repository. Second, edit gitosis.conf and add them to the "members" list.

cd gitosis-admin
cp ~/kakashi.pub keydir/
cp ~/naruto.pub keydir/
git add keydir/kakashi.pub keydir/naruto.pub

Note that the key filename must have a ".pub" extension.

gitosis.conf changes:

 [group team]
writable = testproject
- members = hostname.yourserver.com
+ members = hostname.yourserver.com kakashi naruto

Commit and push:

git commit -a -m "Granted Kakashi and Naruto commit rights to testproject"
git push

That's it. Kakashi and Naruto can now clone the testproject repository like so:

git clone gitosis@yourserver.com:testproject.git

Kakashi and Naruto will also have commit rights.

The web browsing interface

Server will need a web server so I recommend you to install Apache with support for php. Once ViewGit can be linked to GeSHI, I also recommend you installing the php-geshi package:

sudo apt-get install apache2 libapache2-mod-php5 php-geshi

{i} For more extended Apache installation we recommend you reading a dedicated page like this .

Once done, /var/www/ directory will be created. Go there and clone the latest git version of !ViewGIT:

cd /var/www
sudo git clone git://repo.or.cz/viewgit.git
sudo chown -vR www-data:www-data viewgit

After finishing this operation, use your favorite editor to edit the config file for ViewGit:

cd /var/www/viewgit/inc
sudo cp config.php localconfig.php
sudo chown www-data:www-data localconfig.php
sudo $EDITOR localconfig.php

What follows is an example of the ViewGit localconfig.php with !GeSHI and the testproject.git we created.

Although there are two things to note :

* $conf['projects'] will be an array that you explicitly define repositories that viewgit will display. * $conf['projects_glob'] is an array of file-system path patterns that gitweb will use to search for *.git directories. This provides easier inclusion of all your repositories (although it may ignore any gitweb directives in your gitosis.conf)

Both $conf['projects'] and $conf['projects_glob'] will be used to decide what projects to display. So in the following example if you actually created the testproject example in the previous steps, it will show up twice.

$conf['projects'] = array(
'testproject' => array('repo' => '/srv/gitosis/repositories/testproject.git/'),
);
// If set, contains an array of globs/wildcards where to include projects.
// Use this if you have a lot of projects under a directory.
$conf['projects_glob'] = array('/srv/gitosis/repositories/*.git');

// Where git is. Default is to search from PATH, but you can use an absolute
// path as well.
$conf['git'] = 'git';

$conf['datetime'] = '%Y-%m-%d %H:%M';

// More complete format for commit page
$conf['datetime_full'] = '%Y-%m-%d %H:%M:%S';

// Maximum length of commit message's first line to show
$conf['commit_message_maxlen'] = 50;

// Maximum number of shortlog entries to show on the summary page
$conf['summary_shortlog'] = 30;

// Maximum number of tags to show on the summary page
$conf['summary_tags'] = 10;

// Whether to show remote labels on shortlog
$conf['shortlog_remote_labels'] = false;

// Allow checking out projects via "git clone"
$conf['allow_checkout'] = true;

// If set, this function is used to obfuscate e-mail addresses of authors/committers
// The 'obfuscate_mail' function simply replaces @ with ' at ' and . with ' dot '
//$conf['mail_filter'] = 'obfuscate_mail';
//$conf['mail_filter'] = create_function('$mail', 'return str_rot13(strtoupper($mail));');

// Whether to use GeSHi for source highlighting
$conf['geshi'] = true;

// Path to geshi.php
$conf['geshi_path'] = 'inc/geshi/geshi.php';
$conf['geshi_path'] = '/usr/share/php-geshi/geshi.php'; // Path on Debian

// Use line numbers in geshi?
// Setting this to "false" disables line numbers
// Using a value of 0 will enable "NORMAL" geshi line numbers
// Using values of 1 or more will enable "FANCY" geshi line numbers
$conf['geshi_line_numbers'] = 5;

// RSS time to live (how often clients should update the feed), in minutes.
$conf['rss_ttl'] = 10;

// RSS: Maximum number of items in feed
$conf['rss_max_items'] = 30;

// RSS item format. Allowed formatting:
// {AUTHOR}, {AUTHOR_MAIL}, {SHORTLOG}, {LOG}, {COMMITTER}, {COMMITTER_MAIL}, {DIFFSTAT}
$conf['rss_item_title'] = '{SHORTLOG} ({AUTHOR})';
$conf['rss_item_description'] = '
{LOG}
{AUTHOR} <{AUTHOR_MAIL}>
{DIFFSTAT}
';

$conf['debug'] = false;

// Includes a small link to the ViewGit homepage on each page
$conf['ad'] = false;

Now you should be able to browse your Git repository by going to if you got problems on accessing repositories, add your web server user to the same group gitosis user is:

adduser www-data git

Making available public cloning of the projects

To make available public access for cloning of the projects, you have to set up git-daemon. git-daemon is a service which runs on port 9418 and handles public requests for project cloning. git-daemon comes together with git-core so no additional installation is required.

To make this service easier to administrate, here is an init script to start and stop the daemon.

It is, however, easier to make git a subservice of xinetd, by editing /etc/xinetd.d/git and changing disable=no}} to {{{disable=yes.

Create the git-daemon init script

sudo $EDITOR /etc/init.d/git-daemon

paste the following

# Taken from here: 

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=git-daemon
PIDFILE=/var/run/$NAME.pid
DESC="the git daemon"
DAEMON=/usr/lib/git-core/git-daemon
DAEMON_OPTS="--base-path=/srv/gitosis/repositories --export-all --verbose --syslog --detach --pid-file=$PIDFILE --user=gitosis --group=nogroup"

test -x $DAEMON || exit 0

[ -r /etc/default/git-daemon ] && . /etc/default/git-daemon

. /lib/lsb/init-functions

start_git() {
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--startas $DAEMON -- $DAEMON_OPTS
}

stop_git() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE
rm -f $PIDFILE
}

status_git() {
start-stop-daemon --stop --test --quiet --pidfile $PIDFILE >/dev/null 2>&1
}

case "$1" in
start)
log_begin_msg "Starting $DESC"
start_git
log_end_msg 0
;;
stop)
log_begin_msg "Stopping $DESC"
stop_git
log_end_msg 0
;;
status)
log_begin_msg "Testing $DESC: "
if status_git
then
log_success_msg "Running"
exit 0
else
log_failure_msg "Not running"
exit 1
fi
;;
restart|force-reload)
log_begin_msg "Restarting $DESC"
stop_git
sleep 1
start_git
log_end_msg 0
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac

exit 0

To make it usable, and make possible it's automatic startup on server boot change its permissions and update-rc.d

sudo chmod +x /etc/init.d/git-daemon
sudo update-rc.d git-daemon defaults

The daemon can be controlled in the following manner :

Pre Karmic :

sudo /etc/init.d/git-daemon start
sudo /etc/init.d/git-daemon stop
sudo /etc/init.d/git-daemon restart
sudo /etc/init.d/git-daemon force-reload

Ubuntu 9.10 and later :

sudo service git-daemon start
sudo service git-daemon stop
sudo service git-daemon restart
sudo service git-daemon force-reload
阅读(1059) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~