diff --git a/CHANGELOG b/CHANGELOG index 91faaa5..b7d4330 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,18 @@ +2012-12-29 v3.3 bug fix: gl-perms propagation to slaves broke sometime + after v3.2 (so if you're only picking up tagged releases + you're OK) + + the "D" command now allows rm/unlock to be totally + disabled + + new trigger: update-gitweb-daemon-from-options; another + way to update gitweb and daemon access lists + + new 'create' command for explicit wild repo creation, and + new AutoCreate trigger to control auto-creation + + allow simple macros in conf file + 2012-11-14 v3.2 major efficiency boost for large setups optional support for multi-line pubkeys; see diff --git a/README.md b/README.md new file mode 100644 index 0000000..e650fa6 --- /dev/null +++ b/README.md @@ -0,0 +1,359 @@ +Github-users: click the 'wiki' link before sending me anything via github. + +Existing users: this is gitolite v3.x. If you are upgrading from v2.x this +file will not suffice; you *must* check the online docs (see below for URL). + +------------------------------------------------------------------------ + + +This file contains BASIC DOCUMENTATION ONLY. + +* It is suitable for a fresh, ssh-based, installation of gitolite and basic + usage of its most important features. +* It is NOT meant to be exhaustive or detailed. + +The COMPLETE DOCUMENTATION is at: + + http://sitaramc.github.com/gitolite/master-toc.html + +Please go there for what/why/how, concepts, background, troubleshooting, more +details on what is covered here, or advanced features not covered here. + +------------------------------------------------------------------------ + + +BASIC DOCUMENTATION FOR GITOLITE +================================ + +This file contains the following sections: + +* INSTALLATION AND SETUP +* ADDING USERS AND REPOS +* HELP FOR YOUR USERS +* BASIC SYNTAX +* ACCESS RULES +* GROUPS +* COMMANDS +* THE 'rc' FILE +* GIT-CONFIG +* GIT-DAEMON +* GITWEB +* CONTACT AND SUPPORT +* LICENSE + +------------------------------------------------------------------------ + + +INSTALLATION AND SETUP +---------------------- + +Server requirements: + +* any unix system +* sh +* git 1.6.6+ +* perl 5.8.8+ +* openssh 5.0+ +* a dedicated userid to host the repos (in this document, we assume it + is 'git'), with shell access ONLY by 'su - git' from some other userid + on the same server. + +Steps to install: + +* login as 'git' as described above +* make sure ~/.ssh/authorized_keys is empty or non-existent +* make sure your ssh public key from your workstation is available at $HOME/YourName.pub +* run the following commands: + + git clone git://github.com/sitaramc/gitolite + mkdir -p $HOME/bin + gitolite/install -to $HOME/bin + gitolite setup -pk YourName.pub + + If the last command doesn't run perhaps 'bin' in not in your 'PATH'. + You can either add it, or just run: + + $HOME/bin/gitolite setup -pk YourName.pub + + +ADDING USERS AND REPOS +---------------------- + +Do NOT add new repos or users manually on the server. Gitolite users, +repos, and access rules are maintained by making changes to a special repo +called 'gitolite-admin' and pushing those changes to the server. + +---- + +To administer your gitolite installation, start by doing this on your +workstation (if you have not already done so): + + git clone git@host:gitolite-admin + +**NOTE**: if you are asked for a password, something has gone wrong. + +Now if you 'cd gitolite-admin', you will see two subdirectories in it: +'conf' and 'keydir'. + +To add new users alice, bob, and carol, obtain their public keys and add +them to 'keydir' as alice.pub, bob.pub, and carol.pub respectively. + +To add a new repo 'foo' and give different levels of access to these +users, edit the file 'conf/gitolite.conf' and add lines like this: + + repo foo + RW+ = alice + RW = bob + R = carol + +See the 'ACCESS RULES' section later for more details. + +Once you have made these changes, do something like this: + + git add conf + git add keydir + git commit -m 'added foo, gave access to alice, bob, carol' + git push + +When the push completes, gitolite will add the new users to +~/.ssh/authorized_keys on the server, as well as create a new, empty, repo +called 'foo'. + + +HELP FOR YOUR USERS +------------------- + +Once a user has sent you their public key and you have added them as +specified above and given them access, you have to tell them what URL to +access their repos at. This is usually 'git clone git@host:reponame'; see +man git-clone for other forms. + +**NOTE**: again, if they are asked for a password, something is wrong. + +If they need to know what repos they have access to, they just have to run +'ssh git@host info'; see 'COMMANDS' section later for more on this. + + +BASIC SYNTAX +------------ + +The basic syntax of the conf file is very simple. + +* Everything is space separated; there are no commas, semicolons, etc., + in the syntax. +* Comments are in the usual perl/shell style. +* User and repo names are as simple as possible; they must start with an + alphanumeric, but after that they can also contain '.', '_', or '-'. + + Usernames can optionally be followed by an '@' and a domainname + containing at least one '.'; this allows you to use an email address + as someone's username. + + Reponames can contain '/' characters; this allows you to put your + repos in a tree-structure for convenience. +* There are no continuation lines. + + +ACCESS RULES +------------ + +This section is mostly 'by example'. + +Gitolite's access rules are very powerful. The simplest use was already +shown above. Here is a slightly more detailed example: + + repo foo + RW+ = alice + - master = bob + - refs/tags/v[0-9] = bob + RW = bob + RW refs/tags/v[0-9] = carol + R = dave + +For clones and fetches, as long as the user is listed with an R, RW +or RW+ in at least one rule, he is allowed to read the repo. + +For pushes, rules are processed in sequence until a rule is found +where the user, the permission (see note 1), and the refex (note 2) +*all* match. At that point, if the permission on the matched rule +was '-', the push is denied, otherwise it is allowed. If no rule +matches, the push is denied. + +Note 1: permission matching: + +* a permission of RW matches only a fast-forward push or create +* a permission of RW+ matches any type of push +* a permission of '-' matches any type of push + +Note 2: refex matching: +(refex = optional regex to match the ref being pushed) + +* an empty refex is treated as 'refs/.*' +* a refex that does not start with 'refs/' is prefixed with 'refs/heads/' +* finally, a '^' is prefixed +* the ref being pushed is matched against this resulting refex + +With all that background, here's what the example rules say: + +* alice can do anything to any branch or tag -- create, push, delete, rewind/overwrite etc. +* bob can create or fast-forward push any branch whose name does + not start with 'master' and create any tag whose name does not + start with 'v'+digit. +* carol can create tags whose names start with 'v'+digit. +* dave can clone/fetch. + + +GROUPS +------ + +Gitolite allows you to group users or repos for convenience. Here's an +example that creates two groups of users: + + @staff = alice bob carol + @interns = ashok + + repo secret + RW = @staff + + repo foss + RW+ = @staff + RW = @interns + +Group lists accumulate. The following two lines have the same effect as +the earlier definition of @staff above: + + @staff = alice bob + @staff = carol + +You can also use group names in other group names: + + @all-devs = @staff @interns + +Finally, @all is a special group name that is often convenient to use if +you really mean 'all repos' or 'all users'. + + +COMMANDS +-------- + +Users can run certain commands remotely, using ssh. For example: + + ssh git@host help + +prints a list of available commands. + +The most commonly used command is 'info'. All commands respond to a +single argument of '-h' with suitable information. + +If you have shell on the server, you have a lot more commands available to +you; try running 'gitolite help'. + + +THE 'rc' FILE +-------------- + +Some of the instructions below may require you to edit the rc file +(~/.gitolite.rc on the server). + +The rc file is perl code, but you do NOT need to know perl to edit it. +Just mind the commas, use single quotes unless you know what you're doing, +and make sure the brackets and braces stay matched up. + + +GIT-CONFIG +---------- + +Gitolite lets you set git-config values for individual repos without +having to log on to the server and run 'git config' commands: + + repo foo + config hooks.mailinglist = foo-commits@example.tld + config hooks.emailprefix = '[foo] ' + config foo.bar = '' + config foo.baz = + +**WARNING** + +The last syntax shown above is the *only* way to *delete* a config +variable once you have added it. Merely removing it from the conf +file will *not* delete it from the repo.git/config file. + +**SECURITY NOTE** + +Some git-config keys allow arbitrary code to be run on the server. + +If all of your gitolite admins already have shell access to the server +account hosting it, you can edit the rc file (~/.gitolite.rc) on the +server, and change the GIT_CONFIG_KEYS line to look like this: + + GIT_CONFIG_KEYS => '.*', + +Otherwise, give it a space-separated list of regular expressions that +define what git-config keys are allowed. For example, this one allows +only variables whose names start with 'gitweb' or with 'gc' to be +defined: + + GIT_CONFIG_KEYS => 'gitweb\..* gc\..*', + + +GIT-DAEMON +---------- + +Gitolite creates the 'git-daemon-export-ok' file for any repo that is +readable by a special user called 'daemon', like so: + + repo foo + R = daemon + + +GITWEB +------ + +Any repo that is readable by a special user called 'gitweb' will be added +to the projects.list file. + + repo foo + R = gitweb + +Or you can set one or more of the following config variables instead: + + repo foo + config gitweb.owner = some person's name + config gitweb.description = some description + config gitweb.category = some category + +**NOTE** + +You will probably need to change the UMASK in the rc file from the +default (0077) to 0027 and add whatever user your gitweb is running as +to the 'git' group. After that, you need to run a one-time 'chmod -R' +on the already created files and directories. + +------------------------------------------------------------------------ + + +CONTACT AND SUPPORT +------------------- + +Mailing list for support and general discussion: + gitolite@googlegroups.com + subscribe address: gitolite+subscribe@googlegroups.com + +Mailing list for announcements and notices: + subscribe address: gitolite-announce+subscribe@googlegroups.com + +IRC: #git and #gitolite on freenode. Note that I live in India (UTC+0530 +time zone). + +Author: sitaramc@gmail.com, but please DO NOT use this for general support +questions. Subscribe to the list and ask there instead. + + +LICENSE +------- + +The gitolite *code* is released under GPL v2. See COPYING for details. + +This documentation, which is part of the source code repository, is +provided under a Creative Commons Attribution-ShareAlike 3.0 Unported +License -- see http://creativecommons.org/licenses/by-sa/3.0/ diff --git a/README.txt b/README.txt deleted file mode 100644 index 468062e..0000000 --- a/README.txt +++ /dev/null @@ -1,373 +0,0 @@ -Github-users: click the 'wiki' link before sending me anything via github. - -Existing users: this is gitolite v3.x. If you are upgrading from v2.x this -file will not suffice; you *must* check the online docs (see below for URL). - ------------------------------------------------------------------------- - - -This file contains BASIC DOCUMENTATION ONLY. - - * It is suitable for a fresh, ssh-based, installation of gitolite and basic - usage of its most important features. - - * It is NOT meant to be exhaustive or detailed. - -The COMPLETE DOCUMENTATION is at: - - http://sitaramc.github.com/gitolite/master-toc.html - -Please go there for what/why/how, concepts, background, troubleshooting, more -details on what is covered here, or advanced features not covered here. - ------------------------------------------------------------------------- - - -BASIC DOCUMENTATION FOR GITOLITE -================================ - -This file contains the following sections: - - INSTALLATION AND SETUP - ADDING USERS AND REPOS - HELP FOR YOUR USERS - BASIC SYNTAX - ACCESS RULES - GROUPS - COMMANDS - THE 'rc' FILE - GIT-CONFIG - GIT-DAEMON - GITWEB - - CONTACT AND SUPPORT - LICENSE - ------------------------------------------------------------------------- - - -INSTALLATION AND SETUP ----------------------- - - Server requirements: - - * any unix system - * sh - * git 1.6.6+ - * perl 5.8.8+ - * openssh 5.0+ - * a dedicated userid to host the repos (in this document, we assume it - is 'git'), with shell access ONLY by 'su - git' from some other userid - on the same server. - - Steps to install: - - * login as 'git' as described above - - * make sure ~/.ssh/authorized_keys is empty or non-existent - - * make sure your ssh public key from your workstation is available at - $HOME/YourName.pub - - * run the following commands: - - git clone git://github.com/sitaramc/gitolite - mkdir -p $HOME/bin - gitolite/install -to $HOME/bin - gitolite setup -pk YourName.pub - - If the last command doesn't run perhaps 'bin' in not in your 'PATH'. - You can either add it, or just run: - - $HOME/bin/gitolite setup -pk YourName.pub - - -ADDING USERS AND REPOS ----------------------- - - Do NOT add new repos or users manually on the server. Gitolite users, - repos, and access rules are maintained by making changes to a special repo - called 'gitolite-admin' and pushing those changes to the server. - - ---- - - To administer your gitolite installation, start by doing this on your - workstation (if you have not already done so): - - git clone git@host:gitolite-admin - - **NOTE**: if you are asked for a password, something has gone wrong. - - Now if you 'cd gitolite-admin', you will see two subdirectories in it: - 'conf' and 'keydir'. - - To add new users alice, bob, and carol, obtain their public keys and add - them to 'keydir' as alice.pub, bob.pub, and carol.pub respectively. - - To add a new repo 'foo' and give different levels of access to these - users, edit the file 'conf/gitolite.conf' and add lines like this: - - repo foo - RW+ = alice - RW = bob - R = carol - - See the 'ACCESS RULES' section later for more details. - - Once you have made these changes, do something like this: - - git add conf - git add keydir - git commit -m 'added foo, gave access to alice, bob, carol' - git push - - When the push completes, gitolite will add the new users to - ~/.ssh/authorized_keys on the server, as well as create a new, empty, repo - called 'foo'. - - -HELP FOR YOUR USERS -------------------- - - Once a user has sent you their public key and you have added them as - specified above and given them access, you have to tell them what URL to - access their repos at. This is usually 'git clone git@host:reponame'; see - man git-clone for other forms. - - **NOTE**: again, if they are asked for a password, something is wrong. - - If they need to know what repos they have access to, they just have to run - 'ssh git@host info'; see 'COMMANDS' section later for more on this. - - -BASIC SYNTAX ------------- - - The basic syntax of the conf file is very simple. - - * Everything is space separated; there are no commas, semicolons, etc., - in the syntax. - - * Comments are in the usual perl/shell style. - - * User and repo names are as simple as possible; they must start with an - alphanumeric, but after that they can also contain '.', '_', or '-'. - - Usernames can optionally be followed by an '@' and a domainname - containing at least one '.'; this allows you to use an email address - as someone's username. - - Reponames can contain '/' characters; this allows you to put your - repos in a tree-structure for convenience. - - * There are no continuation lines. - - -ACCESS RULES ------------- - - This section is mostly 'by example'. - - Gitolite's access rules are very powerful. The simplest use was already - shown above. Here is a slightly more detailed example: - - repo foo - RW+ = alice - - master = bob - - refs/tags/v[0-9] = bob - RW = bob - RW refs/tags/v[0-9] = carol - R = dave - - For clones and fetches, as long as the user is listed with an R, RW - or RW+ in at least one rule, he is allowed to read the repo. - - For pushes, rules are processed in sequence until a rule is found - where the user, the permission (see note 1), and the refex (note 2) - *all* match. At that point, if the permission on the matched rule - was '-', the push is denied, otherwise it is allowed. If no rule - matches, the push is denied. - - Note 1: permission matching: - - * a permission of RW matches only a fast-forward push or create - * a permission of RW+ matches any type of push - * a permission of '-' matches any type of push - - Note 2: refex matching: - (refex = optional regex to match the ref being pushed) - - * an empty refex is treated as 'refs/.*' - * a refex that does not start with 'refs/' is prefixed with 'refs/heads/' - * finally, a '^' is prefixed - * the ref being pushed is matched against this resulting refex - - With all that background, here's what the example rules say: - - * alice can do anything to any branch or tag -- create, push, - delete, rewind/overwrite etc. - - * bob can create or fast-forward push any branch whose name does - not start with 'master' and create any tag whose name does not - start with 'v'+digit. - - * carol can create tags whose names start with 'v'+digit. - - * dave can clone/fetch. - - -GROUPS ------- - - Gitolite allows you to groups users or repos for convenience. Here's an - example that creates two groups of users: - - @staff = alice bob carol - @interns = ashok - - repo secret - RW = @staff - - repo foss - RW+ = @staff - RW = @interns - - Group lists accumulate. The following two lines have the same effect as - the earlier definition of @staff above: - - @staff = alice bob - @staff = carol - - You can also use group names in other group names: - - @all-devs = @staff @interns - - Finally, @all is a special group name that is often convenient to use if - you really mean 'all repos' or 'all users'. - - -COMMANDS --------- - - Users can run certain commands remotely, using ssh. For example: - - ssh git@host help - - prints a list of available commands. - - The most commonly used command is 'info'. All commands respond to a - single argument of '-h' with suitable information. - - If you have shell on the server, you have a lot more commands available to - you; try running 'gitolite help'. - - -THE 'rc' FILE --------------- - - Some of the instructions below may require you to edit the rc file - (~/.gitolite.rc on the server). - - The rc file is perl code, but you do NOT need to know perl to edit it. - Just mind the commas, use single quotes unless you know what you're doing, - and make sure the brackets and braces stay matched up. - - -GIT-CONFIG ----------- - - Gitolite lets you set git-config values for individual repos without - having to log on to the server and run 'git config' commands: - - repo foo - config hooks.mailinglist = foo-commits@example.tld - config hooks.emailprefix = '[foo] ' - config foo.bar = '' - config foo.baz = - - **WARNING** - - The last syntax shown above is the *only* way to *delete* a config - variable once you have added it. Merely removing it from the conf - file will *not* delete it from the repo.git/config file. - - **SECURITY NOTE** - - Some git-config keys allow arbitrary code to be run on the server. - - If all of your gitolite admins already have shell access to the server - account hosting it, you can edit the rc file (~/.gitolite.rc) on the - server, and change the GIT_CONFIG_KEYS line to look like this: - - GIT_CONFIG_KEYS => '.*', - - Otherwise, give it a space-separated list of regular expressions that - define what git-config keys are allowed. For example, this one allows - only variables whose names start with 'gitweb' or with 'gc' to be - defined: - - GIT_CONFIG_KEYS => 'gitweb\..* gc\..*', - - -GIT-DAEMON ----------- - - Gitolite creates the 'git-daemon-export-ok' file for any repo that is - readable by a special user called 'daemon', like so: - - repo foo - R = daemon - - -GITWEB ------- - - Any repo that is readable by a special user called 'gitweb' will be added - to the projects.list file. - - repo foo - R = gitweb - - Or you can set one or more of the following config variables instead: - - repo foo - config gitweb.owner = some person's name - config gitweb.description = some description - config gitweb.category = some category - - **NOTE** - - You will probably need to change the UMASK in the rc file from the - default (0077) to 0027 and add whatever user your gitweb is running as - to the 'git' group. After that, you need to run a one-time 'chmod -R' - on the already created files and directories. - - ------------------------------------------------------------------------- - - -CONTACT AND SUPPORT -------------------- - - Mailing list for support and general discussion: - gitolite@googlegroups.com - subscribe address: gitolite+subscribe@googlegroups.com - - Mailing list for announcements and notices: - subscribe address: gitolite-announce+subscribe@googlegroups.com - - IRC: #git and #gitolite on freenode. Note that I live in India (UTC+0530 - time zone). - - Author: sitaramc@gmail.com, but please DO NOT use this for general support - questions. Subscribe to the list and ask there instead. - - -LICENSE -------- - - The gitolite *code* is released under GPL v2. See COPYING for details. - - This documentation, which is part of the source code repository, is - provided under a Creative Commons Attribution-ShareAlike 3.0 Unported - License -- see http://creativecommons.org/licenses/by-sa/3.0/ diff --git a/src/commands/D b/src/commands/D index a255073..1a8c2b5 100755 --- a/src/commands/D +++ b/src/commands/D @@ -12,6 +12,9 @@ # - run a cron job to delete old repos based on age (the TRASH_SUFFIX has a # timestamp); your choice how/how often you do that + +# - you can completely disable the 'rm' command by setting an rc variable +# called D_DISABLE_RM to "1". # ---------------------------------------------------------------------- # ---------------------------------------------------------------------- @@ -67,6 +70,8 @@ owner_or_die() { if [ "$cmd" = "rm" ] then + gitolite query-rc -q D_DISABLE_RM && die "sorry, 'unlock' and 'rm' are disabled" + owner_or_die [ -f $repo.git/gl-rm-ok ] || die "'$repo' is locked!" rm -rf $repo.git @@ -82,6 +87,8 @@ then elif [ "$cmd" = "unlock" ] then + gitolite query-rc -q D_DISABLE_RM && die "sorry, 'unlock' and 'rm' are disabled" + owner_or_die touch $repo.git/gl-rm-ok echo "'$repo' is now unlocked" diff --git a/src/commands/create b/src/commands/create new file mode 100755 index 0000000..adac0e3 --- /dev/null +++ b/src/commands/create @@ -0,0 +1,15 @@ +#!/bin/bash + +# Usage: ssh git@host create +# +# Create wild repo. + +die() { echo "$@" >&2; exit 1; } +usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; } +[ -z "$1" ] && usage +[ -z "$2" ] || usage +[ "$1" = "-h" ] && usage +[ -z "$GL_USER" ] && die GL_USER not set + +# ---------------------------------------------------------------------- +exec $GL_BINDIR/commands/perms -c "$@" < /dev/null diff --git a/src/commands/fork b/src/commands/fork index 1d68d64..b381662 100755 --- a/src/commands/fork +++ b/src/commands/fork @@ -10,10 +10,6 @@ # traffic but because it uses git clone's "-l" option to share the object # store also, so it is likely to be almost instantaneous, regardless of how # big the repo actually is. -# -# The only caveat is that the repo you cloned *from* must not later become -# unavailable in any way. If you cannot be sure of this, take the scenic -# route (clone repo1, push to repo2). die() { echo "$@" >&2; exit 1; } usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; } diff --git a/src/commands/list-dangling-repos b/src/commands/list-dangling-repos index 6889ed9..6d86937 100755 --- a/src/commands/list-dangling-repos +++ b/src/commands/list-dangling-repos @@ -4,6 +4,7 @@ use warnings; use lib $ENV{GL_LIBDIR}; use Gitolite::Common; +use Gitolite::Conf::Load; =for usage Usage: gitolite list-dangling-repos @@ -12,6 +13,9 @@ List all existing repos that no one can access remotely any more. They could be normal repos that were taken out of "repo" statements in the conf file, or wildcard repos whose matching "wild" pattern was taken out or changed so it no longer matches. + +I would advise caution if you use this as a basis for deleting repos from the +file system. A bug in this program could cause you to lose important data! =cut usage() if @ARGV and $ARGV[0] eq '-h'; @@ -21,6 +25,9 @@ usage() if @ARGV and $ARGV[0] eq '-h'; # is to cull %phy_repos of all keys that have a matching key in %repos, where # "matching" means "string equal" or "regex match". my %repos = map { chomp; $_ => 1 } `gitolite list-repos`; +for my $r ( grep /^@/, keys %repos ) { + map { chomp; $repos{$_} = 1; } `gitolite list-members $r`; +} my %phy_repos = map { chomp; $_ => 1 } `gitolite list-phy-repos`; # Remove exact matches. But for repo names like "gtk+", you could have @@ -34,8 +41,9 @@ for my $pr (keys %phy_repos) { # Remove regex matches. for my $pr (keys %phy_repos) { my $matched = 0; + my $pr2 = Gitolite::Conf::Load::generic_name($pr); for my $r (keys %repos) { - if ($pr =~ /^$r$/) { + if ($pr =~ /^$r$/ or $pr2 =~ /^$r$/) { $matched = 1; next; } diff --git a/src/commands/lock b/src/commands/lock index f95af6c..a9e9073 100755 --- a/src/commands/lock +++ b/src/commands/lock @@ -71,7 +71,7 @@ sub f_unlock { my ( $repo, $file ) = @_; my %locks = get_locks(); - _die "'$file' not locked by '$ENV{GL_USER}'" if ( $locks{$file} || '' ) ne $ENV{GL_USER}; + _die "'$file' not locked by '$ENV{GL_USER}'" if ( $locks{$file}{USER} || '' ) ne $ENV{GL_USER}; delete $locks{$file}; put_locks(%locks); } diff --git a/src/commands/mirror b/src/commands/mirror index 16c14dd..d72f9ae 100755 --- a/src/commands/mirror +++ b/src/commands/mirror @@ -48,15 +48,16 @@ if ( $cmd eq 'push' ) { if (-f "gl-creator") { # try to propagate the wild repo, including creator name and gl-perms my $creator = `cat gl-creator`; chomp($creator); - trace(1, `cat gl-perms 2>/dev/null | ssh $host CREATOR=$creator perms -c \\'$repo\\'`); + trace(1, `cat gl-perms 2>/dev/null | ssh $host CREATOR=$creator perms -c \\'$repo\\' 2>/dev/null`); } my $errors = 0; for (`git push --mirror $host:$repo 2>&1`) { + $errors = 1 if $?; print STDERR "$_" if -t STDERR or exists $ENV{GL_USER}; chomp; if (/FATAL/) { - $errors++; + $errors = 1; gl_log( 'mirror', $_ ); } else { trace( 1, "mirror: $_" ); diff --git a/src/commands/perms b/src/commands/perms index 46c4e97..88244a9 100755 --- a/src/commands/perms +++ b/src/commands/perms @@ -43,15 +43,17 @@ if ( $ARGV[0] eq '-l' ) { getperms(@ARGV); # doesn't return } +my $generic_error = "repo does not exist, or you are not authorised"; + # auto-create the repo if -c passed and repo doesn't exist if ( $ARGV[0] eq '-c' ) { shift; - my $repo = $ARGV[0]; + my $repo = $ARGV[0] or usage(); _die "invalid repo '$repo'" unless $repo =~ $REPONAME_PATT; if (not -d "$rc{GL_REPO_BASE}/$repo.git") { my $ret = access( $repo, $ENV{GL_USER}, '^C', 'any' ); - _die $ret if $ret =~ /DENIED/; + _die $generic_error if $ret =~ /DENIED/; require Gitolite::Conf::Store; Gitolite::Conf::Store->import; @@ -68,7 +70,7 @@ _system( "gitolite", "trigger", "POST_CREATE", $repo, $ENV{GL_USER}, 'perms' ); sub getperms { my $repo = shift; - _die "sorry you are not authorised" if repo_missing($repo) or creator($repo) ne $ENV{GL_USER}; + _die $generic_error if repo_missing($repo) or creator($repo) ne $ENV{GL_USER}; my $pf = "$rc{GL_REPO_BASE}/$repo.git/gl-perms"; print slurp($pf) if -f $pf; @@ -77,17 +79,20 @@ sub getperms { } sub setperms { - _die "sorry you are not authorised" if repo_missing($repo) or creator($repo) ne $ENV{GL_USER}; + _die $generic_error if repo_missing($repo) or creator($repo) ne $ENV{GL_USER}; my $pf = "$rc{GL_REPO_BASE}/$repo.git/gl-perms"; if ( not @_ ) { # legacy mode; pipe data in + print STDERR "'batch' mode started, waiting for input (run with '-h' for details).\n"; + print STDERR "Please hit Ctrl-C if you did not intend to do this.\n"; @ARGV = (); my @a; for (<>) { _die "Invalid role '$1'; check the rc file" if /(\S+)/ and not $rc{ROLES}{$1}; push @a, $_; } + print STDERR "\n"; # make sure Ctrl-C gets caught _print( $pf, @a ); return; } diff --git a/src/commands/sshkeys-lint b/src/commands/sshkeys-lint index 2ff8e66..5626a27 100755 --- a/src/commands/sshkeys-lint +++ b/src/commands/sshkeys-lint @@ -73,7 +73,7 @@ for my $pkf (@pubkeyfiles) { my $fp = fprint($pkf); next unless $fp; msg 1, "$pkfsn appears to be a COPY of $pkf_by_fp{$fp}\n" if $pkf_by_fp{$fp}; - $pkf_by_fp{$fp} ||= $pkf; + $pkf_by_fp{$fp} ||= $pkfsn; my $fpu = ( $seen_fprints{$fp}{user} || 'no access' ); msg 0, "$pkfsn maps to $fpu\n"; } @@ -170,17 +170,20 @@ sub fprint { sub usage { print <&2; exit 1; } usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; } -[ -z "$1" ] && usage +[ -z "$2" ] && usage [ "$1" = "-h" ] && usage [ -z "$GL_USER" ] && die GL_USER not set diff --git a/src/gitolite-shell b/src/gitolite-shell index 4bbae48..a3ec321 100755 --- a/src/gitolite-shell +++ b/src/gitolite-shell @@ -234,5 +234,6 @@ sub http_print_headers { print "Expires: Fri, 01 Jan 1980 00:00:00 GMT\r\n"; print "Pragma: no-cache\r\n"; print "Cache-Control: no-cache, max-age=0, must-revalidate\r\n"; + print "Content-Type: text/plain\r\n"; print "\r\n"; } diff --git a/src/lib/Gitolite/Common.pm b/src/lib/Gitolite/Common.pm index c93e6ef..f7171ff 100644 --- a/src/lib/Gitolite/Common.pm +++ b/src/lib/Gitolite/Common.pm @@ -277,7 +277,7 @@ sub gl_log { my $fh; logger_plus_stderr( "errors found before logging could be setup", "$msg" ) if not $ENV{GL_LOGFILE}; open my $lfh, ">>", $ENV{GL_LOGFILE} - or logger_plus_stderr( "errors found before logfile could be created", "$msg" ); + or logger_plus_stderr( "errors found but logfile could not be created", "$ENV{GL_LOGFILE}: $!", "$msg" ); print $lfh "$ts\t$tid\t$msg\n"; close $lfh; } diff --git a/src/lib/Gitolite/Conf/Load.pm b/src/lib/Gitolite/Conf/Load.pm index 9a09793..6c133e2 100644 --- a/src/lib/Gitolite/Conf/Load.pm +++ b/src/lib/Gitolite/Conf/Load.pm @@ -246,9 +246,9 @@ sub load_1 { } if ( -f "gl-conf" ) { - _warn "split conf not set, gl-conf present for '$repo'" if not $split_conf{$repo}; + return if not $split_conf{$repo}; - my $cc = "gl-conf"; + my $cc = "./gl-conf"; _die "parse '$cc' failed: " . ( $! or $@ ) unless do $cc; $last_repo = $repo; @@ -386,6 +386,8 @@ sub user_roles { for (@roles) { # READERS u3 u4 @g1 s/^\s+//; s/ +$//; s/=/ /; s/\s+/ /g; s/^\@//; + next if /^#/; + next unless /\S/; my ( $role, @members ) = split; # role = READERS, members = u3, u4, @g1 if ( $role ne 'CREATOR' and not $rc{ROLES}{$role} ) { @@ -418,8 +420,7 @@ sub generic_name { $creator = creator($base); $base2 = $base; - $base2 =~ s(/$creator/)(/CREATOR/) if $creator; - $base2 =~ s(^$creator/)(CREATOR/) if $creator; + $base2 =~ s(\b$creator\b)(CREATOR) if $creator; $base2 = '' if $base2 eq $base; # if there was no change return $base2; diff --git a/src/lib/Gitolite/Conf/Store.pm b/src/lib/Gitolite/Conf/Store.pm index 2a38a72..1d6d8e2 100644 --- a/src/lib/Gitolite/Conf/Store.pm +++ b/src/lib/Gitolite/Conf/Store.pm @@ -156,7 +156,7 @@ sub new_repos { # normal repos my @repos = grep { $_ =~ $REPONAME_PATT and not /^@/ } sort keys %repos; # add in members of repo groups - map { push @repos, keys %{ $groups{$_} } } grep { /^@/ } keys %repos; + map { push @repos, keys %{ $groups{$_} } } grep { /^@/ and $_ ne '@all' } keys %repos; for my $repo ( @{ sort_u( \@repos ) } ) { next unless $repo =~ $REPONAME_PATT; # skip repo patterns @@ -311,8 +311,7 @@ sub store_common { } } - $dumped_data = Data::Dumper->Dump( [ \%patterns ], [qw(*patterns)] ) if %patterns; - print $compiled_fh $dumped_data; + print $compiled_fh Data::Dumper->Dump( [ \%patterns ], [qw(*patterns)] ) if %patterns; print $compiled_fh Data::Dumper->Dump( [ \%split_conf ], [qw(*split_conf)] ) if %split_conf; diff --git a/src/lib/Gitolite/Test/Tsh.pm b/src/lib/Gitolite/Test/Tsh.pm index 2b7dcee..b3c43e0 100644 --- a/src/lib/Gitolite/Test/Tsh.pm +++ b/src/lib/Gitolite/Test/Tsh.pm @@ -261,7 +261,12 @@ sub rc_lines { $cmd = shift @cmds; # is the current command a "testing" command? - my $testing_cmd = ( $cmd =~ m(^ok(?:\s+or\s+(.*))?$) or $cmd =~ m(^!ok(?:\s+or\s+(.*))?$) or $cmd =~ m(^/(.*?)/(?:\s+or\s+(.*))?$) or $cmd =~ m(^!/(.*?)/(?:\s+or\s+(.*))?$) ); + my $testing_cmd = ( + $cmd =~ m(^ok(?:\s+or\s+(.*))?$) + or $cmd =~ m(^!ok(?:\s+or\s+(.*))?$) + or $cmd =~ m(^/(.*?)/(?:\s+or\s+(.*))?$) + or $cmd =~ m(^!/(.*?)/(?:\s+or\s+(.*))?$) + ); # warn if the previous command failed but rc is not being checked if ( $rc and not $testing_cmd ) { @@ -474,7 +479,7 @@ sub fail { sub cmp { # compare input string with second input string or text() - my $in = shift; + my $in = shift; my $text = ( @_ ? +shift : text() ); if ( $text eq $in ) { @@ -583,7 +588,7 @@ sub dummy_commits { test_tick(); next; } - my $ts = ( $tick ? gmtime($tick+19800) : gmtime() ); + my $ts = ( $tick ? gmtime( $tick + 19800 ) : gmtime() ); _sh("echo $f at $ts >> $f && git add $f && git commit -m '$f at $ts'"); } } diff --git a/src/lib/Gitolite/Triggers/Alias.pm b/src/lib/Gitolite/Triggers/Alias.pm old mode 100755 new mode 100644 diff --git a/src/lib/Gitolite/Triggers/AutoCreate.pm b/src/lib/Gitolite/Triggers/AutoCreate.pm new file mode 100644 index 0000000..8fe46d7 --- /dev/null +++ b/src/lib/Gitolite/Triggers/AutoCreate.pm @@ -0,0 +1,24 @@ +package Gitolite::Triggers::AutoCreate; + +use strict; +use warnings; + +# perl trigger set for stuff to do with auto-creating repos +# ---------------------------------------------------------------------- + +# to deny auto-create on read access, add 'AutoCreate::deny_R' to the +# PRE_CREATE trigger list +sub deny_R { + die "autocreate denied\n" if $_[3] and $_[3] eq 'R'; + return; +} + +# to deny auto-create on read *and* write access, add 'AutoCreate::deny_RW' to +# the PRE_CREATE trigger list. This means you can only create repos using the +# 'create' command, (which needs to be enabled in the COMMANDS list). +sub deny_RW { + die "autocreate denied\n" if $_[3] and ( $_[3] eq 'R' or $_[3] eq 'W' ); + return; +} + +1; diff --git a/src/lib/Gitolite/Triggers/CpuTime.pm b/src/lib/Gitolite/Triggers/CpuTime.pm old mode 100755 new mode 100644 index 552bf40..74b4217 --- a/src/lib/Gitolite/Triggers/CpuTime.pm +++ b/src/lib/Gitolite/Triggers/CpuTime.pm @@ -10,6 +10,7 @@ use warnings; # cpu and elapsed times for gitolite+git operations # ---------------------------------------------------------------------- +# uncomment the appropriate lines in the rc file to enable this # Ideally, you will (a) write your own code with a different filename so later # gitolite upgrades won't overwrite your copy, (b) add appropriate variables @@ -18,8 +19,6 @@ use warnings; # ---------------------------------------------------------------------- my $start_time; -# this trigger is not yet documented; it gets called at the start and does not -# receive any arguments. sub input { _warn "something wrong with the invocation of CpuTime::input" if $ENV{GL_TID} ne $$; $start_time = [ Time::HiRes::gettimeofday() ]; diff --git a/src/lib/Gitolite/Triggers/RepoUmask.pm b/src/lib/Gitolite/Triggers/RepoUmask.pm index b0a9ad1..ea675e2 100644 --- a/src/lib/Gitolite/Triggers/RepoUmask.pm +++ b/src/lib/Gitolite/Triggers/RepoUmask.pm @@ -9,6 +9,8 @@ use warnings; # setting a repo specific umask # ---------------------------------------------------------------------- +# this is for people who are too paranoid to trust e.g., gitweb's repo +# exclusion logic, but not paranoid enough to put it on a different server =for usage diff --git a/src/lib/Gitolite/Triggers/Shell.pm b/src/lib/Gitolite/Triggers/Shell.pm index 0e6f0a1..b6e24c3 100644 --- a/src/lib/Gitolite/Triggers/Shell.pm +++ b/src/lib/Gitolite/Triggers/Shell.pm @@ -3,6 +3,9 @@ package Gitolite::Triggers::Shell; # usage notes: this module must be loaded first in the INPUT trigger list. Or # at least before Mirroring::input anyway. +# documentation is in the ssh troubleshooting and tips document, under the +# section "giving shell access to gitolite users" + use Gitolite::Rc; use Gitolite::Common; diff --git a/src/syntactic-sugar/macros b/src/syntactic-sugar/macros new file mode 100644 index 0000000..2dbb5fd --- /dev/null +++ b/src/syntactic-sugar/macros @@ -0,0 +1,74 @@ +# vim: syn=perl: + +# "sugar script" (syntactic sugar helper) for gitolite3 + +# simple line-wise macro processor +# ---------------------------------------------------------------------- +# see documentation at the end of this script + +my %macro; +sub sugar_script { + my $lines = shift; + my @out = (); + + my $l = join("\n", @$lines); + while ($l =~ s/^macro (\w+)\b(.*?)\nend//ms) { + $macro{$1} = $2; + } + + $l =~ s/^((\w+)\b.*)/$macro{$2} ? expand($1) : $1/gem; + + $lines = [split "\n", $l]; + return $lines; +} + +sub expand { + my $l = shift; + my ($word, @arg) = split ' ', $l; + my $v = $macro{$word}; + $v =~ s/%(\d+)/$arg[$1-1] or die "macro '$word' needs $1 arguments at '$l'\n"/gem; + return $v; +} + +__END__ + +Documentation is mostly by example. + +Setup: + + * the line + 'macros', + should be added to the SYNTACTIC_SUGAR list in ~/.gitolite.rc + +Notes on macro definition: + + * the keywords 'macro' and 'end' should start on a new line + * the first word after 'macro' is the name of the macro, and the rest, until + the 'end', is the body + +Notes on macro use: + + * the macro name should be the first word on a line + * the rest of the line is used as arguments to the macro + +Example: + + if your conf contains: + + macro foo repo aa-%1 + RW = u1 %2 + R = u2 + end + + foo 1 alice + foo 2 bob + + this will effectively turn into + + repo aa-1 + RW = u1 alice + R = u2 + + repo aa-2 + RW = u1 bob + R = u2 diff --git a/src/triggers/post-compile/update-gitweb-access-list b/src/triggers/post-compile/update-gitweb-access-list index d986fb3..11e1aa6 100755 --- a/src/triggers/post-compile/update-gitweb-access-list +++ b/src/triggers/post-compile/update-gitweb-access-list @@ -6,8 +6,10 @@ # ---------------------------------------------------------------------- # delete the 'description' file that 'git init' created if this is run from -# the post-create trigger -[ "$1" = "POST_CREATE" ] && rm -f $GL_REPO_BASE/$2.git/description 2>/dev/null +# the post-create trigger. However, note that POST_CREATE is also called from +# perms (since POST_CREATE doubles as eqvt of POST_COMPILE to propagate ad hoc +# permissions changes for wild repos) and then you should not delete it. +[ "$1" = "POST_CREATE" ] && [ "$4" != "perms" ] && rm -f $GL_REPO_BASE/$2.git/description 2>/dev/null # ---------------------------------------------------------------------- # skip if arg-1 is POST_CREATE and no arg-3 (user name) exists; this means diff --git a/src/triggers/post-compile/update-gitweb-daemon-from-options b/src/triggers/post-compile/update-gitweb-daemon-from-options new file mode 100755 index 0000000..a3627c9 --- /dev/null +++ b/src/triggers/post-compile/update-gitweb-daemon-from-options @@ -0,0 +1,57 @@ +#!/bin/sh + +# Update git-daemon and gitweb access using 'option' lines instead of special +# usernames. + +# To use: + +# * enable this combined updater in the rc file by removing the other two +# update-*-access-list entries and inserting this one instead. (This would +# be in the POST_CREATE and POST_COMPILE lists). + +# * the add option lines in the conf file, like this: +# +# repo foo @bar +# option daemon = 1 +# option gitweb = 1 + +# Note: don't forget that gitweb can also be enabled by actual config +# variables (gitweb.owner, gitweb.description, gitweb.category) + +# This is useful for people who don't like '@all' to be literally *all* users, +# including gitweb and daemon, and can't/won't use deny-rules properly. + +# ---------------------------------------------------------------------- +# skip if arg-1 is POST_CREATE and no arg-3 (user name) exists; this means +# it's been triggered by a *normal* (not "wild") repo creation, which in turn +# means a POST_COMPILE should be following so there's no need to waste time +# running this once for each new repo +[ "$1" = "POST_CREATE" ] && [ -z "$3" ] && exit 0; + +# first do the gitweb stuff + +plf=`gitolite query-rc GITWEB_PROJECTS_LIST` +[ -z "$plf" ] && plf=$HOME/projects.list + +( + gitolite list-phy-repos | gitolite git-config % gitolite-options.gitweb + gitolite list-phy-repos | gitolite git-config -r % gitweb\\. +) | + cut -f1 | sort -u | sed -e 's/$/.git/' > $plf + +# now deal with git-daemon + +EO=git-daemon-export-ok +RB=`gitolite query-rc GL_REPO_BASE` +export EO RB + +export tmp=$(mktemp -d) +trap "rm -rf $tmp" 0 + +gitolite list-phy-repos | sort | tee $tmp/all | gitolite git-config % gitolite-options.daemon | cut -f1 > $tmp/daemon + +comm -23 $tmp/all $tmp/daemon | perl -lne 'unlink "$ENV{RB}/$_.git/$ENV{EO}"' +cat $tmp/daemon | while read repo +do + > $RB/$repo.git/$EO +done diff --git a/t/sequence.t b/t/sequence.t index e98690b..87f3731 100755 --- a/t/sequence.t +++ b/t/sequence.t @@ -100,7 +100,7 @@ try " # auto-create using perms fail echo READERS u5 | glt perms u4 -c foo/u4/baz !/Initialized empty Git repository in .*/foo/u4/baz.git/ - /FATAL: .C any foo/u4/baz u4 DENIED by fallthru/ + /FATAL: repo does not exist, or you are not authorised/ # auto-create using perms echo READERS u2 | glt perms u1 -c foo/u1/baz