new repo autovivified now

Merge branch 'pu'
This commit is contained in:
Sitaram Chamarty 2009-11-28 17:42:55 +05:30
commit 81911b77cc
4 changed files with 47 additions and 39 deletions

View file

@ -9,8 +9,9 @@
# the name of this file will change as soon as its function/feature set # the name of this file will change as soon as its function/feature set
# stabilises enough ;-) # stabilises enough ;-)
# right now all it does is define a function that tells you where to find the # right now all it does is
# rc file # - define a function that tells you where to find the rc file
# - define a function that creates a new repo and give it our update hook
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# where is the rc file hiding? # where is the rc file hiding?
@ -42,4 +43,32 @@ sub where_is_rc
} }
} }
$ABRT = "\n\t\t***** ABORTING *****\n ";
$WARN = "\n\t\t***** WARNING *****\n ";
sub wrap_chdir {
chdir($_[0]) or die "$ABRT chdir $_[0] failed: $! at ", (caller)[1], " line ", (caller)[2], "\n";
}
sub wrap_open {
open (my $fh, $_[0], $_[1]) or die "$ABRT open $_[1] failed: $! at ", (caller)[1], " line ", (caller)[2], "\n" .
( $_[2] || '' ); # suffix custom error message if given
return $fh;
}
# NOTE: this sub will change your cwd; caller beware!
sub new_repo
{
my ($repo, $hooks_dir) = @_;
umask($REPO_UMASK);
system("mkdir", "-p", "$repo.git") and die "$ABRT mkdir $repo.git failed: $!\n";
# erm, note that's "and die" not "or die" as is normal in perl
wrap_chdir("$repo.git");
system("git --bare init >&2");
# propagate our own, plus any local admin-defined, hooks
system("cp $hooks_dir/* hooks/");
chmod 0755, "hooks/update";
}
1; 1;

View file

@ -100,6 +100,15 @@ die "$perm access for $repo DENIED to $user\n"
unless $repos{$repo}{$perm}{$user} unless $repos{$repo}{$perm}{$user}
or $repos{$repo}{$perm}{'@all'}; or $repos{$repo}{$perm}{'@all'};
# create the repo if it doesn't already exist and the user has "W" access
my $repo_base_abs = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" );
if ( ( $repos{$repo}{W}{$user}
or $repos{$repo}{W}{'@all'} ) and not -d "$repo_base_abs/$repo.git" ) {
wrap_chdir("$repo_base_abs");
new_repo($repo, "$GL_ADMINDIR/src/hooks");
wrap_chdir($ENV{HOME});
}
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# logging, timestamp. also setup env vars for later # logging, timestamp. also setup env vars for later
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------

View file

