From 379b0c9549faa2699d49da22fe49d3048e12f0a1 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Sat, 10 Mar 2012 18:56:29 +0530 Subject: [PATCH] install/test made easy (WARNING: read below) (1) testing is very easy, just run this from a clone t/g3-clean-install-setup-test BUT BE WARNED THIS IS DESTRUCTIVE; details in t/WARNING (2) install is equally simple; see 'INSTALL' in the main directory --- Gitolite/Rc.pm | 177 ------------------ INSTALL | 17 ++ g3-info | 35 ---- g3-install | 20 -- gitolite | 95 ---------- {Gitolite => src/Gitolite}/Common.pm | 15 +- {Gitolite => src/Gitolite}/Conf.pm | 1 - {Gitolite => src/Gitolite}/Conf/Explode.pm | 1 - {Gitolite => src/Gitolite}/Conf/Load.pm | 3 +- {Gitolite => src/Gitolite}/Conf/Store.pm | 3 +- {Gitolite => src/Gitolite}/Conf/Sugar.pm | 1 - .../Gitolite}/Hooks/PostUpdate.pm | 3 +- {Gitolite => src/Gitolite}/Hooks/Update.pm | 1 - src/Gitolite/Rc.pm | 113 ++++------- {Gitolite => src/Gitolite}/Setup.pm | 7 +- {Gitolite => src/Gitolite}/Test.pm | 12 +- {Gitolite => src/Gitolite}/Test/Tsh.pm | 0 src/gitolite | 117 ++++++------ gitolite-shell => src/gitolite-shell | 6 +- t/README | 8 + t/{t01-basic => basic.t} | 2 +- t/gitolite-receive-pack | 2 +- t/gitolite-upload-pack | 2 +- t/glt | 7 +- t/reset | 8 + 25 files changed, 162 insertions(+), 494 deletions(-) delete mode 100644 Gitolite/Rc.pm create mode 100644 INSTALL delete mode 100755 g3-info delete mode 100755 g3-install delete mode 100755 gitolite rename {Gitolite => src/Gitolite}/Common.pm (92%) rename {Gitolite => src/Gitolite}/Conf.pm (98%) rename {Gitolite => src/Gitolite}/Conf/Explode.pm (99%) rename {Gitolite => src/Gitolite}/Conf/Load.pm (99%) rename {Gitolite => src/Gitolite}/Conf/Store.pm (99%) rename {Gitolite => src/Gitolite}/Conf/Sugar.pm (99%) rename {Gitolite => src/Gitolite}/Hooks/PostUpdate.pm (94%) rename {Gitolite => src/Gitolite}/Hooks/Update.pm (99%) rename {Gitolite => src/Gitolite}/Setup.pm (96%) rename {Gitolite => src/Gitolite}/Test.pm (70%) rename {Gitolite => src/Gitolite}/Test/Tsh.pm (100%) rename gitolite-shell => src/gitolite-shell (93%) create mode 100644 t/README rename t/{t01-basic => basic.t} (99%) create mode 100755 t/reset diff --git a/Gitolite/Rc.pm b/Gitolite/Rc.pm deleted file mode 100644 index 47f0cdb..0000000 --- a/Gitolite/Rc.pm +++ /dev/null @@ -1,177 +0,0 @@ -package Gitolite::Rc; - -# everything to do with 'rc'. Also defines some 'constants' -# ---------------------------------------------------------------------- - -@EXPORT = qw( - %rc - glrc - query_rc - - $ADC_CMD_ARGS_PATT - $REF_OR_FILENAME_PATT - $REPONAME_PATT - $REPOPATT_PATT - $USERNAME_PATT -); - -use Exporter 'import'; -use Getopt::Long; - -use lib $ENV{GL_BINDIR}; -use Gitolite::Common; - -# ---------------------------------------------------------------------- - -our %rc; - -# ---------------------------------------------------------------------- - -# variables that are/could be/should be in the rc file -# ---------------------------------------------------------------------- - -$rc{GL_ADMIN_BASE} = "$ENV{HOME}/.gitolite"; -$rc{GL_REPO_BASE} = "$ENV{HOME}/repositories"; - -# variables that should probably never be changed -# ---------------------------------------------------------------------- - -$ADC_CMD_ARGS_PATT = qr(^[0-9a-zA-Z._\@/+:-]*$); -$REF_OR_FILENAME_PATT = qr(^[0-9a-zA-Z][0-9a-zA-Z._\@/+ :,-]*$); -$REPONAME_PATT = qr(^\@?[0-9a-zA-Z][0-9a-zA-Z._\@/+-]*$); -$REPOPATT_PATT = qr(^\@?[0-9a-zA-Z[][\\^.$|()[\]*+?{}0-9a-zA-Z._\@/,-]*$); -$USERNAME_PATT = qr(^\@?[0-9a-zA-Z][0-9a-zA-Z._\@+-]*$); - -# ---------------------------------------------------------------------- - -my $current_data_version = "3.0"; - -my $rc = glrc('filename'); -do $rc if -r $rc; -# let values specified in rc file override our internal ones -@rc{ keys %RC } = values %RC; - -# ---------------------------------------------------------------------- - -use strict; -use warnings; - -# ---------------------------------------------------------------------- - -my $glrc_default_text = ''; -{ - local $/ = undef; - $glrc_default_text = ; -} - -sub glrc { - my $cmd = shift; - if ( $cmd eq 'default-filename' ) { - trace( 1, "..should happen only on first run" ); - return "$ENV{HOME}/.gitolite.rc"; - } elsif ( $cmd eq 'default-text' ) { - trace( 1, "..should happen only on first run" ); - return $glrc_default_text if $glrc_default_text; - _die "rc file default text not set; this should not happen!"; - } elsif ( $cmd eq 'filename' ) { - # where is the rc file? - trace(4); - - # search $HOME first - return "$ENV{HOME}/.gitolite.rc" if -f "$ENV{HOME}/.gitolite.rc"; - trace( 2, "$ENV{HOME}/.gitolite.rc not found" ); - - # XXX for fedora, we can add the following line, but I would really prefer - # if ~/.gitolite.rc on each $HOME was just a symlink to /etc/gitolite.rc - # XXX return "/etc/gitolite.rc" if -f "/etc/gitolite.rc"; - - return ''; - } elsif ( $cmd eq 'current-data-version' ) { - return $current_data_version; - } else { - _die "unknown argument to glrc: $cmd"; - } -} - -# ---------------------------------------------------------------------- -# implements 'gitolite query-rc' -# ---------------------------------------------------------------------- - -=for usage - -Usage: gitolite query-rc -a - gitolite query-rc - -Example: - - gitolite query-rc GL_ADMIN_BASE GL_UMASK - # prints "/home/git/.gitolite0077" or similar - - gitolite query-rc -a - # prints all known variables and values, one per line -=cut - -# ---------------------------------------------------------------------- - -my $all = 0; - -sub query_rc { - trace( 1, "rc file not found; default should be " . glrc('default-filename') ) if not glrc('filename'); - - my @vars = args(); - - no strict 'refs'; - - if ( $vars[0] eq '-a' ) { - for my $e (sort keys %rc) { - print "$e=" . ( defined($rc{$e}) ? $rc{$e} : 'undef' ) . "\n"; - } - return; - } - - our $GL_BINDIR = $ENV{GL_BINDIR}; - - print join( "\t", map { $rc{$_} } @vars ) . "\n" if @vars; -} - -# ---------------------------------------------------------------------- - -sub args { - my $help = 0; - - GetOptions( - 'all|a' => \$all, - 'help|h' => \$help, - ) or usage(); - - usage("'-a' cannot be combined with other arguments") if $all and @ARGV; - return '-a' if $all; - usage() if not @ARGV or $help; - return @ARGV; -} - -1; - -# ---------------------------------------------------------------------- - -__DATA__ -# configuration variables for gitolite - -# PLEASE READ THE DOCUMENTATION BEFORE EDITING OR ASKING QUESTIONS - -# this file is in perl syntax. However, you do NOT need to know perl to edit -# it; it should be fairly self-explanatory and easy to maintain - -%RC = ( - GL_UMASK => 0077, - GL_GITCONFIG_KEYS => "", -); - -# ------------------------------------------------------------------------------ -# per perl rules, this should be the last line in such a file: -1; - -# Local variables: -# mode: perl -# End: -# vim: set syn=perl: diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..b1c634d --- /dev/null +++ b/INSTALL @@ -0,0 +1,17 @@ +1. Clone the repo and copy src somewhere (or leave it where it is, if you're + sure no one will 'git pull' on a running system!) + + cp -a src /some/full/path + +2. (Optional) Make a symlink for the single executable 'gitolite' to + somewhere in `$PATH` + + ln -sf /full/path/to/some/damn/place/gitolite $HOME/bin + +3. Run setup. That is, either run: + + gitolite setup -a YourName -pk /tmp/YourName.pub + + or, if you did not do step 2, run: + + /some/full/path/src/gitolite -a YourName -pk /tmp/YourName.pub diff --git a/g3-info b/g3-info deleted file mode 100755 index 28fa9ad..0000000 --- a/g3-info +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/perl - -# gitolite shell, invoked from ~/.ssh/authorized_keys -# ---------------------------------------------------------------------- - -BEGIN { - # find and set bin dir - $ENV{GL_BINDIR} = "$ENV{HOME}/bin"; -} - -use lib $ENV{GL_BINDIR}; -use Gitolite::Rc; -use Gitolite::Common; -use Gitolite::Conf::Load; - -use strict; -use warnings; - -# ---------------------------------------------------------------------- - -my $user = shift or die; -my $aa; -my $ref = 'any'; - -my $ret; -while (<>) { - chomp; - - my $perm = ''; - for $aa (qw(R W C)) { - $ret = access($_, $user, $aa, $ref); - $perm .= ( $ret =~ /DENIED/ ? " " : " $aa" ); - } - print "$perm\t$_\n" if $perm =~ /\S/; -} diff --git a/g3-install b/g3-install deleted file mode 100755 index ef40012..0000000 --- a/g3-install +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# this is specific to my test env; you may want to change it - -set -e - -cd /home/g3 - -if [ "$1" = "-c" ] -then - rm -rf .gito* gito* repositories proj* bin - mkdir bin - cp ~/.ssh/id_rsa.pub ~/.ssh/admin.pub - - cd g3; cp -a gito* Gito* t/glt t/gito* ~/bin - gitolite setup -a ${2:-admin} -pk ~/.ssh/admin.pub -else - cd g3; cp -a gito* Gito* t/glt t/gito* ~/bin - gitolite setup -fi diff --git a/gitolite b/gitolite deleted file mode 100755 index 646d036..0000000 --- a/gitolite +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/perl - -# all gitolite CLI tools run as sub-commands of this command -# ---------------------------------------------------------------------- - -=for usage -Usage: gitolite [sub-command] [options] - -The following subcommands are available; they should all respond to '-h': - - setup 1st run: initial setup; all runs: hook fixups - compile compile gitolite.conf - query-rc get values of rc variables - list-groups list all group names in conf - list-users list all users/user groups in conf - list-repos list all repos/repo groups in conf - list-phy-repos list all repos actually on disk - list-memberships list all groups a name is a member of - list-members list all members of a group - -Warnings: - - list-users is disk bound and could take a while on sites with 1000s of repos - - list-memberships does not check if the name is known; unknown names come - back with 2 answers: the name itself and '@all' -=cut - -# ---------------------------------------------------------------------- - -use FindBin; - -BEGIN { $ENV{GL_BINDIR} = $FindBin::Bin; } -use lib $ENV{GL_BINDIR}; -use Gitolite::Rc; -use Gitolite::Common; - -use strict; -use warnings; - -# ---------------------------------------------------------------------- - -args(); - -# ---------------------------------------------------------------------- - -sub args { - my ( $command, @args ) = @ARGV; - usage() if not $command or $command eq '-h'; - - if ( $command eq 'setup' ) { - shift @ARGV; - require Gitolite::Setup; - Gitolite::Setup->import; - setup(); - } elsif ( $command eq 'compile' ) { - shift @ARGV; - _die "'gitolite compile' does not take any arguments" if @ARGV; - require Gitolite::Conf; - Gitolite::Conf->import; - compile(); - } elsif ( $command eq 'query-rc' ) { - shift @ARGV; - query_rc(); - } elsif ( $command eq 'list-groups' ) { - shift @ARGV; - require Gitolite::Conf::Load; - Gitolite::Conf::Load->import; - print "$_\n" for ( @{ list_groups() } ); - } elsif ( $command eq 'list-users' ) { - shift @ARGV; - require Gitolite::Conf::Load; - Gitolite::Conf::Load->import; - print "$_\n" for ( @{ list_users() } ); - } elsif ( $command eq 'list-repos' ) { - shift @ARGV; - require Gitolite::Conf::Load; - Gitolite::Conf::Load->import; - print "$_\n" for ( @{ list_repos() } ); - } elsif ( $command eq 'list-phy-repos' ) { - shift @ARGV; - _chdir( $rc{GL_REPO_BASE} ); - print "$_\n" for ( @{ list_phy_repos() } ); - } elsif ( $command eq 'list-memberships' ) { - shift @ARGV; - require Gitolite::Conf::Load; - Gitolite::Conf::Load->import; - print "$_\n" for ( @{ list_memberships() } ); - } elsif ( $command eq 'list-members' ) { - shift @ARGV; - require Gitolite::Conf::Load; - Gitolite::Conf::Load->import; - print "$_\n" for ( @{ list_members() } ); - } else { - _die "unknown gitolite sub-command"; - } -} diff --git a/Gitolite/Common.pm b/src/Gitolite/Common.pm similarity index 92% rename from Gitolite/Common.pm rename to src/Gitolite/Common.pm index 0435793..6c62403 100644 --- a/Gitolite/Common.pm +++ b/src/Gitolite/Common.pm @@ -7,7 +7,7 @@ package Gitolite::Common; @EXPORT = qw( print2 dbg _mkdir _open ln_sf tsh_rc sort_u say _warn _chdir _print tsh_text list_phy_repos - say2 _die slurp tsh_lines + say2 _die _system slurp tsh_lines trace cleanup_conf_line tsh_try usage tsh_run ); @@ -97,6 +97,19 @@ sub _chdir { chdir( $_[0] || $ENV{HOME} ) or _die "chdir $_[0] failed: $!\n"; } +sub _system { + if ( system(@_) != 0 ) { + say2 "system @_ failed"; + if ( $? == -1 ) { + die "failed to execute: $!\n"; + } elsif ( $? & 127 ) { + die "child died with signal " . ( $? & 127 ) . "\n"; + } else { + die "child exited with value " . ( $? >> 8 ) . "\n"; + } + } +} + sub _open { open( my $fh, $_[0], $_[1] ) or _die "open $_[1] failed: $!\n"; return $fh; diff --git a/Gitolite/Conf.pm b/src/Gitolite/Conf.pm similarity index 98% rename from Gitolite/Conf.pm rename to src/Gitolite/Conf.pm index 2846f1f..6c7dca6 100644 --- a/Gitolite/Conf.pm +++ b/src/Gitolite/Conf.pm @@ -12,7 +12,6 @@ package Gitolite::Conf; use Exporter 'import'; use Getopt::Long; -use lib $ENV{GL_BINDIR}; use Gitolite::Common; use Gitolite::Rc; use Gitolite::Conf::Sugar; diff --git a/Gitolite/Conf/Explode.pm b/src/Gitolite/Conf/Explode.pm similarity index 99% rename from Gitolite/Conf/Explode.pm rename to src/Gitolite/Conf/Explode.pm index 43a5778..a821dc9 100644 --- a/Gitolite/Conf/Explode.pm +++ b/src/Gitolite/Conf/Explode.pm @@ -9,7 +9,6 @@ package Gitolite::Conf::Explode; use Exporter 'import'; -use lib $ENV{GL_BINDIR}; use Gitolite::Common; use strict; diff --git a/Gitolite/Conf/Load.pm b/src/Gitolite/Conf/Load.pm similarity index 99% rename from Gitolite/Conf/Load.pm rename to src/Gitolite/Conf/Load.pm index fd117fc..1b0d199 100644 --- a/Gitolite/Conf/Load.pm +++ b/src/Gitolite/Conf/Load.pm @@ -16,7 +16,6 @@ package Gitolite::Conf::Load; use Exporter 'import'; -use lib $ENV{GL_BINDIR}; use Gitolite::Common; use Gitolite::Rc; @@ -108,7 +107,7 @@ sub load_common { _die "parse $cc failed: " . ( $! or $@ ) unless do $cc; if ( data_version_mismatch() ) { - system("gitolite setup"); + _system("gitolite setup"); _die "parse $cc failed: " . ( $! or $@ ) unless do $cc; _die "data version update failed; this is serious" if data_version_mismatch(); } diff --git a/Gitolite/Conf/Store.pm b/src/Gitolite/Conf/Store.pm similarity index 99% rename from Gitolite/Conf/Store.pm rename to src/Gitolite/Conf/Store.pm index b99ac0b..37824c7 100644 --- a/Gitolite/Conf/Store.pm +++ b/src/Gitolite/Conf/Store.pm @@ -22,7 +22,6 @@ use Data::Dumper; $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys = 1; -use lib $ENV{GL_BINDIR}; use Gitolite::Common; use Gitolite::Rc; use Gitolite::Hooks::Update; @@ -169,7 +168,7 @@ sub new_repo { _mkdir("$repo.git"); _chdir("$repo.git"); - system("git init --bare >&2"); + _system("git init --bare >&2"); _chdir( $rc{GL_REPO_BASE} ); hook_1($repo); diff --git a/Gitolite/Conf/Sugar.pm b/src/Gitolite/Conf/Sugar.pm similarity index 99% rename from Gitolite/Conf/Sugar.pm rename to src/Gitolite/Conf/Sugar.pm index bfa7c5f..932928d 100644 --- a/Gitolite/Conf/Sugar.pm +++ b/src/Gitolite/Conf/Sugar.pm @@ -9,7 +9,6 @@ package Gitolite::Conf::Sugar; use Exporter 'import'; -use lib $ENV{GL_BINDIR}; use Gitolite::Rc; use Gitolite::Common; use Gitolite::Conf::Explode; diff --git a/Gitolite/Hooks/PostUpdate.pm b/src/Gitolite/Hooks/PostUpdate.pm similarity index 94% rename from Gitolite/Hooks/PostUpdate.pm rename to src/Gitolite/Hooks/PostUpdate.pm index 1ce07b2..ef8e522 100644 --- a/Gitolite/Hooks/PostUpdate.pm +++ b/src/Gitolite/Hooks/PostUpdate.pm @@ -10,7 +10,6 @@ package Gitolite::Hooks::PostUpdate; use Exporter 'import'; -use lib $ENV{GL_BINDIR}; use Gitolite::Rc; use Gitolite::Common; @@ -30,7 +29,7 @@ sub post_update { local $ENV{GIT_WORK_TREE} = $rc{GL_ADMIN_BASE}; tsh_try("git checkout -f --quiet master"); } - system("$ENV{GL_BINDIR}/gitolite compile"); + _system("$ENV{GL_BINDIR}/gitolite compile"); exit 0; } diff --git a/Gitolite/Hooks/Update.pm b/src/Gitolite/Hooks/Update.pm similarity index 99% rename from Gitolite/Hooks/Update.pm rename to src/Gitolite/Hooks/Update.pm index 2c60914..488a3ec 100644 --- a/Gitolite/Hooks/Update.pm +++ b/src/Gitolite/Hooks/Update.pm @@ -10,7 +10,6 @@ package Gitolite::Hooks::Update; use Exporter 'import'; -use lib $ENV{GL_BINDIR}; use Gitolite::Common; use Gitolite::Conf::Load; diff --git a/src/Gitolite/Rc.pm b/src/Gitolite/Rc.pm index e84ee0c..18cc6c5 100644 --- a/src/Gitolite/Rc.pm +++ b/src/Gitolite/Rc.pm @@ -7,9 +7,8 @@ package Gitolite::Rc; %rc glrc query_rc - version - $REMOTE_COMMAND_PATT + $ADC_CMD_ARGS_PATT $REF_OR_FILENAME_PATT $REPONAME_PATT $REPOPATT_PATT @@ -37,7 +36,7 @@ $rc{GL_REPO_BASE} = "$ENV{HOME}/repositories"; # variables that should probably never be changed # ---------------------------------------------------------------------- -$REMOTE_COMMAND_PATT = qr(^[- 0-9a-zA-Z\@\%_=+:,./]*$); +$ADC_CMD_ARGS_PATT = qr(^[0-9a-zA-Z._\@/+:-]*$); $REF_OR_FILENAME_PATT = qr(^[0-9a-zA-Z][0-9a-zA-Z._\@/+ :,-]*$); $REPONAME_PATT = qr(^\@?[0-9a-zA-Z][0-9a-zA-Z._\@/+-]*$); $REPOPATT_PATT = qr(^\@?[0-9a-zA-Z[][\\^.$|()[\]*+?{}0-9a-zA-Z._\@/,-]*$); @@ -49,17 +48,9 @@ my $current_data_version = "3.0"; my $rc = glrc('filename'); do $rc if -r $rc; -_die "$rc seems to be for older gitolite" if defined($GL_ADMINDIR); # let values specified in rc file override our internal ones @rc{ keys %RC } = values %RC; -# testing sometimes requires all of it to be overridden silently; use an -# env var that is highly unlikely to appear in real life :) -do $ENV{G3T_RC} if exists $ENV{G3T_RC} and -r $ENV{G3T_RC}; - -# fix PATH (TODO: do it only if 'gitolite' isn't in PATH) -$ENV{PATH} = "$ENV{GL_BINDIR}:$ENV{PATH}"; - # ---------------------------------------------------------------------- use strict; @@ -76,15 +67,19 @@ my $glrc_default_text = ''; sub glrc { my $cmd = shift; if ( $cmd eq 'default-filename' ) { + trace( 1, "..should happen only on first run" ); return "$ENV{HOME}/.gitolite.rc"; } elsif ( $cmd eq 'default-text' ) { + trace( 1, "..should happen only on first run" ); return $glrc_default_text if $glrc_default_text; _die "rc file default text not set; this should not happen!"; } elsif ( $cmd eq 'filename' ) { # where is the rc file? + trace(4); # search $HOME first return "$ENV{HOME}/.gitolite.rc" if -f "$ENV{HOME}/.gitolite.rc"; + trace( 2, "$ENV{HOME}/.gitolite.rc not found" ); # XXX for fedora, we can add the following line, but I would really prefer # if ~/.gitolite.rc on each $HOME was just a symlink to /etc/gitolite.rc @@ -99,68 +94,56 @@ sub glrc { } # ---------------------------------------------------------------------- -# implements 'gitolite query-rc' and 'version' +# implements 'gitolite query-rc' # ---------------------------------------------------------------------- -# ---------------------------------------------------------------------- +=for usage -my $all = 0; -my $nonl = 0; - -sub query_rc { - - my @vars = args(); - - no strict 'refs'; - - if ($all) { - for my $e ( sort keys %rc ) { - print "$e=" . ( defined( $rc{$e} ) ? $rc{$e} : 'undef' ) . "\n"; - } - return; - } - - print join( "\t", map { $rc{$_} || '' } @vars ) . ( $nonl ? '' : "\n" ) if @vars; -} - -sub version { - my $version = ''; - $version = '(unknown)'; - for ("$rc{GL_ADMIN_BASE}/VERSION") { - $version = slurp($_) if -r $_; - } - chomp($version); - return $version; -} - -# ---------------------------------------------------------------------- - -=for args Usage: gitolite query-rc -a - gitolite query-rc [-n] - - -a print all variables and values - -n do not append a newline + gitolite query-rc Example: - gitolite query-rc GL_ADMIN_BASE UMASK + gitolite query-rc GL_ADMIN_BASE GL_UMASK # prints "/home/git/.gitolite0077" or similar gitolite query-rc -a # prints all known variables and values, one per line =cut +# ---------------------------------------------------------------------- + +my $all = 0; + +sub query_rc { + trace( 1, "rc file not found; default should be " . glrc('default-filename') ) if not glrc('filename'); + + my @vars = args(); + + no strict 'refs'; + + if ( $vars[0] eq '-a' ) { + for my $e (sort keys %rc) { + print "$e=" . ( defined($rc{$e}) ? $rc{$e} : 'undef' ) . "\n"; + } + return; + } + + print join( "\t", map { $rc{$_} } @vars ) . "\n" if @vars; +} + +# ---------------------------------------------------------------------- + sub args { my $help = 0; GetOptions( 'all|a' => \$all, - 'nonl|n' => \$nonl, 'help|h' => \$help, ) or usage(); usage("'-a' cannot be combined with other arguments") if $all and @ARGV; + return '-a' if $all; usage() if not $all and not @ARGV or $help; return @ARGV; } @@ -172,36 +155,14 @@ sub args { __DATA__ # configuration variables for gitolite -# This file is in perl syntax. But you do NOT need to know perl to edit it -- -# just mind the commas and make sure the brackets and braces stay matched up! +# PLEASE READ THE DOCUMENTATION BEFORE EDITING OR ASKING QUESTIONS -# (Tip: perl allows a comma after the last item in a list also!) +# this file is in perl syntax. However, you do NOT need to know perl to edit +# it; it should be fairly self-explanatory and easy to maintain %RC = ( UMASK => 0077, GL_GITCONFIG_KEYS => "", - - # comment out or uncomment as needed - # these will run in sequence during the conf file parse - SYNTACTIC_SUGAR => - [ - # 'continuation-lines', - ], - - # comment out or uncomment as needed - # these will run in sequence after post-update - POST_COMPILE => - [ - 'post-compile/ssh-authkeys', - ], - - # comment out or uncomment as needed - # these are available to remote users - COMMANDS => - { - 'help' => 1, - 'info' => 1, - }, ); # ------------------------------------------------------------------------------ diff --git a/Gitolite/Setup.pm b/src/Gitolite/Setup.pm similarity index 96% rename from Gitolite/Setup.pm rename to src/Gitolite/Setup.pm index 28d1d74..b42e0fc 100644 --- a/Gitolite/Setup.pm +++ b/src/Gitolite/Setup.pm @@ -28,7 +28,6 @@ Later runs: use Exporter 'import'; use Getopt::Long; -use lib $ENV{GL_BINDIR}; use Gitolite::Rc; use Gitolite::Common; use Gitolite::Conf::Store; @@ -47,7 +46,7 @@ sub setup { setup_gladmin( $admin, $pubkey, $argv ); } - system("$ENV{GL_BINDIR}/gitolite compile"); + _system("$ENV{GL_BINDIR}/gitolite compile"); hook_repos(); # all of them, just to be sure } @@ -141,8 +140,8 @@ sub setup_gladmin { $ENV{GIT_WORK_TREE} = $rc{GL_ADMIN_BASE}; _chdir("$rc{GL_REPO_BASE}/gitolite-admin.git"); - system("git add conf/gitolite.conf"); - system("git add keydir") if $pubkey; + _system("git add conf/gitolite.conf"); + _system("git add keydir") if $pubkey; tsh_try("git config --get user.email") or tsh_run( "git config user.email $ENV{USER}\@" . `hostname` ); tsh_try("git config --get user.name") or tsh_run( "git config user.name '$ENV{USER} on '" . `hostname` ); tsh_try("git diff --cached --quiet") diff --git a/Gitolite/Test.pm b/src/Gitolite/Test.pm similarity index 70% rename from Gitolite/Test.pm rename to src/Gitolite/Test.pm index bb4d0a9..dcaf3fe 100644 --- a/Gitolite/Test.pm +++ b/src/Gitolite/Test.pm @@ -7,6 +7,7 @@ package Gitolite::Test; @EXPORT = qw( try put + text ); #>>> use Exporter 'import'; @@ -17,6 +18,7 @@ BEGIN { require Gitolite::Test::Tsh; *{'try'} = \&Tsh::try; *{'put'} = \&Tsh::put; + *{'text'} = \&Tsh::text; } use strict; @@ -30,11 +32,15 @@ try " DEF reject = /hook declined to update/; /remote rejected.*hook declined/; /error: failed to push some refs to/ DEF AP_1 = cd ../gitolite-admin; ok or die cant find admin repo clone; - DEF AP_2 = AP_1; git add conf keydir; ok; git commit -m %1; ok; /master.* %1/ + DEF AP_2 = AP_1; git add conf ; ok; git commit -m %1; ok; /master.* %1/ DEF ADMIN_PUSH = AP_2 %1; glt push admin origin; ok; gsh; /master -> master/ - ./g3-install -c admin + mkdir -p $ENV{HOME}/bin + ln -sf $ENV{PWD}/src/gitolite $ENV{PWD}/t/glt ~/bin + cd; rm -vrf .gito* gito* repositories + cd tsh_tempdir; -"; + gitolite setup -a admin +" or die "could not setup the test environment; errors:\n\n" . text() . "\n\n"; 1; diff --git a/Gitolite/Test/Tsh.pm b/src/Gitolite/Test/Tsh.pm similarity index 100% rename from Gitolite/Test/Tsh.pm rename to src/Gitolite/Test/Tsh.pm diff --git a/src/gitolite b/src/gitolite index c6a1f54..0457cc2 100755 --- a/src/gitolite +++ b/src/gitolite @@ -3,17 +3,14 @@ # all gitolite CLI tools run as sub-commands of this command # ---------------------------------------------------------------------- -=for args -Usage: gitolite [] [] +=for usage +Usage: gitolite [sub-command] [options] -The following built-in subcommands are available; they should all respond to -'-h' if you want further details on each: +The following subcommands are available; they should all respond to '-h': setup 1st run: initial setup; all runs: hook fixups compile compile gitolite.conf - query-rc get values of rc variables - list-groups list all group names in conf list-users list all users/user groups in conf list-repos list all repos/repo groups in conf @@ -25,10 +22,6 @@ Warnings: - list-users is disk bound and could take a while on sites with 1000s of repos - list-memberships does not check if the name is known; unknown names come back with 2 answers: the name itself and '@all' - -In addition, running 'gitolite help' should give you a list of custom commands -available. They may or may not respond to '-h', depending on how they were -written. =cut # ---------------------------------------------------------------------- @@ -45,62 +38,58 @@ use warnings; # ---------------------------------------------------------------------- -my ( $command, @args ) = @ARGV; -gl_log( 'gitolite', @ARGV ) if -d $rc{GL_ADMIN_BASE}; args(); -# the first two commands need options via @ARGV, as they have their own -# GetOptions calls and older perls don't have 'GetOptionsFromArray' - -if ( $command eq 'setup' ) { - shift @ARGV; - require Gitolite::Setup; - Gitolite::Setup->import; - setup(); - -} elsif ( $command eq 'query-rc' ) { - shift @ARGV; - query_rc(); - -# the rest don't need @ARGV per se - -} elsif ( $command eq 'compile' ) { - require Gitolite::Conf; - Gitolite::Conf->import; - compile(@args); - -} elsif ( $command eq 'trigger' ) { - trigger(@args); - -} elsif ( -x "$rc{GL_BINDIR}/commands/$command" ) { - trace( 2, "attempting gitolite command $command" ); - run_command( $command, @args ); - -} elsif ( $command eq 'list-phy-repos' ) { - _chdir( $rc{GL_REPO_BASE} ); - print "$_\n" for ( @{ list_phy_repos(@args) } ); - -} elsif ( $command =~ /^list-/ ) { - trace( 2, "attempting lister command $command" ); - require Gitolite::Conf::Load; - Gitolite::Conf::Load->import; - my $fn = lister_dispatch($command); - print "$_\n" for ( @{ $fn->(@args) } ); - -} else { - _die "unknown gitolite sub-command"; -} - -sub args { - usage() if not $command or $command eq '-h'; -} - # ---------------------------------------------------------------------- -sub run_command { - my $pgm = shift; - my $fullpath = "$ENV{GL_BINDIR}/commands/$pgm"; - _die "$pgm not found or not executable" if not -x $fullpath; - _system( $fullpath, @_ ); - exit 0; +sub args { + my ( $command, @args ) = @ARGV; + usage() if not $command or $command eq '-h'; + + if ( $command eq 'setup' ) { + shift @ARGV; + require Gitolite::Setup; + Gitolite::Setup->import; + setup(); + } elsif ( $command eq 'compile' ) { + shift @ARGV; + _die "'gitolite compile' does not take any arguments" if @ARGV; + require Gitolite::Conf; + Gitolite::Conf->import; + compile(); + } elsif ( $command eq 'query-rc' ) { + shift @ARGV; + query_rc(); + } elsif ( $command eq 'list-groups' ) { + shift @ARGV; + require Gitolite::Conf::Load; + Gitolite::Conf::Load->import; + print "$_\n" for ( @{ list_groups() } ); + } elsif ( $command eq 'list-users' ) { + shift @ARGV; + require Gitolite::Conf::Load; + Gitolite::Conf::Load->import; + print "$_\n" for ( @{ list_users() } ); + } elsif ( $command eq 'list-repos' ) { + shift @ARGV; + require Gitolite::Conf::Load; + Gitolite::Conf::Load->import; + print "$_\n" for ( @{ list_repos() } ); + } elsif ( $command eq 'list-phy-repos' ) { + shift @ARGV; + _chdir( $rc{GL_REPO_BASE} ); + print "$_\n" for ( @{ list_phy_repos() } ); + } elsif ( $command eq 'list-memberships' ) { + shift @ARGV; + require Gitolite::Conf::Load; + Gitolite::Conf::Load->import; + print "$_\n" for ( @{ list_memberships() } ); + } elsif ( $command eq 'list-members' ) { + shift @ARGV; + require Gitolite::Conf::Load; + Gitolite::Conf::Load->import; + print "$_\n" for ( @{ list_members() } ); + } else { + _die "unknown gitolite sub-command"; + } } diff --git a/gitolite-shell b/src/gitolite-shell similarity index 93% rename from gitolite-shell rename to src/gitolite-shell index 46ce08b..d7f6a19 100755 --- a/gitolite-shell +++ b/src/gitolite-shell @@ -3,11 +3,9 @@ # gitolite shell, invoked from ~/.ssh/authorized_keys # ---------------------------------------------------------------------- -BEGIN { - # find and set bin dir - $0 =~ m|^(/)?(.*)/| and $ENV{GL_BINDIR} = ( $1 || "$ENV{PWD}/" ) . $2; -} +use FindBin; +BEGIN { $ENV{GL_BINDIR} = $FindBin::RealBin; } use lib $ENV{GL_BINDIR}; use Gitolite::Rc; use Gitolite::Common; diff --git a/t/README b/t/README new file mode 100644 index 0000000..c863b41 --- /dev/null +++ b/t/README @@ -0,0 +1,8 @@ +WARNING: THE TEST SUITE DELETES STUFF FIRST! + +Testing gitolite3 is now one command after the clone: + + prove + +But because it starts by cleaning the slate, it's best to do it on a spare +userid that you are ok to lose data on. diff --git a/t/t01-basic b/t/basic.t similarity index 99% rename from t/t01-basic rename to t/basic.t index 83508a9..96c4012 100755 --- a/t/t01-basic +++ b/t/basic.t @@ -3,7 +3,7 @@ use strict; use warnings; # this is hardcoded; change it if needed -use lib "$ENV{HOME}/bin"; +use lib "src"; use Gitolite::Test; # basic tests diff --git a/t/gitolite-receive-pack b/t/gitolite-receive-pack index 48c7428..a4cc5be 100755 --- a/t/gitolite-receive-pack +++ b/t/gitolite-receive-pack @@ -9,4 +9,4 @@ $repo =~ s/\.git$//; my $user = $ENV{G3T_USER} || 'no-such-user'; $ENV{SSH_ORIGINAL_COMMAND} = "git-receive-pack '$repo'"; -exec( "$ENV{HOME}/bin/gitolite-shell", $user ); +exec( "$ENV{GL_BINDIR}/../src/gitolite-shell", $user ); diff --git a/t/gitolite-upload-pack b/t/gitolite-upload-pack index 8888abb..5981f17 100755 --- a/t/gitolite-upload-pack +++ b/t/gitolite-upload-pack @@ -9,4 +9,4 @@ $repo =~ s/\.git$//; my $user = $ENV{G3T_USER} || 'no-such-user'; $ENV{SSH_ORIGINAL_COMMAND} = "git-upload-pack '$repo'"; -exec( "$ENV{HOME}/bin/gitolite-shell", $user ); +exec( "$ENV{GL_BINDIR}/../src/gitolite-shell", $user ); diff --git a/t/glt b/t/glt index b5704f5..45e7b19 100755 --- a/t/glt +++ b/t/glt @@ -2,6 +2,9 @@ use strict; use warnings; +use FindBin; +BEGIN { $ENV{GL_BINDIR} = $FindBin::RealBin; } + print STDERR "TRACE: glt(", join( ")(", @ARGV ), ")\n"; my $cmd = shift or die "need command"; @@ -10,9 +13,9 @@ my $rc; $ENV{G3T_USER} = $user; if ( $cmd eq 'push' ) { - $rc = system( "git", $cmd, "--receive-pack=$ENV{HOME}/bin/gitolite-receive-pack", @ARGV ); + $rc = system( "git", $cmd, "--receive-pack=$ENV{GL_BINDIR}/gitolite-receive-pack", @ARGV ); } else { - $rc = system( "git", $cmd, "--upload-pack=$ENV{HOME}/bin/gitolite-upload-pack", @ARGV ); + $rc = system( "git", $cmd, "--upload-pack=$ENV{GL_BINDIR}/gitolite-upload-pack", @ARGV ); } if ( $? == -1 ) { diff --git a/t/reset b/t/reset new file mode 100755 index 0000000..8c5dcbf --- /dev/null +++ b/t/reset @@ -0,0 +1,8 @@ +#!/usr/bin/perl +use strict; +use warnings; + +# this is hardcoded; change it if needed +use lib "src"; +use Gitolite::Test; +try 'put';