diff --git a/src/gitolite.pm b/src/gitolite.pm index 2c325e2..c7276bd 100644 --- a/src/gitolite.pm +++ b/src/gitolite.pm @@ -9,8 +9,9 @@ # the name of this file will change as soon as its function/feature set # stabilises enough ;-) -# right now all it does is define a function that tells you where to find the -# rc file +# right now all it does is +# - 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? @@ -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; diff --git a/src/gl-auth-command b/src/gl-auth-command index 31d1fa8..a135be6 100755 --- a/src/gl-auth-command +++ b/src/gl-auth-command @@ -100,6 +100,15 @@ die "$perm access for $repo DENIED to $user\n" unless $repos{$repo}{$perm}{$user} 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 # ---------------------------------------------------------------------------- diff --git a/src/gl-compile-conf b/src/gl-compile-conf index 6ca9b9b..583a3f0 100755 --- a/src/gl-compile-conf +++ b/src/gl-compile-conf @@ -52,12 +52,7 @@ $Data::Dumper::Sortkeys = 1; 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); - -# 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 "; +our ($ABRT, $WARN); # the common setup module is in the same directory as this running program is my $bindir = $0; @@ -118,16 +113,6 @@ umask($REPO_UMASK); # 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 { 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+)/); 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" -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" . "\tyour git version is older than 1.6.2\n" . "\tgitolite will work but you MUST read the section on\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 @@ -363,6 +328,10 @@ warn "\n\t\t***** WARNING *****\n" . # :-) These are now "pseduo users" -- giving them "R" access to a repo is all # 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"); # daemons first... diff --git a/src/gl-easy-install b/src/gl-easy-install index c577307..cf3a859 100755 --- a/src/gl-easy-install +++ b/src/gl-easy-install @@ -398,6 +398,7 @@ setup_pta() { # Substitute $GL_ADMINDIR and $REPO_BASE appropriately. Note there is no # space around the "=" in the second and third lines. + git ls-remote gitolite:gitolite-admin echo "cd $REPO_BASE/gitolite-admin.git 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