@ -52,12 +52,7 @@ $Data::Dumper::Sortkeys = 1;
open STDOUT, ">", "/dev/null" if (@ARGV and shift eq '-q'); open STDOUT, ">", "/dev/null" if (@ARGV and shift eq '-q');
our ($GL_ADMINDIR, $GL_CONF, $GL_KEYDIR, $GL_CONF_COMPILED, $REPO_BASE, $REPO_UMASK, $PROJECTS_LIST, $GIT_PATH); our ($GL_ADMINDIR, $GL_CONF, $GL_KEYDIR, $GL_CONF_COMPILED, $REPO_BASE, $REPO_UMASK, $PROJECTS_LIST, $GIT_PATH);
our ($ABRT, $WARN);
# now that this thing *may* be run via "push to admin", any errors have to
# grab the admin's ATTENTION so he won't miss them among the other messages a
# typical push generates
my $ABRT = "\n\t\t***** ABORTING *****\n ";
my $WARN = "\n\t\t***** WARNING *****\n ";
# the common setup module is in the same directory as this running program is # the common setup module is in the same directory as this running program is
my $bindir = $0; my $bindir = $0;
@ -118,16 +113,6 @@ umask($REPO_UMASK);
# subroutines # subroutines
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
sub wrap_chdir {
chdir($_[0]) or die "$ABRT chdir $_[0] failed: $! at ", (caller)[1], " line ", (caller)[2], "\n";
}
sub wrap_open {
open (my $fh, $_[0], $_[1]) or die "$ABRT open $_[1] failed: $! at ", (caller)[1], " line ", (caller)[2], "\n" .
( $_[2] || '' ); # suffix custom error message if given
return $fh;
}
sub expand_list sub expand_list
{ {
my @list = @_; my @list = @_;
@ -327,32 +312,12 @@ my $git_version = `git --version`;
my ($gv_maj, $gv_min, $gv_patchrel) = ($git_version =~ m/git version (\d+)\.(\d+)\.(\d+)/); my ($gv_maj, $gv_min, $gv_patchrel) = ($git_version =~ m/git version (\d+)\.(\d+)\.(\d+)/);
die "$ABRT I can't understand $git_version\n" unless ($gv_maj >= 1); die "$ABRT I can't understand $git_version\n" unless ($gv_maj >= 1);
$git_version = $gv_maj*10000 + $gv_min*100 + $gv_patchrel; # now it's "normalised" $git_version = $gv_maj*10000 + $gv_min*100 + $gv_patchrel; # now it's "normalised"
my $git_too_old = 0;
# repo-base needs to be an absolute path for this loop to work right
# so if it was not already absolute, prefix $HOME.
my $repo_base_abs = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" );
wrap_chdir("$repo_base_abs");
for my $repo (keys %repos)
{
unless (-d "$repo.git")
{
system("mkdir", "-p", "$repo.git") and die "$ABRT mkdir $repo.git failed: $!\n";
# erm, note that's "and die" not "or die" as is normal in perl
wrap_chdir("$repo.git");
system("git --bare init");
# propagate our own, plus any local admin-defined, hooks
system("cp $GL_ADMINDIR/src/hooks/* hooks/");
chmod 0755, "hooks/update";
wrap_chdir("$repo_base_abs");
$git_too_old++ if $git_version < 10602; # that's 1.6.2 to you
}
}
warn "\n\t\t***** WARNING *****\n" . warn "\n\t\t***** WARNING *****\n" .
"\tyour git version is older than 1.6.2\n" . "\tyour git version is older than 1.6.2\n" .
"\tgitolite will work but you MUST read the section on\n" . "\tgitolite will work but you MUST read the section on\n" .
"\t\"git version dependency\" in doc/3-faq-tips-etc.mkd\n" "\t\"git version dependency\" in doc/3-faq-tips-etc.mkd\n"
if $git_too_old; if $git_version < 10602; # that's 1.6.2 to you
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# handle gitweb and daemon # handle gitweb and daemon
@ -363,6 +328,10 @@ warn "\n\t\t***** WARNING *****\n" .
# :-) These are now "pseduo users" -- giving them "R" access to a repo is all # :-) These are now "pseduo users" -- giving them "R" access to a repo is all
# you have to do # you have to do
# repo-base needs to be an absolute path for this loop to work right
# so if it was not already absolute, prefix $HOME.
my $repo_base_abs = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" );
wrap_chdir("$repo_base_abs"); wrap_chdir("$repo_base_abs");
# daemons first... # daemons first...

View file

@ -398,6 +398,7 @@ setup_pta() {
# Substitute $GL_ADMINDIR and $REPO_BASE appropriately. Note there is no # Substitute $GL_ADMINDIR and $REPO_BASE appropriately. Note there is no
# space around the "=" in the second and third lines. # space around the "=" in the second and third lines.
git ls-remote gitolite:gitolite-admin
echo "cd $REPO_BASE/gitolite-admin.git echo "cd $REPO_BASE/gitolite-admin.git
GIT_WORK_TREE=$GL_ADMINDIR git add conf/gitolite.conf keydir GIT_WORK_TREE=$GL_ADMINDIR git add conf/gitolite.conf keydir
GIT_WORK_TREE=$GL_ADMINDIR git diff --cached --quiet || GIT_WORK_TREE=$GL_ADMINDIR git commit -am start GIT_WORK_TREE=$GL_ADMINDIR git diff --cached --quiet || GIT_WORK_TREE=$GL_ADMINDIR git commit -am start