1
package Gitolite::Triggers::Alias;
5
use Gitolite::Conf::Load;
10
# aliasing a repo to another
11
# ----------------------------------------------------------------------
17
We had an existing repo "foo" that lots of people use. We wanted to
18
rename it to "foo/code", so that related repos "foo/upstream" and
19
"foo/docs" (both containing stuff we did not want to put in "foo") could
20
also be made and then the whole thing would be structured nicely.
22
At the same time we did not want to *force* all the users to change the
23
name. At least git operations should still work with the old name,
24
although it is OK for "info" and other "commands" to display/require the
25
proper name (i.e., the new name).
29
* add a new variable REPO_ALIASES to the rc file, with entries like:
36
* add the following line to the INPUT section in the rc file:
42
* only git operations (clone/fetch/push) are alias aware. Nothing else in
43
gitolite, such as all the gitolite commands etc., are alias-aware and will
44
always use/require the proper repo name.
46
* http mode has not been tested and will not be. If someone has the time to
47
test it and make it work please let me know.
49
* funnily enough, this even works with mirroring! That is, a master can
50
push a repo "foo" to a slave per its configuration, while the slave thinks
51
it is getting repo "bar" from the master per its configuration.
53
Just make sure to put the Alias::input line *before* the Mirroring::input
54
line in the rc file on the slave.
56
However, it will probably not work with redirected pushes unless you setup
57
the opposite alias ("bar" -> "foo") on master.
61
my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive";
62
my $user = $ARGV[0] || '@all'; # user name is undocumented for now
64
if ( $ENV{SSH_ORIGINAL_COMMAND} =~ /(?:$git_commands) '\/?(\S+)'$/ ) {
66
( my $norm = $repo ) =~ s/\.git$//; # normalised repo name
70
return unless $target = $rc{REPO_ALIASES}{$norm};
71
$target = $target->{$user} if ref($target) eq 'HASH';
72
return unless $target;
74
_warn "'$norm' is an alias for '$target'";
76
$ENV{SSH_ORIGINAL_COMMAND} =~ s/'\/?$repo'/'$target'/;